@@ -11,6 +11,7 @@ fn compile_and_run_cmds(
1111 compiler_args : Vec < String > ,
1212 test_target : & Option < String > ,
1313 exe : & Path ,
14+ run_binary : bool ,
1415) -> Vec < ( & ' static str , Command ) > {
1516 let mut compiler = Command :: new ( "rustc" ) ;
1617 compiler. args ( compiler_args) ;
@@ -35,18 +36,33 @@ fn compile_and_run_cmds(
3536 copy. arg ( "cp" ) ;
3637 copy. args ( [ exe, & vm_exe_path] ) ;
3738
38- let mut runtime = Command :: new ( "sudo" ) ;
39- runtime. args ( [ "chroot" , vm_dir, "qemu-m68k-static" ] ) ;
40- runtime. arg ( inside_vm_exe_path) ;
41- runtime. current_dir ( vm_parent_dir) ;
42- vec ! [ ( "Compiler" , compiler) , ( "Copy" , copy) , ( "Run-time" , runtime) ]
39+ let mut commands = vec ! [ ( "Compiler" , compiler) , ( "Copy" , copy) ] ;
40+ if run_binary {
41+ let mut runtime = Command :: new ( "sudo" ) ;
42+ runtime. args ( [ "chroot" , vm_dir, "qemu-m68k-static" ] ) ;
43+ runtime. arg ( inside_vm_exe_path) ;
44+ runtime. current_dir ( vm_parent_dir) ;
45+ commands. push ( ( "Run-time" , runtime) ) ;
46+ }
47+ commands
4348 } else {
44- let runtime = Command :: new ( exe) ;
45- vec ! [ ( "Compiler" , compiler) , ( "Run-time" , runtime) ]
49+ let mut commands = vec ! [ ( "Compiler" , compiler) ] ;
50+ if run_binary {
51+ let runtime = Command :: new ( exe) ;
52+ commands. push ( ( "Run-time" , runtime) ) ;
53+ }
54+ commands
4655 }
4756}
4857
49- fn run_tests ( tempdir : PathBuf , current_dir : String , is_debug : bool ) {
58+ fn build_test_runner (
59+ tempdir : PathBuf ,
60+ current_dir : String ,
61+ is_debug : bool ,
62+ test_kind : & str ,
63+ test_dir : & str ,
64+ run_binary : bool ,
65+ ) {
5066 fn rust_filter ( path : & Path ) -> bool {
5167 path. is_file ( ) && path. extension ( ) . expect ( "extension" ) . to_str ( ) . expect ( "to_str" ) == "rs"
5268 }
@@ -66,14 +82,10 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) {
6682 rust_filter ( filename)
6783 }
6884
69- if is_debug {
70- println ! ( "=== [DEBUG] lang tests ===" ) ;
71- } else {
72- println ! ( "=== [RELEASE] lang tests ===" ) ;
73- }
85+ println ! ( "=== {test_kind} tests ===" ) ;
7486
7587 LangTester :: new ( )
76- . test_dir ( "tests/run" )
88+ . test_dir ( test_dir )
7789 . test_path_filter ( filter)
7890 . test_extract ( |path| {
7991 std:: fs:: read_to_string ( path)
@@ -134,17 +146,40 @@ fn run_tests(tempdir: PathBuf, current_dir: String, is_debug: bool) {
134146 ] ) ;
135147 }
136148
137- compile_and_run_cmds ( compiler_args, & test_target, & exe)
149+ compile_and_run_cmds ( compiler_args, & test_target, & exe, run_binary )
138150 } )
139151 . run ( ) ;
140152}
141153
154+ fn compile_tests ( tempdir : PathBuf , current_dir : String ) {
155+ build_test_runner ( tempdir, current_dir, true , "lang compile" , "tests/compile" , false ) ;
156+ }
157+
158+ fn run_tests ( tempdir : PathBuf , current_dir : String ) {
159+ build_test_runner (
160+ tempdir. clone ( ) ,
161+ current_dir. clone ( ) ,
162+ true ,
163+ "[DEBUG] lang run" ,
164+ "tests/run" ,
165+ true ,
166+ ) ;
167+ build_test_runner (
168+ tempdir,
169+ current_dir. to_string ( ) ,
170+ false ,
171+ "[RELEASE] lang run" ,
172+ "tests/run" ,
173+ true ,
174+ ) ;
175+ }
176+
142177fn main ( ) {
143178 let tempdir = TempDir :: new ( ) . expect ( "temp dir" ) ;
144179 let current_dir = current_dir ( ) . expect ( "current dir" ) ;
145180 let current_dir = current_dir. to_str ( ) . expect ( "current dir" ) . to_string ( ) ;
146181
147182 let tempdir_path: PathBuf = tempdir. as_ref ( ) . into ( ) ;
148- run_tests ( tempdir_path. clone ( ) , current_dir. clone ( ) , true ) ;
149- run_tests ( tempdir_path, current_dir, false ) ;
183+ compile_tests ( tempdir_path. clone ( ) , current_dir. clone ( ) ) ;
184+ run_tests ( tempdir_path, current_dir) ;
150185}
0 commit comments