5
5
and the working directory to contain the cargo-miri-test project.
6
6
'''
7
7
8
- import sys , subprocess , os , re
8
+ import shutil , sys , subprocess , os , re , typing
9
9
10
10
CGREEN = '\33 [32m'
11
11
CBOLD = '\33 [1m'
@@ -23,6 +23,12 @@ def cargo_miri(cmd, quiet = True):
23
23
args += ["--target" , os .environ ['MIRI_TEST_TARGET' ]]
24
24
return args
25
25
26
+ def cargo_miri_nextest (cmd , quiet = True ):
27
+ args = ["cargo" , "miri" , "nextest" , cmd ]
28
+ if 'MIRI_TEST_TARGET' in os .environ :
29
+ args += ["--target" , os .environ ['MIRI_TEST_TARGET' ]]
30
+ return args
31
+
26
32
def normalize_stdout (str ):
27
33
str = str .replace ("src\\ " , "src/" ) # normalize paths across platforms
28
34
return re .sub ("finished in \d+\.\d\ds" , "finished in $TIME" , str )
@@ -55,6 +61,35 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
55
61
print ("--- END test stderr ---" )
56
62
fail ("exit code was {}" .format (p .returncode ))
57
63
64
+ def test_nextest (name , cmd : typing .List [str ], stdin = b'' , env = {}) -> typing .Tuple [str , str ]:
65
+ print ("Testing {}..." .format (name ))
66
+
67
+ ## Call `cargo miri`, capture all output
68
+ p_env = os .environ .copy ()
69
+ p_env .update (env )
70
+ p = subprocess .Popen (
71
+ cmd ,
72
+ stdin = subprocess .PIPE ,
73
+ stdout = subprocess .PIPE ,
74
+ stderr = subprocess .PIPE ,
75
+ env = p_env ,
76
+ )
77
+ (stdout , stderr ) = p .communicate (input = stdin )
78
+ stdout = stdout .decode ("UTF-8" )
79
+ stderr = stderr .decode ("UTF-8" )
80
+
81
+ if p .returncode == 0 :
82
+ return (stdout , stderr )
83
+ # Show output
84
+ print ("Nextest did not exit with 0!" )
85
+ print ("--- BEGIN test stdout ---" )
86
+ print (stdout , end = "" )
87
+ print ("--- END test stdout ---" )
88
+ print ("--- BEGIN test stderr ---" )
89
+ print (stderr , end = "" )
90
+ print ("--- END test stderr ---" )
91
+ fail ("exit code was {}" .format (p .returncode ))
92
+
58
93
def test_no_rebuild (name , cmd , env = {}):
59
94
print ("Testing {}..." .format (name ))
60
95
p_env = os .environ .copy ()
@@ -159,6 +194,26 @@ def test_cargo_miri_test():
159
194
env = {'MIRIFLAGS' : "-Zmiri-permissive-provenance" },
160
195
)
161
196
197
+ def test_cargo_miri_nextest ():
198
+ if shutil .which ("cargo-nextest" ) is None :
199
+ print ("Skipping `cargo miri nextest` (no cargo-nextest)" )
200
+ return
201
+ # main() in src/main.rs is a custom test harness that doesn't implement the API required by
202
+ # nextest -- this means that we can't test it. However, all the other tests are regular ones.
203
+ nextest_filter = "!(package(cargo-miri-test) & binary(main))"
204
+ # These tests just check that the exit code is 0.
205
+ # TODO: maybe inspect stdout/stderr, especially for list output?
206
+ test_nextest ("`cargo miri nextest list`" ,
207
+ cargo_miri_nextest ("list" ) + ["-E" , nextest_filter ]
208
+ )
209
+ test_nextest ("`cargo miri nextest run`" ,
210
+ cargo_miri_nextest ("run" ) + ["-E" , nextest_filter ],
211
+ )
212
+ # Running nextest archives is currently not supported.
213
+ # See https://github.com/nextest-rs/nextest/issues/370 for one issue -- also note that cargo
214
+ # miri passes in cargo-related options to nextest, which nextest rejects when running tests
215
+ # from an archive.
216
+
162
217
os .chdir (os .path .dirname (os .path .realpath (__file__ )))
163
218
os .environ ["CARGO_TARGET_DIR" ] = "target" # this affects the location of the target directory that we need to check
164
219
os .environ ["RUST_TEST_NOCAPTURE" ] = "0" # this affects test output, so make sure it is not set
@@ -173,9 +228,13 @@ def test_cargo_miri_test():
173
228
subprocess .run (cargo_miri ("setup" ), check = True )
174
229
test_cargo_miri_run ()
175
230
test_cargo_miri_test ()
231
+ test_cargo_miri_nextest ()
176
232
# Ensure we did not create anything outside the expected target dir.
177
233
for target_dir in ["target" , "custom-run" , "custom-test" , "config-cli" ]:
178
- if os .listdir (target_dir ) != ["miri" ]:
234
+ listdir = os .listdir (target_dir )
235
+ if "nextest" in listdir :
236
+ listdir .remove ("nextest" )
237
+ if listdir != ["miri" ]:
179
238
fail (f"`{ target_dir } ` contains unexpected files" )
180
239
# Ensure something exists inside that target dir.
181
240
os .access (os .path .join (target_dir , "miri" , "debug" , "deps" ), os .F_OK )
0 commit comments