Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 1 | //! Tests for future-incompat-report messages |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 2 | //! |
| 3 | //! Note that these tests use the -Zfuture-incompat-test for rustc. |
| 4 | //! This causes rustc to treat *every* lint as future-incompatible. |
| 5 | //! This is done because future-incompatible lints are inherently |
| 6 | //! ephemeral, but we don't want to continually update these tests. |
| 7 | //! So we pick some random lint that will likely always be the same |
| 8 | //! over time. |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 9 | |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame] | 10 | use super::config::write_config_toml; |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 11 | use cargo_test_support::registry::Package; |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 12 | use cargo_test_support::{basic_manifest, project, Project}; |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 13 | |
| 14 | // An arbitrary lint (unused_variables) that triggers a lint. |
| 15 | // We use a special flag to force it to generate a report. |
| 16 | const FUTURE_EXAMPLE: &'static str = "fn main() { let x = 1; }"; |
| 17 | // Some text that will be displayed when the lint fires. |
| 18 | const FUTURE_OUTPUT: &'static str = "[..]unused_variables[..]"; |
| 19 | |
| 20 | fn simple_project() -> Project { |
| 21 | project() |
| 22 | .file("Cargo.toml", &basic_manifest("foo", "0.0.0")) |
| 23 | .file("src/main.rs", FUTURE_EXAMPLE) |
| 24 | .build() |
| 25 | } |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 26 | |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 27 | #[cargo_test( |
| 28 | nightly, |
| 29 | reason = "-Zfuture-incompat-test requires nightly (permanently)" |
| 30 | )] |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 31 | fn output_on_stable() { |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 32 | let p = simple_project(); |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 33 | |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 34 | p.cargo("check") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 35 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 36 | .with_stderr_contains(FUTURE_OUTPUT) |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 37 | .with_stderr_contains("[..]cargo report[..]") |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 38 | .run(); |
| 39 | } |
| 40 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 41 | // This feature is stable, and should not be gated |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 42 | #[cargo_test] |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 43 | fn no_gate_future_incompat_report() { |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 44 | let p = simple_project(); |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 45 | |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 46 | p.cargo("check --future-incompat-report") |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 47 | .with_status(0) |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 48 | .run(); |
| 49 | |
Chris Wailes | 2f3fdfe | 2021-07-29 10:56:18 -0700 | [diff] [blame] | 50 | p.cargo("report future-incompatibilities --id foo") |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 51 | .with_stderr_contains("error: no reports are currently available") |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 52 | .with_status(101) |
| 53 | .run(); |
| 54 | } |
| 55 | |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 56 | #[cargo_test( |
| 57 | nightly, |
| 58 | reason = "-Zfuture-incompat-test requires nightly (permanently)" |
| 59 | )] |
Chris Wailes | 32f7835 | 2021-07-20 14:04:55 -0700 | [diff] [blame] | 60 | fn test_zero_future_incompat() { |
Chris Wailes | 32f7835 | 2021-07-20 14:04:55 -0700 | [diff] [blame] | 61 | let p = project() |
| 62 | .file("Cargo.toml", &basic_manifest("foo", "0.0.0")) |
| 63 | .file("src/main.rs", "fn main() {}") |
| 64 | .build(); |
| 65 | |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 66 | // No note if --future-incompat-report is not specified. |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 67 | p.cargo("check") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 68 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 69 | .with_stderr( |
| 70 | "\ |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 71 | [CHECKING] foo v0.0.0 [..] |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 72 | [FINISHED] [..] |
| 73 | ", |
| 74 | ) |
| 75 | .run(); |
| 76 | |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 77 | p.cargo("check --future-incompat-report") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 78 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 79 | .with_stderr( |
| 80 | "\ |
| 81 | [FINISHED] [..] |
| 82 | note: 0 dependencies had future-incompatible warnings |
| 83 | ", |
| 84 | ) |
Chris Wailes | 32f7835 | 2021-07-20 14:04:55 -0700 | [diff] [blame] | 85 | .run(); |
| 86 | } |
| 87 | |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 88 | #[cargo_test( |
| 89 | nightly, |
| 90 | reason = "-Zfuture-incompat-test requires nightly (permanently)" |
| 91 | )] |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 92 | fn test_single_crate() { |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 93 | let p = simple_project(); |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 94 | |
| 95 | for command in &["build", "check", "rustc", "test"] { |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame] | 96 | let check_has_future_compat = || { |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 97 | p.cargo(command) |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame] | 98 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 99 | .with_stderr_contains(FUTURE_OUTPUT) |
| 100 | .with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]") |
| 101 | .with_stderr_does_not_contain("[..]incompatibility[..]") |
| 102 | .run(); |
| 103 | }; |
| 104 | |
| 105 | // Check that we show a message with no [future-incompat-report] config section |
| 106 | write_config_toml(""); |
| 107 | check_has_future_compat(); |
| 108 | |
Charisee | 9cf6780 | 2022-06-30 20:04:09 +0000 | [diff] [blame] | 109 | // Check that we show a message with `frequency = "always"` |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame] | 110 | write_config_toml( |
| 111 | "\ |
| 112 | [future-incompat-report] |
| 113 | frequency = 'always' |
| 114 | ", |
| 115 | ); |
| 116 | check_has_future_compat(); |
| 117 | |
| 118 | // Check that we do not show a message with `frequency = "never"` |
| 119 | write_config_toml( |
| 120 | "\ |
| 121 | [future-incompat-report] |
| 122 | frequency = 'never' |
| 123 | ", |
| 124 | ); |
| 125 | p.cargo(command) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 126 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 127 | .with_stderr_contains(FUTURE_OUTPUT) |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame] | 128 | .with_stderr_does_not_contain("[..]rejected[..]") |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 129 | .with_stderr_does_not_contain("[..]incompatibility[..]") |
| 130 | .run(); |
| 131 | |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame] | 132 | // Check that passing `--future-incompat-report` overrides `frequency = 'never'` |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 133 | p.cargo(command).arg("--future-incompat-report") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 134 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 135 | .with_stderr_contains(FUTURE_OUTPUT) |
| 136 | .with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: foo v0.0.0 [..]") |
Charisee | 9cf6780 | 2022-06-30 20:04:09 +0000 | [diff] [blame] | 137 | .with_stderr_contains(" - foo@0.0.0[..]") |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 138 | .run(); |
| 139 | } |
| 140 | } |
| 141 | |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 142 | #[cargo_test( |
| 143 | nightly, |
| 144 | reason = "-Zfuture-incompat-test requires nightly (permanently)" |
| 145 | )] |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 146 | fn test_multi_crate() { |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 147 | Package::new("first-dep", "0.0.1") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 148 | .file("src/lib.rs", FUTURE_EXAMPLE) |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 149 | .publish(); |
| 150 | Package::new("second-dep", "0.0.2") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 151 | .file("src/lib.rs", FUTURE_EXAMPLE) |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 152 | .publish(); |
| 153 | |
| 154 | let p = project() |
| 155 | .file( |
| 156 | "Cargo.toml", |
| 157 | r#" |
| 158 | [package] |
| 159 | name = "foo" |
| 160 | version = "0.0.0" |
| 161 | |
| 162 | [dependencies] |
| 163 | first-dep = "*" |
| 164 | second-dep = "*" |
| 165 | "#, |
| 166 | ) |
| 167 | .file("src/main.rs", "fn main() {}") |
| 168 | .build(); |
| 169 | |
| 170 | for command in &["build", "check", "rustc", "test"] { |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 171 | p.cargo(command) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 172 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 173 | .with_stderr_does_not_contain(FUTURE_OUTPUT) |
| 174 | .with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2") |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 175 | // Check that we don't have the 'triggers' message shown at the bottom of this loop, |
| 176 | // and that we don't explain how to show a per-package report |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 177 | .with_stderr_does_not_contain("[..]triggers[..]") |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 178 | .with_stderr_does_not_contain("[..]--package[..]") |
| 179 | .with_stderr_does_not_contain("[..]-p[..]") |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 180 | .run(); |
| 181 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 182 | p.cargo(command).arg("--future-incompat-report") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 183 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
| 184 | .with_stderr_contains("warning: the following packages contain code that will be rejected by a future version of Rust: first-dep v0.0.1, second-dep v0.0.2") |
Charisee | 9cf6780 | 2022-06-30 20:04:09 +0000 | [diff] [blame] | 185 | .with_stderr_contains(" - first-dep@0.0.1") |
| 186 | .with_stderr_contains(" - second-dep@0.0.2") |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 187 | .run(); |
| 188 | |
Charisee | 9cf6780 | 2022-06-30 20:04:09 +0000 | [diff] [blame] | 189 | p.cargo("report future-incompatibilities").arg("--package").arg("first-dep@0.0.1") |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 190 | .with_stdout_contains("The package `first-dep v0.0.1` currently triggers the following future incompatibility lints:") |
| 191 | .with_stdout_contains(FUTURE_OUTPUT) |
| 192 | .with_stdout_does_not_contain("[..]second-dep-0.0.2/src[..]") |
| 193 | .run(); |
| 194 | |
Charisee | 9cf6780 | 2022-06-30 20:04:09 +0000 | [diff] [blame] | 195 | p.cargo("report future-incompatibilities").arg("--package").arg("second-dep@0.0.2") |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 196 | .with_stdout_contains("The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:") |
| 197 | .with_stdout_contains(FUTURE_OUTPUT) |
| 198 | .with_stdout_does_not_contain("[..]first-dep-0.0.1/src[..]") |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 199 | .run(); |
| 200 | } |
| 201 | |
| 202 | // Test that passing the correct id via '--id' doesn't generate a warning message |
| 203 | let output = p |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 204 | .cargo("check") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 205 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 206 | .exec_with_output() |
| 207 | .unwrap(); |
| 208 | |
| 209 | // Extract the 'id' from the stdout. We are looking |
Chris Wailes | 2f3fdfe | 2021-07-29 10:56:18 -0700 | [diff] [blame] | 210 | // for the id in a line of the form "run `cargo report future-incompatibilities --id yZ7S`" |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 211 | // which is generated by Cargo to tell the user what command to run |
| 212 | // This is just to test that passing the id suppresses the warning mesasge. Any users needing |
| 213 | // access to the report from a shell script should use the `--future-incompat-report` flag |
| 214 | let stderr = std::str::from_utf8(&output.stderr).unwrap(); |
| 215 | |
| 216 | // Find '--id <ID>' in the output |
Chris Wailes | 32f7835 | 2021-07-20 14:04:55 -0700 | [diff] [blame] | 217 | let mut iter = stderr.split(' '); |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 218 | iter.find(|w| *w == "--id").unwrap(); |
| 219 | let id = iter |
| 220 | .next() |
| 221 | .unwrap_or_else(|| panic!("Unexpected output:\n{}", stderr)); |
| 222 | // Strip off the trailing '`' included in the output |
| 223 | let id: String = id.chars().take_while(|c| *c != '`').collect(); |
| 224 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 225 | p.cargo(&format!("report future-incompatibilities --id {}", id)) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 226 | .with_stdout_contains("The package `first-dep v0.0.1` currently triggers the following future incompatibility lints:") |
| 227 | .with_stdout_contains("The package `second-dep v0.0.2` currently triggers the following future incompatibility lints:") |
| 228 | .run(); |
| 229 | |
| 230 | // Test without --id, and also the full output of the report. |
| 231 | let output = p |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 232 | .cargo("report future-incompat") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 233 | .exec_with_output() |
| 234 | .unwrap(); |
| 235 | let output = std::str::from_utf8(&output.stdout).unwrap(); |
| 236 | assert!(output.starts_with("The following warnings were discovered")); |
| 237 | let mut lines = output |
| 238 | .lines() |
| 239 | // Skip the beginning of the per-package information. |
| 240 | .skip_while(|line| !line.starts_with("The package")); |
| 241 | for expected in &["first-dep v0.0.1", "second-dep v0.0.2"] { |
| 242 | assert_eq!( |
| 243 | &format!( |
| 244 | "The package `{}` currently triggers the following future incompatibility lints:", |
| 245 | expected |
| 246 | ), |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 247 | lines.next().unwrap(), |
| 248 | "Bad output:\n{}", |
| 249 | output |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 250 | ); |
| 251 | let mut count = 0; |
| 252 | while let Some(line) = lines.next() { |
| 253 | if line.is_empty() { |
| 254 | break; |
| 255 | } |
| 256 | count += 1; |
| 257 | } |
| 258 | assert!(count > 0); |
| 259 | } |
| 260 | assert_eq!(lines.next(), None); |
| 261 | } |
| 262 | |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 263 | #[cargo_test( |
| 264 | nightly, |
| 265 | reason = "-Zfuture-incompat-test requires nightly (permanently)" |
| 266 | )] |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 267 | fn color() { |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 268 | let p = simple_project(); |
| 269 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 270 | p.cargo("check") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 271 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 272 | .masquerade_as_nightly_cargo(&["future-incompat-test"]) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 273 | .run(); |
| 274 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 275 | p.cargo("report future-incompatibilities") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 276 | .with_stdout_does_not_contain("[..]\x1b[[..]") |
| 277 | .run(); |
| 278 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 279 | p.cargo("report future-incompatibilities") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 280 | .env("CARGO_TERM_COLOR", "always") |
| 281 | .with_stdout_contains("[..]\x1b[[..]") |
| 282 | .run(); |
| 283 | } |
| 284 | |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 285 | #[cargo_test( |
| 286 | nightly, |
| 287 | reason = "-Zfuture-incompat-test requires nightly (permanently)" |
| 288 | )] |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 289 | fn bad_ids() { |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 290 | let p = simple_project(); |
| 291 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 292 | p.cargo("report future-incompatibilities --id 1") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 293 | .with_status(101) |
| 294 | .with_stderr("error: no reports are currently available") |
| 295 | .run(); |
| 296 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 297 | p.cargo("check") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 298 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 299 | .masquerade_as_nightly_cargo(&["future-incompat-test"]) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 300 | .run(); |
| 301 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 302 | p.cargo("report future-incompatibilities --id foo") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 303 | .with_status(1) |
| 304 | .with_stderr("error: Invalid value: could not parse `foo` as a number") |
| 305 | .run(); |
| 306 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 307 | p.cargo("report future-incompatibilities --id 7") |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 308 | .with_status(101) |
| 309 | .with_stderr( |
| 310 | "\ |
| 311 | error: could not find report with ID 7 |
| 312 | Available IDs are: 1 |
| 313 | ", |
| 314 | ) |
| 315 | .run(); |
| 316 | } |
| 317 | |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 318 | #[cargo_test( |
| 319 | nightly, |
| 320 | reason = "-Zfuture-incompat-test requires nightly (permanently)" |
| 321 | )] |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 322 | fn suggestions_for_updates() { |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 323 | Package::new("with_updates", "1.0.0") |
| 324 | .file("src/lib.rs", FUTURE_EXAMPLE) |
| 325 | .publish(); |
| 326 | Package::new("big_update", "1.0.0") |
| 327 | .file("src/lib.rs", FUTURE_EXAMPLE) |
| 328 | .publish(); |
| 329 | Package::new("without_updates", "1.0.0") |
| 330 | .file("src/lib.rs", FUTURE_EXAMPLE) |
| 331 | .publish(); |
| 332 | |
| 333 | let p = project() |
| 334 | .file( |
| 335 | "Cargo.toml", |
| 336 | r#" |
| 337 | [package] |
| 338 | name = "foo" |
| 339 | version = "0.1.0" |
| 340 | |
| 341 | [dependencies] |
| 342 | with_updates = "1" |
| 343 | big_update = "1" |
| 344 | without_updates = "1" |
| 345 | "#, |
| 346 | ) |
| 347 | .file("src/lib.rs", "") |
| 348 | .build(); |
| 349 | |
| 350 | p.cargo("generate-lockfile").run(); |
| 351 | |
| 352 | Package::new("with_updates", "1.0.1") |
| 353 | .file("src/lib.rs", "") |
| 354 | .publish(); |
| 355 | Package::new("with_updates", "1.0.2") |
| 356 | .file("src/lib.rs", "") |
| 357 | .publish(); |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 358 | Package::new("with_updates", "3.0.1") |
| 359 | .file("src/lib.rs", "") |
| 360 | .publish(); |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 361 | Package::new("big_update", "2.0.0") |
| 362 | .file("src/lib.rs", "") |
| 363 | .publish(); |
| 364 | |
| 365 | // This is a hack to force cargo to update the index. Cargo can't do this |
| 366 | // automatically because doing a network update on every build would be a |
| 367 | // bad idea. Under normal circumstances, we'll hope the user has done |
| 368 | // something else along the way to trigger an update (building some other |
| 369 | // project or something). This could use some more consideration of how to |
| 370 | // handle this better (maybe only trigger an update if it hasn't updated |
| 371 | // in a long while?). |
| 372 | p.cargo("update -p without_updates").run(); |
| 373 | |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 374 | let update_message = "\ |
| 375 | - Some affected dependencies have newer versions available. |
| 376 | You may want to consider updating them to a newer version to see if the issue has been fixed. |
| 377 | |
| 378 | big_update v1.0.0 has the following newer versions available: 2.0.0 |
| 379 | with_updates v1.0.0 has the following newer versions available: 1.0.1, 1.0.2, 3.0.1 |
| 380 | "; |
| 381 | |
Charisee | 7878d54 | 2022-02-24 18:21:36 +0000 | [diff] [blame] | 382 | p.cargo("check --future-incompat-report") |
Charisee | b1d3280 | 2022-09-22 15:38:41 +0000 | [diff] [blame] | 383 | .masquerade_as_nightly_cargo(&["future-incompat-test"]) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 384 | .env("RUSTFLAGS", "-Zfuture-incompat-test") |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 385 | .with_stderr_contains(update_message) |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 386 | .run(); |
| 387 | |
| 388 | p.cargo("report future-incompatibilities") |
Chris Wailes | 356b57e | 2022-01-13 10:08:24 -0800 | [diff] [blame] | 389 | .with_stdout_contains(update_message) |
| 390 | .run() |
Chris Wailes | e3116c4 | 2021-07-13 14:40:48 -0700 | [diff] [blame] | 391 | } |