|
1 | 1 | //! Tests for unstable `patch-files` feature.
|
2 | 2 |
|
3 |
| -use cargo_test_support::registry::Package; |
| 3 | +use cargo_test_support::basic_manifest; |
| 4 | +use cargo_test_support::git; |
| 5 | +use cargo_test_support::paths; |
4 | 6 | use cargo_test_support::project;
|
| 7 | +use cargo_test_support::registry; |
| 8 | +use cargo_test_support::registry::Package; |
5 | 9 | use cargo_test_support::str;
|
6 | 10 |
|
7 | 11 | #[cargo_test]
|
@@ -114,3 +118,192 @@ fn warn_if_in_normal_dep() {
|
114 | 118 | "#]])
|
115 | 119 | .run();
|
116 | 120 | }
|
| 121 | + |
| 122 | +#[cargo_test] |
| 123 | +fn disallow_non_exact_version() { |
| 124 | + Package::new("bar", "1.0.0").publish(); |
| 125 | + let p = project() |
| 126 | + .file( |
| 127 | + "Cargo.toml", |
| 128 | + r#" |
| 129 | + cargo-features = ["patch-files"] |
| 130 | +
|
| 131 | + [package] |
| 132 | + name = "foo" |
| 133 | + edition = "2015" |
| 134 | +
|
| 135 | + [dependencies] |
| 136 | + bar = "1" |
| 137 | +
|
| 138 | + [patch.crates-io] |
| 139 | + bar = { version = "1.0.0", patches = [] } |
| 140 | + "#, |
| 141 | + ) |
| 142 | + .file("src/lib.rs", "") |
| 143 | + .build(); |
| 144 | + |
| 145 | + p.cargo("check") |
| 146 | + .masquerade_as_nightly_cargo(&["patch-files"]) |
| 147 | + .with_status(101) |
| 148 | + .with_stderr_data(str![[r#" |
| 149 | +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 150 | +
|
| 151 | +Caused by: |
| 152 | + patch for `bar` in `https://github.com/rust-lang/crates.io-index` requires an exact version when patching with patch files |
| 153 | +
|
| 154 | +"#]]) |
| 155 | + .run(); |
| 156 | +} |
| 157 | + |
| 158 | +#[cargo_test] |
| 159 | +fn disallow_empty_patches_array() { |
| 160 | + Package::new("bar", "1.0.0").publish(); |
| 161 | + let p = project() |
| 162 | + .file( |
| 163 | + "Cargo.toml", |
| 164 | + r#" |
| 165 | + cargo-features = ["patch-files"] |
| 166 | +
|
| 167 | + [package] |
| 168 | + name = "foo" |
| 169 | + edition = "2015" |
| 170 | +
|
| 171 | + [dependencies] |
| 172 | + bar = "1" |
| 173 | +
|
| 174 | + [patch.crates-io] |
| 175 | + bar = { version = "=1.0.0", patches = [] } |
| 176 | + "#, |
| 177 | + ) |
| 178 | + .file("src/lib.rs", "") |
| 179 | + .build(); |
| 180 | + |
| 181 | + p.cargo("check") |
| 182 | + .masquerade_as_nightly_cargo(&["patch-files"]) |
| 183 | + .with_status(101) |
| 184 | + .with_stderr_data(str![[r#" |
| 185 | +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 186 | +
|
| 187 | +Caused by: |
| 188 | + patch for `bar` in `https://github.com/rust-lang/crates.io-index` requires at least one patch file when patching with patch files |
| 189 | +
|
| 190 | +"#]]) |
| 191 | + .run(); |
| 192 | +} |
| 193 | + |
| 194 | +#[cargo_test] |
| 195 | +fn disallow_mismatched_source_url() { |
| 196 | + registry::alt_init(); |
| 197 | + Package::new("bar", "1.0.0").alternative(true).publish(); |
| 198 | + let p = project() |
| 199 | + .file( |
| 200 | + "Cargo.toml", |
| 201 | + r#" |
| 202 | + cargo-features = ["patch-files"] |
| 203 | +
|
| 204 | + [package] |
| 205 | + name = "foo" |
| 206 | + edition = "2015" |
| 207 | +
|
| 208 | + [dependencies] |
| 209 | + bar = "1" |
| 210 | +
|
| 211 | + [patch.crates-io] |
| 212 | + bar = { version = "=1.0.0", registry = "alternative", patches = [] } |
| 213 | + "#, |
| 214 | + ) |
| 215 | + .file("src/lib.rs", "") |
| 216 | + .build(); |
| 217 | + |
| 218 | + p.cargo("check") |
| 219 | + .masquerade_as_nightly_cargo(&["patch-files"]) |
| 220 | + .with_status(101) |
| 221 | + .with_stderr_data(str![[r#" |
| 222 | +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 223 | +
|
| 224 | +Caused by: |
| 225 | + patch for `bar` in `https://github.com/rust-lang/crates.io-index` must refer to the same source when patching with patch files |
| 226 | +
|
| 227 | +"#]]) |
| 228 | + .run(); |
| 229 | +} |
| 230 | + |
| 231 | +#[cargo_test] |
| 232 | +fn disallow_path_dep() { |
| 233 | + let p = project() |
| 234 | + .file( |
| 235 | + "Cargo.toml", |
| 236 | + r#" |
| 237 | + cargo-features = ["patch-files"] |
| 238 | +
|
| 239 | + [package] |
| 240 | + name = "foo" |
| 241 | + edition = "2015" |
| 242 | +
|
| 243 | + [dependencies] |
| 244 | + bar = "1" |
| 245 | +
|
| 246 | + [patch.crates-io] |
| 247 | + bar = { path = "bar", patches = [""] } |
| 248 | + "#, |
| 249 | + ) |
| 250 | + .file("src/lib.rs", "") |
| 251 | + .file("bar/Cargo.toml", &basic_manifest("bar", "1.0.0")) |
| 252 | + .file("bar/src/lib.rs", "") |
| 253 | + .build(); |
| 254 | + |
| 255 | + p.cargo("check") |
| 256 | + .masquerade_as_nightly_cargo(&["patch-files"]) |
| 257 | + .with_status(101) |
| 258 | + .with_stderr_data(str![[r#" |
| 259 | +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 260 | +
|
| 261 | +Caused by: |
| 262 | + patch for `bar` in `https://github.com/rust-lang/crates.io-index` requires a registry source when patching with patch files |
| 263 | +
|
| 264 | +"#]]) |
| 265 | + .run(); |
| 266 | +} |
| 267 | + |
| 268 | +#[cargo_test] |
| 269 | +fn disallow_git_dep() { |
| 270 | + let git = git::repo(&paths::root().join("bar")) |
| 271 | + .file("Cargo.toml", &basic_manifest("bar", "1.0.0")) |
| 272 | + .file("src/lib.rs", "") |
| 273 | + .build(); |
| 274 | + let url = git.url(); |
| 275 | + |
| 276 | + let p = project() |
| 277 | + .file( |
| 278 | + "Cargo.toml", |
| 279 | + &format!( |
| 280 | + r#" |
| 281 | + cargo-features = ["patch-files"] |
| 282 | +
|
| 283 | + [package] |
| 284 | + name = "foo" |
| 285 | + edition = "2015" |
| 286 | +
|
| 287 | + [dependencies] |
| 288 | + bar = "1" |
| 289 | +
|
| 290 | + [patch.crates-io] |
| 291 | + bar = {{ git = "{url}", patches = [""] }} |
| 292 | + "# |
| 293 | + ), |
| 294 | + ) |
| 295 | + .file("src/lib.rs", "") |
| 296 | + .build(); |
| 297 | + |
| 298 | + p.cargo("check") |
| 299 | + .masquerade_as_nightly_cargo(&["patch-files"]) |
| 300 | + .with_status(101) |
| 301 | + .with_stderr_data(str![[r#" |
| 302 | +[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` |
| 303 | +
|
| 304 | +Caused by: |
| 305 | + patch for `bar` in `https://github.com/rust-lang/crates.io-index` requires a registry source when patching with patch files |
| 306 | +
|
| 307 | +"#]]) |
| 308 | + .run(); |
| 309 | +} |
0 commit comments