1
1
use std:: path:: { Path , PathBuf } ;
2
2
use std:: { env, fs} ;
3
3
4
- use ctest_next:: { Result , TestGenerator , __compile_test , __run_test , generate_test} ;
4
+ use ctest_next:: { __compile_test , __run_test , Result , TestGenerator , generate_test} ;
5
5
use pretty_assertions:: assert_eq;
6
6
7
7
// Headers are found relevative to the include directory, all files are generated
@@ -12,7 +12,8 @@ use pretty_assertions::assert_eq;
12
12
/// The files will be generated in a unique temporary directory that gets
13
13
/// deleted when it goes out of scope.
14
14
fn 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 ( ) ) } ;
16
17
let temp_dir = tempfile:: tempdir ( ) ?;
17
18
let mut generator = TestGenerator :: new ( ) ;
18
19
generator
@@ -44,13 +45,13 @@ fn bless_equal(new_file: impl AsRef<Path>, old_file: impl AsRef<Path>) {
44
45
/// Additionally, if this test is not being ran on a cross compiled target, it will compile
45
46
/// and run the generated tests as well.
46
47
fn check_entrypoint (
47
- gen : & mut TestGenerator ,
48
+ gen_ : & mut TestGenerator ,
48
49
out_dir : tempfile:: TempDir ,
49
50
crate_path : impl AsRef < Path > ,
50
51
library_path : impl AsRef < Path > ,
51
52
include_path : impl AsRef < Path > ,
52
53
) {
53
- let output_file = gen . generate_files ( & crate_path, & library_path) . unwrap ( ) ;
54
+ let output_file = gen_ . generate_files ( & crate_path, & library_path) . unwrap ( ) ;
54
55
55
56
let rs = include_path
56
57
. as_ref ( )
@@ -63,7 +64,7 @@ fn check_entrypoint(
63
64
bless_equal ( output_file. with_extension ( "c" ) , c) ;
64
65
65
66
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 ( ) ;
67
68
let test_binary = __compile_test ( & out_dir, crate_path, library_path) . unwrap ( ) ;
68
69
let result = __run_test ( test_binary) ;
69
70
if let Err ( err) = & result {
@@ -79,8 +80,8 @@ fn test_entrypoint_hierarchy() {
79
80
let crate_path = include_path. join ( "hierarchy/lib.rs" ) ;
80
81
let library_path = "hierarchy.out.a" ;
81
82
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) ;
84
85
}
85
86
86
87
#[ test]
@@ -89,10 +90,10 @@ fn test_skip_simple() {
89
90
let crate_path = include_path. join ( "simple.rs" ) ;
90
91
let library_path = "simple.out.with-skips.a" ;
91
92
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" ) ;
94
95
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) ;
96
97
}
97
98
98
99
#[ test]
@@ -101,10 +102,10 @@ fn test_map_simple() {
101
102
let crate_path = include_path. join ( "simple.rs" ) ;
102
103
let library_path = "simple.out.with-renames.a" ;
103
104
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 ( ) ) ) ;
106
107
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) ;
108
109
}
109
110
110
111
#[ test]
@@ -113,16 +114,16 @@ fn test_entrypoint_macro() {
113
114
let crate_path = include_path. join ( "macro.rs" ) ;
114
115
let library_path = "macro.out.a" ;
115
116
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) ;
118
119
}
119
120
120
121
#[ test]
121
122
fn test_entrypoint_invalid_syntax ( ) {
122
123
let crate_path = "tests/input/invalid_syntax.rs" ;
123
- let mut gen = TestGenerator :: new ( ) ;
124
+ let mut gen_ = TestGenerator :: new ( ) ;
124
125
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 ( ) ;
126
127
127
128
assert ! ( fails)
128
129
}
0 commit comments