diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index deb5733485d7..f514f4e3e5c3 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -502,7 +502,7 @@ fn phase_cargo_rustc(args: env::Args) { /// Cargo does not give us this information directly, so we need to check /// various command-line flags. fn is_runnable_crate() -> bool { - let is_bin = get_arg_flag_value("--crate-type").as_deref() == Some("bin"); + let is_bin = get_arg_flag_value("--crate-type").as_deref().unwrap_or("bin") == "bin"; let is_test = has_arg_flag("--test"); let print = get_arg_flag_value("--print").is_some(); (is_bin || is_test) && !print diff --git a/test-cargo-miri/Cargo.toml b/test-cargo-miri/Cargo.toml index 6bc11ef0cc5a..f4847270ba40 100644 --- a/test-cargo-miri/Cargo.toml +++ b/test-cargo-miri/Cargo.toml @@ -13,3 +13,7 @@ num_cpus = "1.10.1" [lib] test = false # test that this is respected (will show in the output) + +[[test]] +name = "no-harness" +harness = false diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index c7694f3854c8..665e9834e8e5 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -22,7 +22,7 @@ def cargo_miri(cmd): return args def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}): - print("==> Testing `{}` <==".format(name)) + print("==> Testing {} <==".format(name)) ## Call `cargo miri`, capture all output p_env = os.environ.copy() p_env.update(env) @@ -50,13 +50,13 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}): fail("stderr does not match reference") def test_cargo_miri_run(): - test("cargo miri run", + test("`cargo miri run`", cargo_miri("run"), - "stdout.ref", "stderr.ref", + "stdout.ref1", "stderr.ref1", stdin=b'12\n21\n', env={'MIRIFLAGS': "-Zmiri-disable-isolation"}, ) - test("cargo miri run (with arguments and target)", + test("`cargo miri run` (with arguments and target)", cargo_miri("run") + ["--bin", "cargo-miri-test", "--", "hello world", '"hello world"'], "stdout.ref2", "stderr.ref2" ) @@ -64,27 +64,27 @@ def test_cargo_miri_run(): def test_cargo_miri_test(): # rustdoc is not run on foreign targets is_foreign = 'MIRI_TEST_TARGET' in os.environ - rustdoc_ref = "test.stderr.ref2" if is_foreign else "test.stderr.ref" + rustdoc_ref = "test.stderr.ref2" if is_foreign else "test.stderr.ref1" - test("cargo miri test", + test("`cargo miri test`", cargo_miri("test"), - "test.stdout.ref",rustdoc_ref, + "test.stdout.ref1",rustdoc_ref, env={'MIRIFLAGS': "-Zmiri-seed=feed"}, ) - test("cargo miri test (with filter)", + test("`cargo miri test` (with filter)", cargo_miri("test") + ["--", "--format=pretty", "le1"], "test.stdout.ref2", rustdoc_ref ) - test("cargo miri test (without isolation)", + test("`cargo miri test` (without isolation)", cargo_miri("test") + ["--", "--format=pretty", "num_cpus"], "test.stdout.ref3", rustdoc_ref, env={'MIRIFLAGS': "-Zmiri-disable-isolation"}, ) - test("cargo miri test (test target)", + test("`cargo miri test` (test target)", cargo_miri("test") + ["--test", "test", "--", "--format=pretty"], "test.stdout.ref4", "test.stderr.ref2" ) - test("cargo miri test (bin target)", + test("`cargo miri test` (bin target)", cargo_miri("test") + ["--bin", "cargo-miri-test", "--", "--format=pretty"], "test.stdout.ref5", "test.stderr.ref2" ) diff --git a/test-cargo-miri/src/main.rs b/test-cargo-miri/src/main.rs index 0079328ff605..17808f57061e 100644 --- a/test-cargo-miri/src/main.rs +++ b/test-cargo-miri/src/main.rs @@ -28,7 +28,6 @@ fn main() { println!("42"); } } - } #[cfg(test)] diff --git a/test-cargo-miri/stderr.ref b/test-cargo-miri/stderr.ref1 similarity index 100% rename from test-cargo-miri/stderr.ref rename to test-cargo-miri/stderr.ref1 diff --git a/test-cargo-miri/stdout.ref b/test-cargo-miri/stdout.ref1 similarity index 100% rename from test-cargo-miri/stdout.ref rename to test-cargo-miri/stdout.ref1 diff --git a/test-cargo-miri/test.stderr.ref b/test-cargo-miri/test.stderr.ref1 similarity index 100% rename from test-cargo-miri/test.stderr.ref rename to test-cargo-miri/test.stderr.ref1 diff --git a/test-cargo-miri/test.stdout.ref b/test-cargo-miri/test.stdout.ref1 similarity index 92% rename from test-cargo-miri/test.stdout.ref rename to test-cargo-miri/test.stdout.ref1 index 1eb18fe88768..76144513c548 100644 --- a/test-cargo-miri/test.stdout.ref +++ b/test-cargo-miri/test.stdout.ref1 @@ -3,6 +3,7 @@ running 1 test . test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out +no-harness test running 8 tests ..i..... diff --git a/test-cargo-miri/test.stdout.ref2 b/test-cargo-miri/test.stdout.ref2 index d426bdf6db63..1264c6da7ff8 100644 --- a/test-cargo-miri/test.stdout.ref2 +++ b/test-cargo-miri/test.stdout.ref2 @@ -3,6 +3,7 @@ running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out +no-harness test running 1 test test simple1 ... ok diff --git a/test-cargo-miri/test.stdout.ref3 b/test-cargo-miri/test.stdout.ref3 index bc4a7c47e9f5..a5edee2c5f13 100644 --- a/test-cargo-miri/test.stdout.ref3 +++ b/test-cargo-miri/test.stdout.ref3 @@ -3,6 +3,7 @@ running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out +no-harness test running 1 test test num_cpus ... ok diff --git a/test-cargo-miri/tests/no-harness.rs b/test-cargo-miri/tests/no-harness.rs new file mode 100644 index 000000000000..8d1c5c346266 --- /dev/null +++ b/test-cargo-miri/tests/no-harness.rs @@ -0,0 +1,3 @@ +fn main() { + println!("no-harness test"); +}