@@ -9,7 +9,6 @@ def read_from_file(path: str) -> str:
9
9
return f .read ()
10
10
11
11
def normalize_name (test_name : str ) -> str :
12
- # Replace underscores with spaces and capitalize the first letter.
13
12
return test_name .replace ("_" , " " ).capitalize ()
14
13
15
14
def run_command (cmd : list , cwd = None ):
@@ -25,7 +24,6 @@ def process_test(test_dir: str, release_mode: bool):
25
24
normalized = normalize_name (test_name )
26
25
print (f"|-- Test '{ test_name } ' ({ normalized } )" )
27
26
28
- # Clean the folder: with cargo clean
29
27
print ("|--- 🧼 Cleaning test folder..." )
30
28
proc = run_command (["cargo" , "clean" ], cwd = test_dir )
31
29
if proc .returncode != 0 :
@@ -35,7 +33,6 @@ def process_test(test_dir: str, release_mode: bool):
35
33
print (f"|---- ❌ cargo clean exited with code { proc .returncode } " )
36
34
return False
37
35
38
- # Run cargo build.
39
36
print ("|--- ⚒️ Building with Cargo..." )
40
37
build_cmd = ["cargo" , "build" , "--release" ] if release_mode else ["cargo" , "build" ]
41
38
no_jvm_target = os .path .join (test_dir , "no_jvm_target.flag" )
@@ -50,7 +47,6 @@ def process_test(test_dir: str, release_mode: bool):
50
47
print (f"|---- ❌ cargo build exited with code { proc .returncode } " )
51
48
return False
52
49
53
- # Run java with the generated jar.
54
50
print ("|--- 🤖 Running with Java..." )
55
51
target_dir = "release" if release_mode else "debug"
56
52
if os .path .exists (no_jvm_target ):
@@ -64,11 +60,12 @@ def process_test(test_dir: str, release_mode: bool):
64
60
print ("|---- ❌ No jar file found in target/{target_dir}/deps" )
65
61
return False
66
62
os .makedirs (os .path .join (test_dir , "target" , "jvm-unknown-unknown" , target_dir ), exist_ok = True )
67
- os .rename (os .path .join (test_dir , "target" , target_dir , "deps" , jar_file ), os .path .join (test_dir , "target" , "jvm-unknown-unknown" , target_dir , f"{ test_name } .jar" ))
63
+ os .rename (os .path .join (test_dir , "target" , target_dir , "deps" , jar_file ),
64
+ os .path .join (test_dir , "target" , "jvm-unknown-unknown" , target_dir , f"{ test_name } .jar" ))
65
+
68
66
jar_path = os .path .join (test_dir , "target" , "jvm-unknown-unknown" , target_dir , f"{ test_name } .jar" )
69
67
proc = run_command (["java" , "-jar" , jar_path ])
70
68
71
- # Check for java-returncode.expected
72
69
expected_returncode_file = os .path .join (test_dir , "java-returncode.expected" )
73
70
if os .path .exists (expected_returncode_file ):
74
71
expected_returncode = int (read_from_file (expected_returncode_file ).strip ())
@@ -86,17 +83,14 @@ def process_test(test_dir: str, release_mode: bool):
86
83
print (f"|---- ❌ java exited with code { proc .returncode } " )
87
84
return False
88
85
89
- # Compare the STDOUT and STDERR to {test_dir}/java-output.expected
90
86
expected_file = os .path .join (test_dir , "java-output.expected" )
91
87
if os .path .exists (expected_file ):
92
88
expected_output = read_from_file (expected_file )
93
- # special case: blank file = no STDOUT or STDERR expected
94
89
if expected_output .strip () == "" :
95
90
expected_output = "STDOUT:STDERR:"
96
91
else :
97
92
expected_output = expected_output .replace ("\n " , "" )
98
93
actual_output = f"STDOUT:{ proc .stdout .strip ()} STDERR:{ proc .stderr .strip ()} "
99
- # remove all remaining newlines
100
94
actual_output = actual_output .replace ("\n " , "" )
101
95
if actual_output != expected_output .strip ():
102
96
diff_path = os .path .join (test_dir , "output-diff.generated" )
@@ -114,6 +108,7 @@ def process_test(test_dir: str, release_mode: bool):
114
108
def main ():
115
109
parser = argparse .ArgumentParser (description = "Tester for Rustc's JVM Codegen Backend" )
116
110
parser .add_argument ("--release" , action = "store_true" , help = "Run cargo in release mode" )
111
+ parser .add_argument ("--only-run" , type = str , help = "Comma-separated list of specific test names to run" )
117
112
args = parser .parse_args ()
118
113
119
114
print ("🧪 Tester for Rustc's JVM Codegen Backend started!" )
@@ -124,19 +119,24 @@ def main():
124
119
125
120
print (" " )
126
121
127
- # Process binary tests.
122
+ # Gather test directories
128
123
binary_dir = os .path .join ("tests" , "binary" )
129
124
if os .path .isdir (binary_dir ):
130
125
binary_tests = [os .path .join (binary_dir , d ) for d in os .listdir (binary_dir ) if os .path .isdir (os .path .join (binary_dir , d ))]
131
126
else :
132
127
binary_tests = []
133
- print (f"|- 📦 Running { len (binary_tests )} binary build tests..." )
134
- for idx , test_dir in enumerate (binary_tests ):
128
+
129
+ # Filter based on --only-run
130
+ if args .only_run :
131
+ requested_tests = set ([name .strip () for name in args .only_run .split ("," )])
132
+ binary_tests = [t for t in binary_tests if os .path .basename (t ) in requested_tests ]
133
+
134
+ print (f"|- 📦 Running { len (binary_tests )} binary build test(s)..." )
135
+ for test_dir in binary_tests :
135
136
if not process_test (test_dir , args .release ):
136
137
overall_success = False
137
138
138
139
print ("" )
139
-
140
140
if overall_success :
141
141
print ("|-✅ All tests passed!" )
142
142
sys .exit (0 )
0 commit comments