11use std:: path:: { Path , PathBuf } ;
22use std:: { env, fs} ;
33
4- use ctest_next:: { Result , TestGenerator , __compile_test , __run_test , generate_test} ;
4+ use ctest_next:: { __compile_test , __run_test , Result , TestGenerator , generate_test} ;
55use pretty_assertions:: assert_eq;
66
77// Headers are found relevative to the include directory, all files are generated
@@ -12,7 +12,8 @@ use pretty_assertions::assert_eq;
1212/// The files will be generated in a unique temporary directory that gets
1313/// deleted when it goes out of scope.
1414fn default_generator ( opt_level : u8 , header : & str ) -> Result < ( TestGenerator , tempfile:: TempDir ) > {
15- env:: set_var ( "OPT_LEVEL" , opt_level. to_string ( ) ) ;
15+ // FIXME(mbyx): Remove this in favor of not-unsafe alternatives.
16+ unsafe { env:: set_var ( "OPT_LEVEL" , opt_level. to_string ( ) ) } ;
1617 let temp_dir = tempfile:: tempdir ( ) ?;
1718 let mut generator = TestGenerator :: new ( ) ;
1819 generator
@@ -44,13 +45,13 @@ fn bless_equal(new_file: impl AsRef<Path>, old_file: impl AsRef<Path>) {
4445/// Additionally, if this test is not being ran on a cross compiled target, it will compile
4546/// and run the generated tests as well.
4647fn check_entrypoint (
47- gen : & mut TestGenerator ,
48+ gen_ : & mut TestGenerator ,
4849 out_dir : tempfile:: TempDir ,
4950 crate_path : impl AsRef < Path > ,
5051 library_path : impl AsRef < Path > ,
5152 include_path : impl AsRef < Path > ,
5253) {
53- let output_file = gen . generate_files ( & crate_path, & library_path) . unwrap ( ) ;
54+ let output_file = gen_ . generate_files ( & crate_path, & library_path) . unwrap ( ) ;
5455
5556 let rs = include_path
5657 . as_ref ( )
@@ -63,7 +64,7 @@ fn check_entrypoint(
6364 bless_equal ( output_file. with_extension ( "c" ) , c) ;
6465
6566 if env:: var ( "TARGET_PLATFORM" ) == env:: var ( "HOST_PLATFORM" ) {
66- generate_test ( gen , & crate_path, & library_path) . unwrap ( ) ;
67+ generate_test ( gen_ , & crate_path, & library_path) . unwrap ( ) ;
6768 let test_binary = __compile_test ( & out_dir, crate_path, library_path) . unwrap ( ) ;
6869 let result = __run_test ( test_binary) ;
6970 if let Err ( err) = & result {
@@ -79,8 +80,8 @@ fn test_entrypoint_hierarchy() {
7980 let crate_path = include_path. join ( "hierarchy/lib.rs" ) ;
8081 let library_path = "hierarchy.out.a" ;
8182
82- let ( mut gen , out_dir) = default_generator ( 1 , "hierarchy.h" ) . unwrap ( ) ;
83- check_entrypoint ( & mut gen , out_dir, crate_path, library_path, include_path) ;
83+ let ( mut gen_ , out_dir) = default_generator ( 1 , "hierarchy.h" ) . unwrap ( ) ;
84+ check_entrypoint ( & mut gen_ , out_dir, crate_path, library_path, include_path) ;
8485}
8586
8687#[ test]
@@ -89,10 +90,10 @@ fn test_skip_simple() {
8990 let crate_path = include_path. join ( "simple.rs" ) ;
9091 let library_path = "simple.out.with-skips.a" ;
9192
92- let ( mut gen , out_dir) = default_generator ( 1 , "simple.h" ) . unwrap ( ) ;
93- gen . skip_const ( |c| c. ident ( ) == "B" ) ;
93+ let ( mut gen_ , out_dir) = default_generator ( 1 , "simple.h" ) . unwrap ( ) ;
94+ gen_ . skip_const ( |c| c. ident ( ) == "B" ) ;
9495
95- check_entrypoint ( & mut gen , out_dir, crate_path, library_path, include_path) ;
96+ check_entrypoint ( & mut gen_ , out_dir, crate_path, library_path, include_path) ;
9697}
9798
9899#[ test]
@@ -101,10 +102,10 @@ fn test_map_simple() {
101102 let crate_path = include_path. join ( "simple.rs" ) ;
102103 let library_path = "simple.out.with-renames.a" ;
103104
104- let ( mut gen , out_dir) = default_generator ( 1 , "simple.h" ) . unwrap ( ) ;
105- gen . rename_constant ( |c| ( c. ident ( ) == "B" ) . then ( || "C_B" . to_string ( ) ) ) ;
105+ let ( mut gen_ , out_dir) = default_generator ( 1 , "simple.h" ) . unwrap ( ) ;
106+ gen_ . rename_constant ( |c| ( c. ident ( ) == "B" ) . then ( || "C_B" . to_string ( ) ) ) ;
106107
107- check_entrypoint ( & mut gen , out_dir, crate_path, library_path, include_path) ;
108+ check_entrypoint ( & mut gen_ , out_dir, crate_path, library_path, include_path) ;
108109}
109110
110111#[ test]
@@ -113,16 +114,16 @@ fn test_entrypoint_macro() {
113114 let crate_path = include_path. join ( "macro.rs" ) ;
114115 let library_path = "macro.out.a" ;
115116
116- let ( mut gen , out_dir) = default_generator ( 1 , "macro.h" ) . unwrap ( ) ;
117- check_entrypoint ( & mut gen , out_dir, crate_path, library_path, include_path) ;
117+ let ( mut gen_ , out_dir) = default_generator ( 1 , "macro.h" ) . unwrap ( ) ;
118+ check_entrypoint ( & mut gen_ , out_dir, crate_path, library_path, include_path) ;
118119}
119120
120121#[ test]
121122fn test_entrypoint_invalid_syntax ( ) {
122123 let crate_path = "tests/input/invalid_syntax.rs" ;
123- let mut gen = TestGenerator :: new ( ) ;
124+ let mut gen_ = TestGenerator :: new ( ) ;
124125
125- let fails = generate_test ( & mut gen , crate_path, "invalid_syntax.out" ) . is_err ( ) ;
126+ let fails = generate_test ( & mut gen_ , crate_path, "invalid_syntax.out" ) . is_err ( ) ;
126127
127128 assert ! ( fails)
128129}
0 commit comments