Skip to content

Commit 8827baa

Browse files
committed
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](#10846 (comment)) 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.
2 parents eff62ad + 6070b0a commit 8827baa

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/testsuite/workspaces.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,3 +2454,50 @@ fn virtual_primary_package_env_var() {
24542454
p.cargo("clean").run();
24552455
p.cargo("test -p foo").run();
24562456
}
2457+
2458+
#[cargo_test]
2459+
fn ensure_correct_workspace_when_nested() {
2460+
let p = project()
2461+
.file(
2462+
"Cargo.toml",
2463+
r#"
2464+
[workspace]
2465+
2466+
[project]
2467+
name = "bar"
2468+
version = "0.1.0"
2469+
authors = []
2470+
"#,
2471+
)
2472+
.file("src/lib.rs", "")
2473+
.file(
2474+
"sub/Cargo.toml",
2475+
r#"
2476+
[workspace]
2477+
members = ["foo"]
2478+
"#,
2479+
)
2480+
.file(
2481+
"sub/foo/Cargo.toml",
2482+
r#"
2483+
[project]
2484+
name = "foo"
2485+
version = "0.1.0"
2486+
authors = []
2487+
2488+
[dependencies]
2489+
bar = { path = "../.."}
2490+
"#,
2491+
)
2492+
.file("sub/foo/src/main.rs", "fn main() {}");
2493+
let p = p.build();
2494+
p.cargo("tree")
2495+
.cwd("sub/foo")
2496+
.with_stdout(
2497+
"\
2498+
foo v0.1.0 ([..]/foo/sub/foo)
2499+
└── bar v0.1.0 ([..]/foo)\
2500+
",
2501+
)
2502+
.run();
2503+
}

0 commit comments

Comments
 (0)