@@ -4,6 +4,7 @@ use std::path::Path;
44use std:: path:: PathBuf ;
55use std:: process:: Command ;
66
7+ use c2rust_ast_exporter:: get_clang_major_version;
78use c2rust_rust_tools:: rustc;
89use c2rust_rust_tools:: sanitize_file_name;
910use c2rust_rust_tools:: RustEdition ;
@@ -105,6 +106,26 @@ fn transpile_snapshot(
105106 expect_compile_error : bool ,
106107 imported_crates : & [ & str ] ,
107108) {
109+ let c_file_name = c_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
110+ let c_file_name = sanitize_file_name ( & c_file_name) ;
111+
112+ // Some versions of clang can produce results different from their snapshots,
113+ // those tests append the clang version to the snapshot of the failing test.
114+ let clang_ver = match ( get_clang_major_version ( ) . unwrap ( ) , c_file_name. as_str ( ) ) {
115+ // Tests that change @ clang-22
116+ ( 22 .., "varargs.c" ) => "clang22" ,
117+ ( 22 .., "wide_strings.c" ) => "clang22" ,
118+ ( 22 .., "auto_type.c" ) => "clang22" ,
119+
120+ // Tests that changed @ clang-17
121+
122+ // The minimum tested clang
123+ ( 15 .., _) => "clang15" ,
124+
125+ // Clang versions bellow 15 test against 15 and hope for the best
126+ ( 0 .., _) => "clang15" ,
127+ } ;
128+
108129 let cfg = config ( edition) ;
109130 compile_and_transpile_file ( c_path, cfg) ;
110131 let cwd = current_dir ( ) . unwrap ( ) ;
@@ -116,9 +137,10 @@ fn transpile_snapshot(
116137 let rs_path = c_path. with_extension ( "rs" ) ;
117138 // We need to move the `.rs` file to a platform/edition-specific name
118139 // so that they don't overwrite each other.
119- let ext = [ & [ edition. as_str ( ) ] [ ..] , platform]
140+ let ext = [ & [ edition. as_str ( ) ] [ ..] , platform, & [ clang_ver ] [ .. ] ]
120141 . into_iter ( )
121142 . flatten ( )
143+ . filter ( |s| !s. is_empty ( ) )
122144 . join ( "." ) ;
123145 let old_rs_path = rs_path;
124146 let rs_path = old_rs_path. with_extension ( format ! ( "{ext}.rs" ) ) ;
@@ -130,8 +152,6 @@ fn transpile_snapshot(
130152 // Replace real paths with placeholders
131153 let rs = rs. replace ( cwd. to_str ( ) . unwrap ( ) , "." ) ;
132154
133- let c_file_name = c_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
134- let c_file_name = sanitize_file_name ( & c_file_name) ;
135155 let snapshot_name = format ! ( "transpile@{c_file_name}.{ext}" ) ;
136156
137157 insta:: assert_snapshot!( snapshot_name, & rs, & debug_expr) ;
0 commit comments