Skip to content

Commit 8bb14dc

Browse files
committed
add tests for local crate detection
1 parent af47763 commit 8bb14dc

File tree

10 files changed

+71
-3
lines changed

10 files changed

+71
-3
lines changed

test-cargo-miri/Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-cargo-miri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ issue_1567 = { path = "issue-1567" }
1717
issue_1691 = { path = "issue-1691" }
1818
issue_1705 = { path = "issue-1705" }
1919
issue_rust_86261 = { path = "issue-rust-86261" }
20+
executable = { path = "local-crate/executable" }
2021

2122
[dev-dependencies]
2223
byteorder_2 = { package = "byteorder", version = "0.5" } # to test dev-dependencies behave as expected, with renaming
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "executable"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
library-with-dashes = { path = "../library-with-dashes" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
eprintln!("{}", env!("MIRI_LOCAL_CRATES"));
3+
library_with_dashes::entry_point();
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "library-with-dashes"
3+
version = "0.1.0"
4+
edition = "2021"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub fn entry_point() {
2+
function()
3+
}
4+
5+
fn function() {
6+
unsafe { std::hint::unreachable_unchecked() }
7+
}

test-cargo-miri/run-test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def check_output(actual, path, name):
5050
print(f"--- END diff {name} ---")
5151
return False
5252

53-
def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env=None):
53+
def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env=None, expected_exit_code=0):
5454
if env is None:
5555
env = {}
5656
print("Testing {}...".format(name))
@@ -71,10 +71,10 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env=None):
7171
stdout_matches = check_output(stdout, stdout_ref, "stdout")
7272
stderr_matches = check_output(stderr, stderr_ref, "stderr")
7373

74-
if p.returncode == 0 and stdout_matches and stderr_matches:
74+
if p.returncode == expected_exit_code and stdout_matches and stderr_matches:
7575
# All good!
7676
return
77-
fail("exit code was {}".format(p.returncode))
77+
fail(f"exit code was {p.returncode} but {expected_exit_code} was expected")
7878

7979
def test_no_rebuild(name, cmd, env=None):
8080
if env is None:
@@ -131,6 +131,12 @@ def test_cargo_miri_run():
131131
cargo_miri("run") + ["--target-dir=custom-run", "--", "--target-dir=target/custom-run"],
132132
"run.args.stdout.ref", "run.custom-target-dir.stderr.ref",
133133
)
134+
test("`cargo miri run -p executable` (local crate)",
135+
cargo_miri("run") + ["--package=executable"],
136+
"run.local_crate.stdout.ref", "run.local_crate.stderr.ref",
137+
env={"RUSTFLAGS": f"--remap-path-prefix={os.getcwd()}=/build"},
138+
expected_exit_code=1,
139+
)
134140

135141
def test_cargo_miri_test():
136142
# rustdoc is not run on foreign targets
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
subcrate,issue_1567,exported_symbol_dep,cargo_miri_test,cdylib,executable,library_with_dashes,exported_symbol,issue_1691,issue_1705,issue_rust_86261,proc_macro_crate
2+
error: Undefined Behavior: entering unreachable code
3+
--> /build/local-crate/library-with-dashes/src/lib.rs:6:14
4+
|
5+
6 | unsafe { std::hint::unreachable_unchecked() }
6+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entering unreachable code
7+
|
8+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
9+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
10+
= note: BACKTRACE:
11+
= note: inside `library_with_dashes::function` at /build/local-crate/library-with-dashes/src/lib.rs:6:14: 6:48
12+
note: inside `library_with_dashes::entry_point`
13+
--> /build/local-crate/library-with-dashes/src/lib.rs:2:5
14+
|
15+
2 | function()
16+
| ^^^^^^^^^^
17+
note: inside `main`
18+
--> local-crate/executable/src/main.rs:3:5
19+
|
20+
3 | library_with_dashes::entry_point();
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
24+
25+
error: aborting due to 1 previous error
26+

test-cargo-miri/run.local_crate.stdout.ref

Whitespace-only changes.

0 commit comments

Comments
 (0)