Skip to content

Commit 941c414

Browse files
committed
Add test for cached report id
1 parent 307cbfd commit 941c414

File tree

1 file changed

+113
-8
lines changed

1 file changed

+113
-8
lines changed

tests/testsuite/future_incompat_report.rs

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,47 @@ use super::config::write_config_toml;
1515

1616
// An arbitrary lint (unused_variables) that triggers a lint.
1717
// We use a special flag to force it to generate a report.
18-
const FUTURE_EXAMPLE: &'static str = "fn main() { let x = 1; }";
18+
const FUTURE_EXAMPLE: &'static str = "pub fn foo() { let x = 1; }";
1919
// Some text that will be displayed when the lint fires.
2020
const FUTURE_OUTPUT: &'static str = "[..]unused variable[..]";
2121

22-
fn simple_project() -> Project {
22+
/// A project with a future-incompat error in the local package.
23+
fn local_project() -> Project {
2324
project()
2425
.file("Cargo.toml", &basic_manifest("foo", "0.0.0"))
25-
.file("src/main.rs", FUTURE_EXAMPLE)
26+
.file("src/lib.rs", FUTURE_EXAMPLE)
27+
.build()
28+
}
29+
30+
/// A project with a future-incompat error in a dependency.
31+
fn dependency_project() -> Project {
32+
Package::new("bar", "1.0.0")
33+
.file(
34+
"Cargo.toml",
35+
r#"
36+
[package]
37+
name = "bar"
38+
version = "1.0.0"
39+
edition = "2015"
40+
repository = "https://example.com/"
41+
"#,
42+
)
43+
.file("src/lib.rs", FUTURE_EXAMPLE)
44+
.publish();
45+
project()
46+
.file(
47+
"Cargo.toml",
48+
r#"
49+
[package]
50+
name = "foo"
51+
version = "1.0.0"
52+
edition = "2015"
53+
54+
[dependencies]
55+
bar = "1.0"
56+
"#,
57+
)
58+
.file("src/lib.rs", "")
2659
.build()
2760
}
2861

@@ -31,7 +64,7 @@ fn simple_project() -> Project {
3164
reason = "-Zfuture-incompat-test requires nightly (permanently)"
3265
)]
3366
fn output_on_stable() {
34-
let p = simple_project();
67+
let p = local_project();
3568

3669
p.cargo("check")
3770
.env("RUSTFLAGS", "-Zfuture-incompat-test")
@@ -48,7 +81,7 @@ fn output_on_stable() {
4881
// This feature is stable, and should not be gated
4982
#[cargo_test]
5083
fn no_gate_future_incompat_report() {
51-
let p = simple_project();
84+
let p = local_project();
5285

5386
p.cargo("check --future-incompat-report")
5487
.with_status(0)
@@ -98,7 +131,7 @@ fn test_zero_future_incompat() {
98131
reason = "-Zfuture-incompat-test requires nightly (permanently)"
99132
)]
100133
fn test_single_crate() {
101-
let p = simple_project();
134+
let p = local_project();
102135

103136
for command in &["build", "check", "rustc", "test"] {
104137
let check_has_future_compat = || {
@@ -315,7 +348,7 @@ The package `second-dep v0.0.2` currently triggers the following future incompat
315348
reason = "-Zfuture-incompat-test requires nightly (permanently)"
316349
)]
317350
fn color() {
318-
let p = simple_project();
351+
let p = local_project();
319352

320353
p.cargo("check")
321354
.env("RUSTFLAGS", "-Zfuture-incompat-test")
@@ -337,7 +370,7 @@ fn color() {
337370
reason = "-Zfuture-incompat-test requires nightly (permanently)"
338371
)]
339372
fn bad_ids() {
340-
let p = simple_project();
373+
let p = local_project();
341374

342375
p.cargo("report future-incompatibilities --id 1")
343376
.with_status(101)
@@ -451,3 +484,75 @@ with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.
451484
"#]])
452485
.run();
453486
}
487+
488+
#[cargo_test(
489+
nightly,
490+
reason = "-Zfuture-incompat-test requires nightly (permanently)"
491+
)]
492+
fn correct_report_id_when_cached() {
493+
// Checks for a bug where the `--id` value was off-by-one when the report
494+
// is already cached.
495+
let p = dependency_project();
496+
497+
p.cargo("check --future-incompat-report")
498+
.env("RUSTFLAGS", "-Zfuture-incompat-test")
499+
.with_stderr_data(str![[r#"
500+
[UPDATING] `dummy-registry` index
501+
[LOCKING] 1 package to latest compatible version
502+
[DOWNLOADING] crates ...
503+
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
504+
[CHECKING] bar v1.0.0
505+
[CHECKING] foo v1.0.0 ([ROOT]/foo)
506+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
507+
[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0
508+
[NOTE]
509+
To solve this problem, you can try the following approaches:
510+
511+
512+
- If the issue is not solved by updating the dependencies, a fix has to be
513+
implemented by those dependencies. You can help with that by notifying the
514+
maintainers of this problem (e.g. by creating a bug report) or by proposing a
515+
fix to the maintainers (e.g. by creating a pull request):
516+
517+
- bar@1.0.0
518+
- Repository: https://example.com/
519+
- Detailed warning command: `cargo report future-incompatibilities --id 1 --package bar@1.0.0`
520+
521+
- If waiting for an upstream fix is not an option, you can use the `[patch]`
522+
section in `Cargo.toml` to use your own version of the dependency. For more
523+
information, see:
524+
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section
525+
526+
[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1`
527+
528+
"#]])
529+
.run();
530+
531+
p.cargo("check --future-incompat-report")
532+
.env("RUSTFLAGS", "-Zfuture-incompat-test")
533+
.with_stderr_data(str![[r#"
534+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
535+
[WARNING] the following packages contain code that will be rejected by a future version of Rust: bar v1.0.0
536+
[NOTE]
537+
To solve this problem, you can try the following approaches:
538+
539+
540+
- If the issue is not solved by updating the dependencies, a fix has to be
541+
implemented by those dependencies. You can help with that by notifying the
542+
maintainers of this problem (e.g. by creating a bug report) or by proposing a
543+
fix to the maintainers (e.g. by creating a pull request):
544+
545+
- bar@1.0.0
546+
- Repository: https://example.com/
547+
- Detailed warning command: `cargo report future-incompatibilities --id 2 --package bar@1.0.0`
548+
549+
- If waiting for an upstream fix is not an option, you can use the `[patch]`
550+
section in `Cargo.toml` to use your own version of the dependency. For more
551+
information, see:
552+
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section
553+
554+
[NOTE] this report can be shown with `cargo report future-incompatibilities --id 1`
555+
556+
"#]])
557+
.run();
558+
}

0 commit comments

Comments
 (0)