blob: bbaad4badf1a0fba23e8bfa2e0352e8a4bd52050 [file] [log] [blame]
Chris Wailese3116c42021-07-13 14:40:48 -07001//! Tests for future-incompat-report messages
2
3use cargo_test_support::registry::Package;
4use cargo_test_support::{basic_manifest, is_nightly, project};
5
6#[cargo_test]
7fn no_output_on_stable() {
8 let p = project()
9 .file("Cargo.toml", &basic_manifest("foo", "0.0.0"))
10 .file("src/main.rs", "fn main() { [true].into_iter(); }")
11 .build();
12
13 p.cargo("build")
14 .with_stderr_contains(" = note: `#[warn(array_into_iter)]` on by default")
15 .with_stderr_does_not_contain("[..]crates[..]")
16 .run();
17}
18
19#[cargo_test]
20fn gate_future_incompat_report() {
21 let p = project()
22 .file("Cargo.toml", &basic_manifest("foo", "0.0.0"))
23 .file("src/main.rs", "fn main() { [true].into_iter(); }")
24 .build();
25
26 p.cargo("build --future-incompat-report")
27 .with_stderr_contains("error: the `--future-incompat-report` flag is unstable[..]")
28 .with_status(101)
29 .run();
30
31 // Both `-Z future-incompat-report` and `-Z unstable-opts` are required
32 p.cargo("build --future-incompat-report -Z future-incompat-report")
33 .masquerade_as_nightly_cargo()
34 .with_stderr_contains("error: the `--future-incompat-report` flag is unstable[..]")
35 .with_status(101)
36 .run();
37
38 p.cargo("build --future-incompat-report -Z unstable-options")
39 .masquerade_as_nightly_cargo()
40 .with_stderr_contains(
41 "error: Usage of `--future-incompat-report` requires `-Z future-incompat-report`",
42 )
43 .with_status(101)
44 .run();
45
46 p.cargo("describe-future-incompatibilities --id foo")
47 .with_stderr_contains(
48 "error: `cargo describe-future-incompatibilities` can only be used on the nightly channel"
49 )
50 .with_status(101)
51 .run();
52}
53
54#[cargo_test]
55fn test_single_crate() {
56 if !is_nightly() {
57 return;
58 }
59
60 let p = project()
61 .file("Cargo.toml", &basic_manifest("foo", "0.0.0"))
62 .file("src/main.rs", "fn main() { [true].into_iter(); }")
63 .build();
64
65 for command in &["build", "check", "rustc", "test"] {
66 p.cargo(command).arg("-Zfuture-incompat-report")
67 .masquerade_as_nightly_cargo()
68 .with_stderr_contains(" = note: `#[warn(array_into_iter)]` on by default")
69 .with_stderr_contains("warning: the following crates contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]")
70 .with_stderr_does_not_contain("[..]incompatibility[..]")
71 .run();
72
73 p.cargo(command).arg("-Zfuture-incompat-report").arg("-Zunstable-options").arg("--future-incompat-report")
74 .masquerade_as_nightly_cargo()
75 .with_stderr_contains(" = note: `#[warn(array_into_iter)]` on by default")
76 .with_stderr_contains("warning: the following crates contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]")
77 .with_stderr_contains("The crate `foo v0.0.0 ([..])` currently triggers the following future incompatibility lints:")
78 .run();
79 }
80}
81
82#[cargo_test]
83fn test_multi_crate() {
84 if !is_nightly() {
85 return;
86 }
87
88 Package::new("first-dep", "0.0.1")
89 .file("src/lib.rs", "fn foo() { [25].into_iter(); }")
90 .publish();
91 Package::new("second-dep", "0.0.2")
92 .file("src/lib.rs", "fn foo() { ['a'].into_iter(); }")
93 .publish();
94
95 let p = project()
96 .file(
97 "Cargo.toml",
98 r#"
99 [package]
100 name = "foo"
101 version = "0.0.0"
102
103 [dependencies]
104 first-dep = "*"
105 second-dep = "*"
106 "#,
107 )
108 .file("src/main.rs", "fn main() {}")
109 .build();
110
111 for command in &["build", "check", "rustc", "test"] {
112 p.cargo(command).arg("-Zfuture-incompat-report")
113 .masquerade_as_nightly_cargo()
114 .with_stderr_does_not_contain("[..]array_into_iter[..]")
115 .with_stderr_contains("warning: the following crates contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2")
116 // Check that we don't have the 'triggers' message shown at the bottom of this loop
117 .with_stderr_does_not_contain("[..]triggers[..]")
118 .run();
119
120 p.cargo("describe-future-incompatibilities -Z future-incompat-report --id bad-id")
121 .masquerade_as_nightly_cargo()
122 .with_stderr_contains("error: Expected an id of [..]")
123 .with_stderr_does_not_contain("[..]triggers[..]")
124 .with_status(101)
125 .run();
126
127 p.cargo(command).arg("-Zunstable-options").arg("-Zfuture-incompat-report").arg("--future-incompat-report")
128 .masquerade_as_nightly_cargo()
129 .with_stderr_contains("warning: the following crates contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2")
130 .with_stderr_contains("The crate `first-dep v0.0.1` currently triggers the following future incompatibility lints:")
131 .with_stderr_contains("The crate `second-dep v0.0.2` currently triggers the following future incompatibility lints:")
132 .run();
133 }
134
135 // Test that passing the correct id via '--id' doesn't generate a warning message
136 let output = p
137 .cargo("build -Z future-incompat-report")
138 .masquerade_as_nightly_cargo()
139 .exec_with_output()
140 .unwrap();
141
142 // Extract the 'id' from the stdout. We are looking
143 // for the id in a line of the form "run `cargo describe-future-incompatibilities --id yZ7S`"
144 // which is generated by Cargo to tell the user what command to run
145 // This is just to test that passing the id suppresses the warning mesasge. Any users needing
146 // access to the report from a shell script should use the `--future-incompat-report` flag
147 let stderr = std::str::from_utf8(&output.stderr).unwrap();
148
149 // Find '--id <ID>' in the output
150 let mut iter = stderr.split(" ");
151 iter.find(|w| *w == "--id").unwrap();
152 let id = iter
153 .next()
154 .unwrap_or_else(|| panic!("Unexpected output:\n{}", stderr));
155 // Strip off the trailing '`' included in the output
156 let id: String = id.chars().take_while(|c| *c != '`').collect();
157
158 p.cargo(&format!("describe-future-incompatibilities -Z future-incompat-report --id {}", id))
159 .masquerade_as_nightly_cargo()
160 .with_stderr_contains("The crate `first-dep v0.0.1` currently triggers the following future incompatibility lints:")
161 .with_stderr_contains("The crate `second-dep v0.0.2` currently triggers the following future incompatibility lints:")
162 .run();
163}