mirror of
https://github.com/rust-lang/cargo
synced 2024-08-25 10:35:53 +00:00
Auto merge of #10862 - Muscraft:workspace-selection-test, r=epage
Add a test for regressions in selecting the correct workspace root This adds a test to check for regressions in selecting the correct workspace when there are nested workspaces. #10846 solved a problem with nested workspace resolution that was caused by #10776. `@ehuss` [suggested](https://github.com/rust-lang/cargo/pull/10846#issuecomment-1183754728) that a test should be added to ensure that this issue does not pop up again. I ensured that this worked by testing against commit before #10846. Sporadically I would get an error that was the same as described in #10846. ``` error: package `{path}/cargo/target/tmp/cit/t0/foo/sub/foo/Cargo.toml` is a member of the wrong workspace expected: {path}/cargo/target/tmp/cit/t0/foo/sub/Cargo.toml actual: {path}/cargo/target/tmp/cit/t0/foo/Cargo.toml ``` I then tested it on the commit with the fix and the test passed every time. --- While this does add a test to catch any regression I am worried that it will not catch it every time. It was noted in #10846 that this error would sometimes happen but not every time, in my testing I found this to be true as well. Since this is caused by the `HashMap` order changing each run, switching to something ordered like `BTreeMap` **_should_** catch any regressions every run (if the implementation were to ever change). I'm not sure if this is necessary so I figured I would note the concern here.
This commit is contained in:
commit
8827baaa78
|
@ -2454,3 +2454,50 @@ fn virtual_primary_package_env_var() {
|
|||
p.cargo("clean").run();
|
||||
p.cargo("test -p foo").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn ensure_correct_workspace_when_nested() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[workspace]
|
||||
|
||||
[project]
|
||||
name = "bar"
|
||||
version = "0.1.0"
|
||||
authors = []
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.file(
|
||||
"sub/Cargo.toml",
|
||||
r#"
|
||||
[workspace]
|
||||
members = ["foo"]
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"sub/foo/Cargo.toml",
|
||||
r#"
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
authors = []
|
||||
|
||||
[dependencies]
|
||||
bar = { path = "../.."}
|
||||
"#,
|
||||
)
|
||||
.file("sub/foo/src/main.rs", "fn main() {}");
|
||||
let p = p.build();
|
||||
p.cargo("tree")
|
||||
.cwd("sub/foo")
|
||||
.with_stdout(
|
||||
"\
|
||||
foo v0.1.0 ([..]/foo/sub/foo)
|
||||
└── bar v0.1.0 ([..]/foo)\
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue