@@ -5,7 +5,9 @@ use std::path::PathBuf;
55use std:: process:: Command ;
66
77use c2rust_rust_tools:: rustc;
8+ use c2rust_transpile:: convert_type:: RESERVED_NAMES ;
89use c2rust_transpile:: { ReplaceMode , TranspilerConfig } ;
10+ use itertools:: Itertools ;
911
1012fn config ( ) -> TranspilerConfig {
1113 TranspilerConfig {
@@ -135,6 +137,8 @@ fn transpile_snapshot(platform: Option<&str>, c_path: &Path) {
135137
136138#[ test]
137139fn transpile_all_snapshots ( ) {
140+ generate_keywords_test ( ) ;
141+
138142 // TODO parallelize these `insta::glob!`s across multiple `#[test]`s
139143 // now that we use `cargo nextest`.
140144
@@ -180,6 +184,25 @@ fn transpile_all_snapshots() {
180184 } ) ;
181185}
182186
187+ fn generate_keywords_test ( ) {
188+ // Common keywords we need to filter out.
189+ let c_keywords = [
190+ "break" , "const" , "continue" , "else" , "enum" , "extern" , "for" , "if" , "return" , "static" ,
191+ "struct" , "while" , "do" , "typeof" , "char" ,
192+ ] ;
193+ // These don't work yet. We need to fix these.
194+ let broken_rust_keywords = [ "await" ] ;
195+ let mut c_code = RESERVED_NAMES
196+ . into_iter ( )
197+ . filter ( |keyword| !c_keywords. contains ( keyword) )
198+ . filter ( |keyword| !broken_rust_keywords. contains ( keyword) )
199+ . map ( |name| format ! ( "void {name}(void) {{}}" ) )
200+ . join ( "\n \n " ) ;
201+ c_code. push_str ( "\n " ) ;
202+ let c_path = Path :: new ( "tests/snapshots/keywords.c" ) ;
203+ fs_err:: write ( c_path, c_code) . unwrap ( ) ;
204+ }
205+
183206#[ test]
184207fn check_c_decl_map ( ) {
185208 insta:: glob!( "c_decls_snapshots/*.c" , transpile_with_c_decl_map_snapshot) ;
0 commit comments