|
1 | 1 | //! Tests for the `cargo fix` command.
|
2 | 2 |
|
3 | 3 | use cargo::core::Edition;
|
| 4 | +use cargo_test_support::compare::assert_match_exact; |
4 | 5 | use cargo_test_support::git;
|
5 | 6 | use cargo_test_support::paths::CargoPathExt;
|
6 | 7 | use cargo_test_support::registry::{Dependency, Package};
|
@@ -1552,3 +1553,49 @@ fn fix_edition_2021() {
|
1552 | 1553 | .run();
|
1553 | 1554 | assert!(p.read_file("src/lib.rs").contains(r#"0..=100 => true,"#));
|
1554 | 1555 | }
|
| 1556 | + |
| 1557 | +#[cargo_test] |
| 1558 | +fn fix_shared_cross_workspace() { |
| 1559 | + // Fixing a file that is shared between multiple packages in the same workspace. |
| 1560 | + // Make sure two processes don't try to fix the same file at the same time. |
| 1561 | + let p = project() |
| 1562 | + .file( |
| 1563 | + "Cargo.toml", |
| 1564 | + r#" |
| 1565 | + [workspace] |
| 1566 | + members = ["foo", "bar"] |
| 1567 | + "#, |
| 1568 | + ) |
| 1569 | + .file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0")) |
| 1570 | + .file("foo/src/lib.rs", "pub mod shared;") |
| 1571 | + // This will fix both unused and bare trait. |
| 1572 | + .file("foo/src/shared.rs", "pub fn fixme(x: Box<&Fn() -> ()>) {}") |
| 1573 | + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) |
| 1574 | + .file( |
| 1575 | + "bar/src/lib.rs", |
| 1576 | + r#" |
| 1577 | + #[path="../../foo/src/shared.rs"] |
| 1578 | + pub mod shared; |
| 1579 | + "#, |
| 1580 | + ) |
| 1581 | + .build(); |
| 1582 | + |
| 1583 | + // The output here can be either of these two, depending on who runs first: |
| 1584 | + // [FIXED] bar/src/../../foo/src/shared.rs (2 fixes) |
| 1585 | + // [FIXED] foo/src/shared.rs (2 fixes) |
| 1586 | + p.cargo("fix --allow-no-vcs") |
| 1587 | + .with_stderr_unordered( |
| 1588 | + "\ |
| 1589 | +[CHECKING] foo v0.1.0 [..] |
| 1590 | +[CHECKING] bar v0.1.0 [..] |
| 1591 | +[FIXED] [..]foo/src/shared.rs (2 fixes) |
| 1592 | +[FINISHED] [..] |
| 1593 | +", |
| 1594 | + ) |
| 1595 | + .run(); |
| 1596 | + |
| 1597 | + assert_match_exact( |
| 1598 | + "pub fn fixme(_x: Box<&dyn Fn() -> ()>) {}", |
| 1599 | + &p.read_file("foo/src/shared.rs"), |
| 1600 | + ); |
| 1601 | +} |
0 commit comments