55and the working directory to contain the cargo-miri-test project.
66'''
77
8- import sys , subprocess , os , re
8+ import shutil , sys , subprocess , os , re , typing
99
1010CGREEN = '\33 [32m'
1111CBOLD = '\33 [1m'
@@ -23,6 +23,12 @@ def cargo_miri(cmd, quiet = True):
2323 args += ["--target" , os .environ ['MIRI_TEST_TARGET' ]]
2424 return args
2525
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+
2632def normalize_stdout (str ):
2733 str = str .replace ("src\\ " , "src/" ) # normalize paths across platforms
2834 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={}):
5561 print ("--- END test stderr ---" )
5662 fail ("exit code was {}" .format (p .returncode ))
5763
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+
5893def test_no_rebuild (name , cmd , env = {}):
5994 print ("Testing {}..." .format (name ))
6095 p_env = os .environ .copy ()
@@ -159,6 +194,26 @@ def test_cargo_miri_test():
159194 env = {'MIRIFLAGS' : "-Zmiri-permissive-provenance" },
160195 )
161196
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+
162217os .chdir (os .path .dirname (os .path .realpath (__file__ )))
163218os .environ ["CARGO_TARGET_DIR" ] = "target" # this affects the location of the target directory that we need to check
164219os .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():
173228 subprocess .run (cargo_miri ("setup" ), check = True )
174229test_cargo_miri_run ()
175230test_cargo_miri_test ()
231+ test_cargo_miri_nextest ()
176232# Ensure we did not create anything outside the expected target dir.
177233for 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" ]:
179238 fail (f"`{ target_dir } ` contains unexpected files" )
180239 # Ensure something exists inside that target dir.
181240 os .access (os .path .join (target_dir , "miri" , "debug" , "deps" ), os .F_OK )
0 commit comments