|
1 | 1 | //! Tests for hints.
|
2 | 2 |
|
3 | 3 | use cargo_test_support::prelude::*;
|
| 4 | +use cargo_test_support::registry::Package; |
4 | 5 | use cargo_test_support::{project, str};
|
5 | 6 |
|
6 | 7 | #[cargo_test]
|
@@ -57,3 +58,238 @@ fn unknown_hints_warn() {
|
57 | 58 | "#]])
|
58 | 59 | .run();
|
59 | 60 | }
|
| 61 | + |
| 62 | +#[cargo_test] |
| 63 | +fn hint_unknown_type_warn() { |
| 64 | + Package::new("bar", "1.0.0") |
| 65 | + .file( |
| 66 | + "Cargo.toml", |
| 67 | + r#" |
| 68 | + [package] |
| 69 | + name = "bar" |
| 70 | + version = "1.0.0" |
| 71 | + edition = "2015" |
| 72 | +
|
| 73 | + [hints] |
| 74 | + mostly-unused = 1 |
| 75 | + "#, |
| 76 | + ) |
| 77 | + .file("src/lib.rs", "") |
| 78 | + .publish(); |
| 79 | + let p = project() |
| 80 | + .file( |
| 81 | + "Cargo.toml", |
| 82 | + r#" |
| 83 | + [package] |
| 84 | + name = "foo" |
| 85 | + version = "0.0.1" |
| 86 | + edition = "2015" |
| 87 | +
|
| 88 | + [dependencies] |
| 89 | + bar = "1.0" |
| 90 | + "#, |
| 91 | + ) |
| 92 | + .file("src/main.rs", "fn main() {}") |
| 93 | + .build(); |
| 94 | + p.cargo("check -v") |
| 95 | + .with_stderr_data(str![[r#" |
| 96 | +[UPDATING] `dummy-registry` index |
| 97 | +[LOCKING] 1 package to latest compatible version |
| 98 | +[DOWNLOADING] crates ... |
| 99 | +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) |
| 100 | +[CHECKING] bar v1.0.0 |
| 101 | +[RUNNING] `rustc --crate-name bar [..]` |
| 102 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 103 | +[RUNNING] `rustc --crate-name foo [..]` |
| 104 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 105 | +
|
| 106 | +"#]]) |
| 107 | + .with_stderr_does_not_contain("-Zhint-mostly-unused") |
| 108 | + .run(); |
| 109 | +} |
| 110 | + |
| 111 | +#[cargo_test] |
| 112 | +fn hints_mostly_unused_warn_without_gate() { |
| 113 | + Package::new("bar", "1.0.0") |
| 114 | + .file( |
| 115 | + "Cargo.toml", |
| 116 | + r#" |
| 117 | + [package] |
| 118 | + name = "bar" |
| 119 | + version = "1.0.0" |
| 120 | + edition = "2015" |
| 121 | +
|
| 122 | + [hints] |
| 123 | + mostly-unused = true |
| 124 | + "#, |
| 125 | + ) |
| 126 | + .file("src/lib.rs", "") |
| 127 | + .publish(); |
| 128 | + let p = project() |
| 129 | + .file( |
| 130 | + "Cargo.toml", |
| 131 | + r#" |
| 132 | + [package] |
| 133 | + name = "foo" |
| 134 | + version = "0.0.1" |
| 135 | + edition = "2015" |
| 136 | +
|
| 137 | + [dependencies] |
| 138 | + bar = "1.0" |
| 139 | + "#, |
| 140 | + ) |
| 141 | + .file("src/main.rs", "fn main() {}") |
| 142 | + .build(); |
| 143 | + p.cargo("check -v") |
| 144 | + .with_stderr_data(str![[r#" |
| 145 | +[UPDATING] `dummy-registry` index |
| 146 | +[LOCKING] 1 package to latest compatible version |
| 147 | +[DOWNLOADING] crates ... |
| 148 | +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) |
| 149 | +[CHECKING] bar v1.0.0 |
| 150 | +[RUNNING] `rustc --crate-name bar [..]` |
| 151 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 152 | +[RUNNING] `rustc --crate-name foo [..]` |
| 153 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 154 | +
|
| 155 | +"#]]) |
| 156 | + .with_stderr_does_not_contain("-Zhint-mostly-unused") |
| 157 | + .run(); |
| 158 | +} |
| 159 | + |
| 160 | +#[cargo_test(nightly, reason = "-Zhint-mostly-unused is unstable")] |
| 161 | +fn hints_mostly_unused_nightly() { |
| 162 | + Package::new("bar", "1.0.0") |
| 163 | + .file( |
| 164 | + "Cargo.toml", |
| 165 | + r#" |
| 166 | + [package] |
| 167 | + name = "bar" |
| 168 | + version = "1.0.0" |
| 169 | + edition = "2015" |
| 170 | +
|
| 171 | + [hints] |
| 172 | + mostly-unused = true |
| 173 | + "#, |
| 174 | + ) |
| 175 | + .file("src/lib.rs", "") |
| 176 | + .publish(); |
| 177 | + let p = project() |
| 178 | + .file( |
| 179 | + "Cargo.toml", |
| 180 | + r#" |
| 181 | + [package] |
| 182 | + name = "foo" |
| 183 | + version = "0.0.1" |
| 184 | + edition = "2015" |
| 185 | +
|
| 186 | + [dependencies] |
| 187 | + bar = "1.0" |
| 188 | + "#, |
| 189 | + ) |
| 190 | + .file("src/main.rs", "fn main() {}") |
| 191 | + .build(); |
| 192 | + p.cargo("check -Zprofile-hint-mostly-unused -v") |
| 193 | + .masquerade_as_nightly_cargo(&["profile-hint-mostly-unused"]) |
| 194 | + .with_stderr_data(str![[r#" |
| 195 | +[UPDATING] `dummy-registry` index |
| 196 | +[LOCKING] 1 package to latest compatible version |
| 197 | +[DOWNLOADING] crates ... |
| 198 | +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) |
| 199 | +[CHECKING] bar v1.0.0 |
| 200 | +[RUNNING] `rustc --crate-name bar [..]` |
| 201 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 202 | +[RUNNING] `rustc --crate-name foo [..]` |
| 203 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 204 | +
|
| 205 | +"#]]) |
| 206 | + .with_stderr_does_not_contain( |
| 207 | + "[RUNNING] `rustc --crate-name foo [..] -Zhint-mostly-unused [..]", |
| 208 | + ) |
| 209 | + .run(); |
| 210 | +} |
| 211 | + |
| 212 | +#[cargo_test(nightly, reason = "-Zhint-mostly-unused is unstable")] |
| 213 | +fn mostly_unused_profile_overrides_hints_nightly() { |
| 214 | + Package::new("bar", "1.0.0") |
| 215 | + .file( |
| 216 | + "Cargo.toml", |
| 217 | + r#" |
| 218 | + [package] |
| 219 | + name = "bar" |
| 220 | + version = "1.0.0" |
| 221 | + edition = "2015" |
| 222 | +
|
| 223 | + [hints] |
| 224 | + mostly-unused = true |
| 225 | + "#, |
| 226 | + ) |
| 227 | + .file("src/lib.rs", "") |
| 228 | + .publish(); |
| 229 | + let p = project() |
| 230 | + .file( |
| 231 | + "Cargo.toml", |
| 232 | + r#" |
| 233 | + [package] |
| 234 | + name = "foo" |
| 235 | + version = "0.0.1" |
| 236 | + edition = "2015" |
| 237 | +
|
| 238 | + [dependencies] |
| 239 | + bar = "1.0" |
| 240 | +
|
| 241 | + [profile.dev.package.bar] |
| 242 | + hint-mostly-unused = false |
| 243 | + "#, |
| 244 | + ) |
| 245 | + .file("src/main.rs", "fn main() {}") |
| 246 | + .build(); |
| 247 | + p.cargo("check -Zprofile-hint-mostly-unused -v") |
| 248 | + .masquerade_as_nightly_cargo(&["profile-hint-mostly-unused"]) |
| 249 | + .with_stderr_data(str![[r#" |
| 250 | +[UPDATING] `dummy-registry` index |
| 251 | +[LOCKING] 1 package to latest compatible version |
| 252 | +[DOWNLOADING] crates ... |
| 253 | +[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`) |
| 254 | +[CHECKING] bar v1.0.0 |
| 255 | +[RUNNING] `rustc --crate-name bar [..]` |
| 256 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 257 | +[RUNNING] `rustc --crate-name foo [..]` |
| 258 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 259 | +
|
| 260 | +"#]]) |
| 261 | + .with_stderr_does_not_contain("-Zhint-mostly-unused") |
| 262 | + .run(); |
| 263 | +} |
| 264 | + |
| 265 | +#[cargo_test(nightly, reason = "-Zhint-mostly-unused is unstable")] |
| 266 | +fn mostly_unused_profile_overrides_hints_on_self_nightly() { |
| 267 | + let p = project() |
| 268 | + .file( |
| 269 | + "Cargo.toml", |
| 270 | + r#" |
| 271 | + [package] |
| 272 | + name = "foo" |
| 273 | + version = "0.0.1" |
| 274 | + edition = "2015" |
| 275 | +
|
| 276 | + [hints] |
| 277 | + mostly-unused = true |
| 278 | +
|
| 279 | + [profile.dev] |
| 280 | + hint-mostly-unused = false |
| 281 | + "#, |
| 282 | + ) |
| 283 | + .file("src/main.rs", "fn main() {}") |
| 284 | + .build(); |
| 285 | + p.cargo("check -v") |
| 286 | + .with_stderr_data(str![[r#" |
| 287 | +[WARNING] unused manifest key: hints |
| 288 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 289 | +[RUNNING] `rustc --crate-name foo [..]` |
| 290 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 291 | +
|
| 292 | +"#]]) |
| 293 | + .with_stderr_does_not_contain("-Zhint-mostly-unused") |
| 294 | + .run(); |
| 295 | +} |
0 commit comments