|
| 1 | +use crate::prelude::*; |
| 2 | +use cargo_test_support::project; |
| 3 | +use cargo_test_support::str; |
| 4 | + |
| 5 | +#[cargo_test] |
| 6 | +fn fires_on_tree_url() { |
| 7 | + let p = project() |
| 8 | + .file( |
| 9 | + "Cargo.toml", |
| 10 | + r#" |
| 11 | +[workspace] |
| 12 | +
|
| 13 | +[package] |
| 14 | +name = "foo" |
| 15 | +version = "0.0.1" |
| 16 | +edition = "2015" |
| 17 | +repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 18 | +
|
| 19 | +[lints.cargo] |
| 20 | +uninherited_repository = "warn" |
| 21 | +"#, |
| 22 | + ) |
| 23 | + .file("src/lib.rs", "") |
| 24 | + .build(); |
| 25 | + |
| 26 | + p.cargo("check -Zcargo-lints") |
| 27 | + .masquerade_as_nightly_cargo(&["cargo-lints"]) |
| 28 | + .with_stderr_data(str![[r#" |
| 29 | +[WARNING] `package.repository` in a workspace member should be inherited from `[workspace.package]` |
| 30 | + --> Cargo.toml:8:1 |
| 31 | + | |
| 32 | +8 | repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 33 | + | [..] |
| 34 | + | |
| 35 | + = [NOTE] `cargo::uninherited_repository` is set to `warn` in `[lints]` |
| 36 | +[HELP] consider moving `repository` to `[workspace.package]` and inheriting it |
| 37 | + | |
| 38 | +8 - repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 39 | +8 + repository.workspace = true |
| 40 | + | |
| 41 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 42 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 43 | +
|
| 44 | +"#]]) |
| 45 | + .run(); |
| 46 | +} |
| 47 | + |
| 48 | +#[cargo_test] |
| 49 | +fn fires_on_blob_url() { |
| 50 | + let p = project() |
| 51 | + .file( |
| 52 | + "Cargo.toml", |
| 53 | + r#" |
| 54 | +[workspace] |
| 55 | +
|
| 56 | +[package] |
| 57 | +name = "foo" |
| 58 | +version = "0.0.1" |
| 59 | +edition = "2015" |
| 60 | +repository = "https://github.com/rust-lang/cargo/repo/blob/main/README.md" |
| 61 | +
|
| 62 | +[lints.cargo] |
| 63 | +uninherited_repository = "warn" |
| 64 | +"#, |
| 65 | + ) |
| 66 | + .file("src/lib.rs", "") |
| 67 | + .build(); |
| 68 | + |
| 69 | + p.cargo("check -Zcargo-lints") |
| 70 | + .masquerade_as_nightly_cargo(&["cargo-lints"]) |
| 71 | + .with_stderr_data(str![[r#" |
| 72 | +[WARNING] `package.repository` in a workspace member should be inherited from `[workspace.package]` |
| 73 | + --> Cargo.toml:8:1 |
| 74 | + | |
| 75 | +8 | repository = "https://github.com/rust-lang/cargo/repo/blob/main/README.md" |
| 76 | + | [..] |
| 77 | + | |
| 78 | + = [NOTE] `cargo::uninherited_repository` is set to `warn` in `[lints]` |
| 79 | +[HELP] consider moving `repository` to `[workspace.package]` and inheriting it |
| 80 | + | |
| 81 | +8 - repository = "https://github.com/rust-lang/cargo/repo/blob/main/README.md" |
| 82 | +8 + repository.workspace = true |
| 83 | + | |
| 84 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 85 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 86 | +
|
| 87 | +"#]]) |
| 88 | + .run(); |
| 89 | +} |
| 90 | + |
| 91 | +#[cargo_test] |
| 92 | +fn fires_on_root_url() { |
| 93 | + // Even a technically correct root URL should be inherited in a workspace. |
| 94 | + // The lint encourages inheritance regardless of the URL content. |
| 95 | + let p = project() |
| 96 | + .file( |
| 97 | + "Cargo.toml", |
| 98 | + r#" |
| 99 | +[workspace] |
| 100 | +
|
| 101 | +[package] |
| 102 | +name = "foo" |
| 103 | +version = "0.0.1" |
| 104 | +edition = "2015" |
| 105 | +repository = "https://github.com/rust-lang/cargo/repo" |
| 106 | +
|
| 107 | +[lints.cargo] |
| 108 | +uninherited_repository = "warn" |
| 109 | +"#, |
| 110 | + ) |
| 111 | + .file("src/lib.rs", "") |
| 112 | + .build(); |
| 113 | + |
| 114 | + p.cargo("check -Zcargo-lints") |
| 115 | + .masquerade_as_nightly_cargo(&["cargo-lints"]) |
| 116 | + .with_stderr_data(str![[r#" |
| 117 | +[WARNING] `package.repository` in a workspace member should be inherited from `[workspace.package]` |
| 118 | + --> Cargo.toml:8:1 |
| 119 | + | |
| 120 | +8 | repository = "https://github.com/rust-lang/cargo/repo" |
| 121 | + | [..] |
| 122 | + | |
| 123 | + = [NOTE] `cargo::uninherited_repository` is set to `warn` in `[lints]` |
| 124 | +[HELP] consider moving `repository` to `[workspace.package]` and inheriting it |
| 125 | + | |
| 126 | +8 - repository = "https://github.com/rust-lang/cargo/repo" |
| 127 | +8 + repository.workspace = true |
| 128 | + | |
| 129 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 130 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 131 | +
|
| 132 | +"#]]) |
| 133 | + .run(); |
| 134 | +} |
| 135 | + |
| 136 | +#[cargo_test] |
| 137 | +fn no_fire_without_workspace() { |
| 138 | + // Single-crate project (no explicit [workspace]) lint must not fire |
| 139 | + // because there is no [workspace.package] to inherit from. |
| 140 | + let p = project() |
| 141 | + .file( |
| 142 | + "Cargo.toml", |
| 143 | + r#" |
| 144 | +[package] |
| 145 | +name = "foo" |
| 146 | +version = "0.0.1" |
| 147 | +edition = "2015" |
| 148 | +repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 149 | +
|
| 150 | +[lints.cargo] |
| 151 | +uninherited_repository = "warn" |
| 152 | +"#, |
| 153 | + ) |
| 154 | + .file("src/lib.rs", "") |
| 155 | + .build(); |
| 156 | + |
| 157 | + p.cargo("check -Zcargo-lints") |
| 158 | + .masquerade_as_nightly_cargo(&["cargo-lints"]) |
| 159 | + .with_stderr_data(str![[r#" |
| 160 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 161 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 162 | +
|
| 163 | +"#]]) |
| 164 | + .run(); |
| 165 | +} |
| 166 | + |
| 167 | +#[cargo_test] |
| 168 | +fn no_fire_when_inherited() { |
| 169 | + // Already using workspace inheritance lint must not fire. |
| 170 | + let p = project() |
| 171 | + .file( |
| 172 | + "Cargo.toml", |
| 173 | + r#" |
| 174 | +[workspace.package] |
| 175 | +repository = "https://github.com/rust-lang/cargo/repo" |
| 176 | +
|
| 177 | +[package] |
| 178 | +name = "foo" |
| 179 | +version = "0.0.1" |
| 180 | +edition = "2015" |
| 181 | +repository.workspace = true |
| 182 | +
|
| 183 | +[lints.cargo] |
| 184 | +uninherited_repository = "warn" |
| 185 | +"#, |
| 186 | + ) |
| 187 | + .file("src/lib.rs", "") |
| 188 | + .build(); |
| 189 | + |
| 190 | + p.cargo("check -Zcargo-lints") |
| 191 | + .masquerade_as_nightly_cargo(&["cargo-lints"]) |
| 192 | + .with_stderr_data(str![[r#" |
| 193 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 194 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 195 | +
|
| 196 | +"#]]) |
| 197 | + .run(); |
| 198 | +} |
| 199 | + |
| 200 | +#[cargo_test] |
| 201 | +fn fires_in_workspace_member() { |
| 202 | + // A member crate with an explicit repository should trigger the lint on |
| 203 | + // its own manifest, not the workspace root. |
| 204 | + let p = project() |
| 205 | + .file( |
| 206 | + "Cargo.toml", |
| 207 | + r#" |
| 208 | +[workspace] |
| 209 | +members = ["crates/foo"] |
| 210 | +"#, |
| 211 | + ) |
| 212 | + .file( |
| 213 | + "crates/foo/Cargo.toml", |
| 214 | + r#" |
| 215 | +[package] |
| 216 | +name = "foo" |
| 217 | +version = "0.0.1" |
| 218 | +edition = "2015" |
| 219 | +repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 220 | +
|
| 221 | +[lints.cargo] |
| 222 | +uninherited_repository = "warn" |
| 223 | +"#, |
| 224 | + ) |
| 225 | + .file("crates/foo/src/lib.rs", "") |
| 226 | + .build(); |
| 227 | + |
| 228 | + p.cargo("check -Zcargo-lints") |
| 229 | + .masquerade_as_nightly_cargo(&["cargo-lints"]) |
| 230 | + .with_stderr_data(str![[r#" |
| 231 | +[WARNING] `package.repository` in a workspace member should be inherited from `[workspace.package]` |
| 232 | + --> crates/foo/Cargo.toml:6:1 |
| 233 | + | |
| 234 | +6 | repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 235 | + | [..] |
| 236 | + | |
| 237 | + = [NOTE] `cargo::uninherited_repository` is set to `warn` in `[lints]` |
| 238 | +[HELP] consider moving `repository` to `[workspace.package]` and inheriting it |
| 239 | + | |
| 240 | +6 - repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 241 | +6 + repository.workspace = true |
| 242 | + | |
| 243 | +[CHECKING] foo v0.0.1 ([ROOT]/foo/crates/foo) |
| 244 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 245 | +
|
| 246 | +"#]]) |
| 247 | + .run(); |
| 248 | +} |
| 249 | + |
| 250 | +#[cargo_test] |
| 251 | +fn suppressed_by_allow() { |
| 252 | + // Setting the lint to "allow" must silence it even when the field is explicit. |
| 253 | + let p = project() |
| 254 | + .file( |
| 255 | + "Cargo.toml", |
| 256 | + r#" |
| 257 | +[workspace] |
| 258 | +
|
| 259 | +[package] |
| 260 | +name = "foo" |
| 261 | +version = "0.0.1" |
| 262 | +edition = "2015" |
| 263 | +repository = "https://github.com/rust-lang/cargo/repo/tree/main/crates/foo" |
| 264 | +
|
| 265 | +[lints.cargo] |
| 266 | +uninherited_repository = "allow" |
| 267 | +"#, |
| 268 | + ) |
| 269 | + .file("src/lib.rs", "") |
| 270 | + .build(); |
| 271 | + |
| 272 | + p.cargo("check -Zcargo-lints") |
| 273 | + .masquerade_as_nightly_cargo(&["cargo-lints"]) |
| 274 | + .with_stderr_data(str![[r#" |
| 275 | +[CHECKING] foo v0.0.1 ([ROOT]/foo) |
| 276 | +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s |
| 277 | +
|
| 278 | +"#]]) |
| 279 | + .run(); |
| 280 | +} |
0 commit comments