|
3 | 3 | use std::fs::{self, read_to_string, File};
|
4 | 4 | use std::path::Path;
|
5 | 5 |
|
| 6 | +use cargo_test_support::compare::assert_e2e; |
6 | 7 | use cargo_test_support::prelude::*;
|
7 | 8 | use cargo_test_support::publish::validate_crate_contents;
|
8 | 9 | use cargo_test_support::registry::{self, Package};
|
@@ -1425,6 +1426,123 @@ edition = "2021"
|
1425 | 1426 | );
|
1426 | 1427 | }
|
1427 | 1428 |
|
| 1429 | +#[cargo_test] |
| 1430 | +fn dirty_ws_lockfile_dirty() { |
| 1431 | + let (p, repo) = git::new_repo("foo", |p| { |
| 1432 | + p.file( |
| 1433 | + "Cargo.toml", |
| 1434 | + r#" |
| 1435 | + [workspace] |
| 1436 | + members = ["isengard"] |
| 1437 | + resolver = "2" |
| 1438 | + [workspace.package] |
| 1439 | + edition = "2015" |
| 1440 | + "#, |
| 1441 | + ) |
| 1442 | + .file( |
| 1443 | + "isengard/Cargo.toml", |
| 1444 | + r#" |
| 1445 | + [package] |
| 1446 | + name = "isengard" |
| 1447 | + edition.workspace = true |
| 1448 | + homepage = "saruman" |
| 1449 | + description = "saruman" |
| 1450 | + license = "MIT" |
| 1451 | + "#, |
| 1452 | + ) |
| 1453 | + .file("isengard/src/lib.rs", "") |
| 1454 | + }); |
| 1455 | + git::commit(&repo); |
| 1456 | + |
| 1457 | + p.cargo("package --workspace --no-verify") |
| 1458 | + .with_stderr_data(str![[r#" |
| 1459 | +[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) |
| 1460 | +[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) |
| 1461 | +
|
| 1462 | +"#]]) |
| 1463 | + .run(); |
| 1464 | + |
| 1465 | + // lockfile is untracked. |
| 1466 | + p.cargo("generate-lockfile").run(); |
| 1467 | + p.cargo("package --workspace --no-verify") |
| 1468 | + .with_stderr_data(str![[r#" |
| 1469 | +[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) |
| 1470 | +[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) |
| 1471 | +
|
| 1472 | +"#]]) |
| 1473 | + .run(); |
| 1474 | + |
| 1475 | + // lockfile is tracked. |
| 1476 | + p.cargo("clean").run(); |
| 1477 | + git::add(&repo); |
| 1478 | + git::commit(&repo); |
| 1479 | + p.cargo("package --workspace --no-verify") |
| 1480 | + .with_stderr_data(str![[r#" |
| 1481 | +[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) |
| 1482 | +[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) |
| 1483 | +
|
| 1484 | +"#]]) |
| 1485 | + .run(); |
| 1486 | + |
| 1487 | + // Simulate that Cargo.lock had some outdated but SemVer compat dependency changes. |
| 1488 | + Package::new("dep", "1.0.0").publish(); |
| 1489 | + Package::new("dep", "1.1.0").publish(); |
| 1490 | + p.cargo("clean").run(); |
| 1491 | + p.cargo("add dep@1").run(); |
| 1492 | + git::add(&repo); |
| 1493 | + git::commit(&repo); |
| 1494 | + // make sure we have [email protected] in lockfile |
| 1495 | + assert_e2e().eq( |
| 1496 | + &p.read_lockfile(), |
| 1497 | + str![[r##" |
| 1498 | +# This file is automatically @generated by Cargo. |
| 1499 | +# It is not intended for manual editing. |
| 1500 | +version = 4 |
| 1501 | +
|
| 1502 | +[[package]] |
| 1503 | +name = "dep" |
| 1504 | +version = "1.1.0" |
| 1505 | +source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1506 | +checksum = "77d3d6a4f2203d590707cc803c94afbe36393bbdba757ef66986f39159eaab51" |
| 1507 | +
|
| 1508 | +[[package]] |
| 1509 | +name = "isengard" |
| 1510 | +version = "0.0.0" |
| 1511 | +dependencies = [ |
| 1512 | + "dep", |
| 1513 | +] |
| 1514 | +
|
| 1515 | +"##]], |
| 1516 | + ); |
| 1517 | + p.cargo("update dep --precise 1.0.0") |
| 1518 | + .with_stderr_data(str![[r#" |
| 1519 | +[UPDATING] `dummy-registry` index |
| 1520 | +[DOWNGRADING] dep v1.1.0 -> v1.0.0 |
| 1521 | +
|
| 1522 | +"#]]) |
| 1523 | + .run(); |
| 1524 | + p.cargo("package --workspace --no-verify") |
| 1525 | + .with_stderr_data(str![[r#" |
| 1526 | +[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) |
| 1527 | +[UPDATING] `dummy-registry` index |
| 1528 | +[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) |
| 1529 | +
|
| 1530 | +"#]]) |
| 1531 | + .run(); |
| 1532 | + |
| 1533 | + // Now check if it is considered dirty when removed. |
| 1534 | + p.cargo("clean").run(); |
| 1535 | + fs::remove_file(p.root().join("Cargo.lock")).unwrap(); |
| 1536 | + p.cargo("package --workspace --no-verify") |
| 1537 | + .with_stderr_data(str![[r#" |
| 1538 | +[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) |
| 1539 | +[UPDATING] `dummy-registry` index |
| 1540 | +[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) |
| 1541 | +
|
| 1542 | +"#]]) |
| 1543 | + .run(); |
| 1544 | +} |
| 1545 | + |
1428 | 1546 | #[cargo_test]
|
1429 | 1547 | fn issue_13695_allow_dirty_vcs_info() {
|
1430 | 1548 | let p = project()
|
|
0 commit comments