]> git.lizzy.rs Git - rust.git/blobdiff - test-cargo-miri/run-test.py
test reading from stdin
[rust.git] / test-cargo-miri / run-test.py
index a258c7f73c2d94c4dc18ab64d881bbc40439542f..877a2a5706196e3d9864c6600aa21b4c0f8c0dba 100755 (executable)
@@ -21,15 +21,19 @@ def cargo_miri(cmd):
         args += ["--target", os.environ['MIRI_TEST_TARGET']]
     return args
 
-def test(name, cmd, stdout_ref, stderr_ref):
+def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
     print("==> Testing `{}` <==".format(name))
     ## Call `cargo miri`, capture all output
+    p_env = os.environ.copy()
+    p_env.update(env)
     p = subprocess.Popen(
         cmd,
+        stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE
+        stderr=subprocess.PIPE,
+        env=p_env,
     )
-    (stdout, stderr) = p.communicate()
+    (stdout, stderr) = p.communicate(input=stdin)
     stdout = stdout.decode("UTF-8")
     stderr = stderr.decode("UTF-8")
     # Show output
@@ -48,36 +52,36 @@ def test(name, cmd, stdout_ref, stderr_ref):
 def test_cargo_miri_run():
     test("cargo miri run",
         cargo_miri("run"),
-        "stdout.ref", "stderr.ref"
+        "stdout.ref", "stderr.ref",
+        stdin=b'12\n21\n',
+        env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
     )
-    test("cargo miri run (with target)",
-        cargo_miri("run") + ["--bin", "cargo-miri-test"],
-        "stdout.ref", "stderr.ref"
-    )
-    test("cargo miri run (with arguments)",
-        cargo_miri("run") + ["--", "--", "hello world", '"hello world"'],
-        "stdout.ref", "stderr.ref2"
+    test("cargo miri run (with arguments and target)",
+        cargo_miri("run") + ["--bin", "cargo-miri-test", "--", "hello world", '"hello world"'],
+        "stdout.ref2", "stderr.ref2"
     )
 
 def test_cargo_miri_test():
     test("cargo miri test",
-        cargo_miri("test") + ["--", "-Zmiri-seed=feed"],
-        "test.stdout.ref", "test.stderr.ref"
+        cargo_miri("test"),
+        "test.stdout.ref", "test.stderr.ref",
+        env={'MIRIFLAGS': "-Zmiri-seed=feed"},
     )
     test("cargo miri test (with filter)",
-        cargo_miri("test") + ["--", "--", "le1"],
+        cargo_miri("test") + ["--", "--format=pretty", "le1"],
         "test.stdout.ref2", "test.stderr.ref"
     )
     test("cargo miri test (without isolation)",
-        cargo_miri("test") + ["--", "-Zmiri-disable-isolation", "--", "num_cpus"],
-        "test.stdout.ref3", "test.stderr.ref"
+        cargo_miri("test") + ["--", "--format=pretty", "num_cpus"],
+        "test.stdout.ref3", "test.stderr.ref",
+        env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
     )
     test("cargo miri test (test target)",
-        cargo_miri("test") + ["--test", "test"],
+        cargo_miri("test") + ["--test", "test", "--", "--format=pretty"],
         "test.stdout.ref4", "test.stderr.ref"
     )
     test("cargo miri test (bin target)",
-        cargo_miri("test") + ["--bin", "cargo-miri-test"],
+        cargo_miri("test") + ["--bin", "cargo-miri-test", "--", "--format=pretty"],
         "test.stdout.ref5", "test.stderr.ref"
     )