Skip to content

Commit c12aed2

Browse files
committed
Add tests for CARGO_PRIMARY_PACKAGE (workspaces)
1 parent 0f20b2e commit c12aed2

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

tests/testsuite/workspaces.rs

+89
Original file line numberDiff line numberDiff line change
@@ -2319,3 +2319,92 @@ Caused by:
23192319
)
23202320
.run();
23212321
}
2322+
2323+
#[cargo_test]
2324+
fn simple_primary_package_env_var() {
2325+
let p = project()
2326+
.file(
2327+
"Cargo.toml",
2328+
r#"
2329+
[project]
2330+
name = "foo"
2331+
version = "0.1.0"
2332+
authors = []
2333+
2334+
[workspace]
2335+
members = ["bar"]
2336+
"#,
2337+
)
2338+
.file("src/main.rs", "fn main() {}")
2339+
.file(
2340+
"bar/Cargo.toml",
2341+
r#"
2342+
[project]
2343+
name = "bar"
2344+
version = "0.1.0"
2345+
authors = []
2346+
workspace = ".."
2347+
"#,
2348+
)
2349+
.file("bar/src/main.rs", "fn main() {}");
2350+
let p = p.build();
2351+
2352+
p.cargo("build -vv")
2353+
.with_stderr_contains(
2354+
"[RUNNING] [..] CARGO_CRATE_NAME=foo [..] CARGO_PRIMARY_PACKAGE=1 [..]",
2355+
)
2356+
.run();
2357+
2358+
// Again, this time selecting a specific crate
2359+
p.cargo("clean").run();
2360+
p.cargo("build -vv -p bar")
2361+
.with_stderr_contains(
2362+
"[RUNNING] [..] CARGO_CRATE_NAME=bar [..] CARGO_PRIMARY_PACKAGE=1 [..]",
2363+
)
2364+
.run();
2365+
2366+
// Again, this time selecting all crates
2367+
p.cargo("clean").run();
2368+
p.cargo("build -vv --all")
2369+
.with_stderr_contains(
2370+
"[RUNNING] [..] CARGO_CRATE_NAME=foo [..] CARGO_PRIMARY_PACKAGE=1 [..]",
2371+
)
2372+
.with_stderr_contains(
2373+
"[RUNNING] [..] CARGO_CRATE_NAME=bar [..] CARGO_PRIMARY_PACKAGE=1 [..]",
2374+
)
2375+
.run();
2376+
}
2377+
2378+
#[cargo_test]
2379+
fn virtual_primary_package_env_var() {
2380+
let p = project()
2381+
.file(
2382+
"Cargo.toml",
2383+
r#"
2384+
[workspace]
2385+
members = ["foo", "bar"]
2386+
"#,
2387+
)
2388+
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
2389+
.file("foo/src/main.rs", "fn main() {}")
2390+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
2391+
.file("bar/src/main.rs", "fn main() {}");
2392+
let p = p.build();
2393+
2394+
p.cargo("build -vv")
2395+
.with_stderr_contains(
2396+
"[RUNNING] [..] CARGO_CRATE_NAME=foo [..] CARGO_PRIMARY_PACKAGE=1 [..]",
2397+
)
2398+
.with_stderr_contains(
2399+
"[RUNNING] [..] CARGO_CRATE_NAME=bar [..] CARGO_PRIMARY_PACKAGE=1 [..]",
2400+
)
2401+
.run();
2402+
2403+
// Again, this time selecting a specific crate
2404+
p.cargo("clean").run();
2405+
p.cargo("build -vv -p foo")
2406+
.with_stderr_contains(
2407+
"[RUNNING] [..] CARGO_CRATE_NAME=foo [..] CARGO_PRIMARY_PACKAGE=1 [..]",
2408+
)
2409+
.run();
2410+
}

0 commit comments

Comments
 (0)