Skip to content

Commit

Permalink
Auto merge of #14618 - weihanglo:relax-more, r=epage
Browse files Browse the repository at this point in the history
test: relax compiler panic assertions

### What does this PR try to resolve?

Minimize the panic output assertion per request from <#14602 (comment)>.

Instead of snapshotting the entire panic message,
here we only check the precense of our custom messaage.

### How should we test and review this PR?

Test suite passes.
  • Loading branch information
bors committed Sep 30, 2024
2 parents 5e2878f + dfa8f26 commit fe50f67
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 269 deletions.
8 changes: 4 additions & 4 deletions tests/build-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ fn remap_path_scope() {
[FINISHED] `release` profile [optimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/[HOST_TARGET]/release/foo`
[..]thread '[..]' panicked at [..]src/main.rs:3:[..]:
remap to /rustc/<hash>
at /rustc/[..]/library/std/src/[..]
at ./src/main.rs:3:[..]
at /rustc/[..]/library/core/src/[..]
[..]remap to /rustc/<hash>[..]
[..]at /rustc/[..]/library/std/src/[..]
[..]at ./src/main.rs:3:[..]
[..]at /rustc/[..]/library/core/src/[..]
...
"#]]
.unordered(),
Expand Down
16 changes: 7 additions & 9 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn check_with_invalid_target_triple() {
Caused by:
process didn't exit successfully: `rustc - --crate-name ___ --print=file-names --target unknown-target-triple [..]` ([EXIT_STATUS]: 1)
--- stderr
[ERROR] Error loading target specification: Could not find specification for target "unknown-target-triple". Run `rustc --print target-list` for a list of built-in targets
...
"#]])
Expand Down Expand Up @@ -1571,13 +1571,11 @@ fn artifact_dep_target_specified() {
// TODO: This command currently fails due to a bug in cargo but it should be fixed so that it succeeds in the future.
p.cargo("tree -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stdout_data(str![[""]])
.with_stderr_data(str![[r#"
thread 'main' panicked at src/cargo/[..]:
activated_features for invalid package: features did not find PackageId { name: "bindep", version: "0.0.0", source: "[..]" } NormalOrDev
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
"#]])
.with_stdout_data("")
.with_stderr_data(r#"...
[..]activated_features for invalid package: features did not find PackageId { name: "bindep", version: "0.0.0", source: "[..]" } NormalOrDev[..]
...
"#)
.with_status(101)
.run();
}
Expand Down Expand Up @@ -3246,7 +3244,7 @@ Caused by:
Caused by:
process didn't exit successfully: `rustc [..] ([EXIT_STATUS]: 1)
--- stderr
[ERROR] Error loading target specification: Could not find specification for target "custom-target". Run `rustc --print target-list` for a list of built-in targets
...
"#]])
Expand Down
80 changes: 13 additions & 67 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ fn cargo_bench_failing_test() {
#[bench]
fn bench_hello(_b: &mut test::Bencher) {
assert_eq!(hello(), "nope")
assert_eq!(hello(), "nope", "NOPE!")
}
"#,
)
Expand All @@ -389,28 +389,7 @@ hello
[ERROR] bench failed, to rerun pass `--bin foo`
"#]])
.with_stdout_data(str![[r#"
running 1 test
test bench_hello ... FAILED
failures:
---- bench_hello stdout ----
thread 'main' panicked at src/main.rs:15:17:
assertion `left == right` failed
left: "hello"
right: "nope"
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
bench_hello
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.with_stdout_data("...\n[..]NOPE![..]\n...")
.with_status(101)
.run();
}
Expand Down Expand Up @@ -1439,7 +1418,7 @@ fn test_bench_no_fail_fast() {
#[bench]
fn bench_nope(_b: &mut test::Bencher) {
assert_eq!("nope", hello())
assert_eq!("nope", hello(), "NOPE!")
}
"#,
)
Expand All @@ -1449,7 +1428,7 @@ fn test_bench_no_fail_fast() {
#![feature(test)]
extern crate test;
#[bench]
fn b1_fail(_b: &mut test::Bencher) { assert_eq!(1, 2); }
fn b1_fail(_b: &mut test::Bencher) { assert_eq!(1, 2, "ONE=TWO"); }
"#,
)
.build();
Expand All @@ -1468,48 +1447,15 @@ fn test_bench_no_fail_fast() {
`--bench b1`
"#]])
.with_stdout_data(str![[r#"
running 2 tests
test bench_hello ... bench: [AVG_ELAPSED] ns/iter (+/- [JITTER])
test bench_nope ... FAILED
failures:
---- bench_nope stdout ----
thread 'main' panicked at src/main.rs:20:17:
assertion `left == right` failed
left: "nope"
right: "hello"
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
bench_nope
test result: FAILED. 0 passed; 1 failed; 0 ignored; 1 measured; 0 filtered out; finished in [ELAPSED]s
running 1 test
test b1_fail ... FAILED
failures:
---- b1_fail stdout ----
thread 'main' panicked at benches/b1.rs:5:54:
assertion `left == right` failed
left: 1
right: 2
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
b1_fail
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.with_stdout_data(
r#"
...
[..]NOPE![..]
...
[..]ONE=TWO[..]
...
"#,
)
.run();
}

Expand Down
6 changes: 1 addition & 5 deletions tests/testsuite/features2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,11 +1120,7 @@ it is true
// Make sure the test is fallible.
p.cargo("test --doc")
.with_status(101)
.with_stdout_data(str![[r#"
...
assertion `left == right` failed: common is wrong
...
"#]])
.with_stdout_data("...\n[..]common is wrong[..]\n...")
.run();
p.cargo("test --doc").env("TEST_EXPECTS_ENABLED", "1").run();
p.cargo("doc").run();
Expand Down
58 changes: 3 additions & 55 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,29 +1883,7 @@ fn dirty_both_lib_and_test() {
// 2 != 1
p.cargo("test --lib")
.with_status(101)
.with_stdout_data(str![[r#"
running 1 test
test t1 ... FAILED
failures:
---- t1 stdout ----
...
thread 't1' panicked at src/lib.rs:8:21:
assertion `left == right` failed: doit assert failure
left: 2
right: 1
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
t1
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.with_stdout_data("...\n[..]doit assert failure[..]\n...")
.run();

if is_coarse_mtime() {
Expand Down Expand Up @@ -1949,42 +1927,12 @@ fn script_fails_stay_dirty() {
}
p.change_file("helper.rs", r#"pub fn doit() {panic!("Crash!");}"#);
p.cargo("build")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[ERROR] failed to run custom build command for `foo v0.0.1 ([ROOT]/foo)`
Caused by:
process didn't exit successfully: `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` ([EXIT_STATUS]: 101)
--- stdout
cargo::rerun-if-changed=build.rs
--- stderr
...
thread 'main' panicked at helper.rs:1:16:
Crash!
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
"#]])
.with_stderr_data("...\n[..]Crash![..]\n...")
.with_status(101)
.run();
// There was a bug where this second call would be "fresh".
p.cargo("build")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[ERROR] failed to run custom build command for `foo v0.0.1 ([ROOT]/foo)`
Caused by:
process didn't exit successfully: `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` ([EXIT_STATUS]: 101)
--- stdout
cargo::rerun-if-changed=build.rs
--- stderr
...
thread 'main' panicked at helper.rs:1:16:
Crash!
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
"#]])
.with_stderr_data("...\n[..]Crash![..]\n...")
.with_status(101)
.run();
}
Expand Down
10 changes: 2 additions & 8 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ fn do_not_rebuilds_on_local_install() {
#[cargo_test]
fn reports_unsuccessful_subcommand_result() {
Package::new("cargo-fail", "1.0.0")
.file("src/main.rs", "fn main() { panic!(); }")
.file("src/main.rs", r#"fn main() { panic!("EXPLICIT PANIC!"); }"#)
.publish();
cargo_process("install cargo-fail").run();
cargo_process("--list")
Expand All @@ -1326,13 +1326,7 @@ fn reports_unsuccessful_subcommand_result() {
.run();
cargo_process("fail")
.with_status(101)
.with_stderr_data(str![[r#"
...
thread 'main' panicked at [ROOT]/home/.cargo/registry/src/-[HASH]/cargo-fail-1.0.0/src/main.rs:1:13:
explicit panic
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
"#]])
.with_stderr_data("...\n[..]EXPLICIT PANIC![..]\n...")
.run();
}

Expand Down
60 changes: 4 additions & 56 deletions tests/testsuite/jobserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ this is a runner
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/cargo-jobserver-check[EXE]`
...
thread 'main' panicked at src/main.rs:5:43:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[..]no jobserver from env[..]
...
"#]])
Expand All @@ -250,40 +248,14 @@ no jobserver from env: NotPresent
[RUNNING] `runner target/debug/cargo-jobserver-check[EXE]`
this is a runner
...
thread 'main' panicked at src/main.rs:5:43:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
...
thread 'main' panicked at src/main.rs:6:17:
assertion failed: status.success()
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[..]no jobserver from env[..]
...
"#]])
.run();
p.cargo("test -j2")
.with_status(101)
.with_stdout_data(str![[r#"
running 1 test
test test ... FAILED
failures:
---- test stdout ----
...
thread 'test' panicked at src/lib.rs:4:42:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
test
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.with_stdout_data("...\n[..]no jobserver from env[..]\n...")
.run();
p.cargo("test -j2")
.env("PATH", path)
Expand All @@ -295,33 +267,9 @@ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out;
[RUNNING] unittests src/lib.rs (target/debug/deps/cargo_jobserver_check-[HASH][EXE])
this is a runner
...
thread 'main' panicked at src/main.rs:6:17:
assertion failed: status.success()
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[ERROR] test failed, to rerun pass `--lib`
"#]])
.with_stdout_data(str![[r#"
running 1 test
test test ... FAILED
failures:
---- test stdout ----
...
thread 'test' panicked at src/lib.rs:4:42:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
test
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.with_stdout_data("...\n[..]no jobserver from env[..]\n...")
.run();
}

Expand Down
Loading

0 comments on commit fe50f67

Please sign in to comment.