@@ -11,7 +11,7 @@ fn compile_and_run_cmds(
1111 compiler_args : Vec < String > ,
1212 test_target : & Option < String > ,
1313 exe : & Path ,
14- run_binary : bool ,
14+ test_mode : TestMode ,
1515) -> Vec < ( & ' static str , Command ) > {
1616 let mut compiler = Command :: new ( "rustc" ) ;
1717 compiler. args ( compiler_args) ;
@@ -24,7 +24,7 @@ fn compile_and_run_cmds(
2424 compiler. env ( "PATH" , env_path) ;
2525
2626 let mut commands = vec ! [ ( "Compiler" , compiler) ] ;
27- if run_binary {
27+ if test_mode . should_run ( ) {
2828 let vm_parent_dir = std:: env:: var ( "CG_GCC_VM_DIR" )
2929 . map ( PathBuf :: from)
3030 . unwrap_or_else ( |_| std:: env:: current_dir ( ) . unwrap ( ) ) ;
@@ -50,21 +50,45 @@ fn compile_and_run_cmds(
5050 commands
5151 } else {
5252 let mut commands = vec ! [ ( "Compiler" , compiler) ] ;
53- if run_binary {
53+ if test_mode . should_run ( ) {
5454 let runtime = Command :: new ( exe) ;
5555 commands. push ( ( "Run-time" , runtime) ) ;
5656 }
5757 commands
5858 }
5959}
6060
61+ #[ derive( Clone , Copy ) ]
62+ enum BuildMode {
63+ Debug ,
64+ Release ,
65+ }
66+
67+ impl BuildMode {
68+ fn is_debug ( self ) -> bool {
69+ matches ! ( self , Self :: Debug )
70+ }
71+ }
72+
73+ #[ derive( Clone , Copy ) ]
74+ enum TestMode {
75+ Compile ,
76+ CompileAndRun ,
77+ }
78+
79+ impl TestMode {
80+ fn should_run ( self ) -> bool {
81+ matches ! ( self , Self :: CompileAndRun )
82+ }
83+ }
84+
6185fn build_test_runner (
6286 tempdir : PathBuf ,
6387 current_dir : String ,
64- is_debug : bool ,
88+ build_mode : BuildMode ,
6589 test_kind : & str ,
6690 test_dir : & str ,
67- run_binary : bool ,
91+ test_mode : TestMode ,
6892 files_to_ignore_on_m68k : & ' static [ & ' static str ] ,
6993) {
7094 fn rust_filter ( path : & Path ) -> bool {
@@ -148,7 +172,7 @@ fn build_test_runner(
148172 }
149173 }
150174
151- if is_debug {
175+ if build_mode . is_debug ( ) {
152176 compiler_args
153177 . extend_from_slice ( & [ "-C" . to_string ( ) , "llvm-args=sanitize-undefined" . into ( ) ] ) ;
154178 if test_target. is_none ( ) {
@@ -164,7 +188,7 @@ fn build_test_runner(
164188 ] ) ;
165189 }
166190
167- compile_and_run_cmds ( compiler_args, & test_target, & exe, run_binary )
191+ compile_and_run_cmds ( compiler_args, & test_target, & exe, test_mode )
168192 } )
169193 . run ( ) ;
170194}
@@ -173,10 +197,10 @@ fn compile_tests(tempdir: PathBuf, current_dir: String) {
173197 build_test_runner (
174198 tempdir,
175199 current_dir,
176- true ,
200+ BuildMode :: Debug ,
177201 "lang compile" ,
178202 "tests/compile" ,
179- false ,
203+ TestMode :: Compile ,
180204 & [ "simd-ffi.rs" ] ,
181205 ) ;
182206}
@@ -185,19 +209,19 @@ fn run_tests(tempdir: PathBuf, current_dir: String) {
185209 build_test_runner (
186210 tempdir. clone ( ) ,
187211 current_dir. clone ( ) ,
188- true ,
212+ BuildMode :: Debug ,
189213 "[DEBUG] lang run" ,
190214 "tests/run" ,
191- true ,
215+ TestMode :: CompileAndRun ,
192216 & [ ] ,
193217 ) ;
194218 build_test_runner (
195219 tempdir,
196220 current_dir. to_string ( ) ,
197- false ,
221+ BuildMode :: Release ,
198222 "[RELEASE] lang run" ,
199223 "tests/run" ,
200- true ,
224+ TestMode :: CompileAndRun ,
201225 & [ ] ,
202226 ) ;
203227}
0 commit comments