Skip to content

Commit 4df1375

Browse files
committed
Add tests for "build --all"
These are basically the same as the ones from "test --all"
1 parent 0d92be3 commit 4df1375

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

tests/build.rs

+101
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use cargotest::{is_nightly, rustc_host, sleep_ms};
1212
use cargotest::support::paths::{CargoPathExt,root};
1313
use cargotest::support::{ProjectBuilder};
1414
use cargotest::support::{project, execs, main_file, basic_bin_manifest};
15+
use cargotest::support::registry::Package;
1516
use hamcrest::{assert_that, existing_file, is_not};
1617
use tempdir::TempDir;
1718

@@ -2554,3 +2555,103 @@ fn cargo_build_empty_target() {
25542555
execs().with_status(101)
25552556
.with_stderr_contains("[..] target was empty"));
25562557
}
2558+
2559+
#[test]
2560+
fn build_all_workspace() {
2561+
let p = project("foo")
2562+
.file("Cargo.toml", r#"
2563+
[project]
2564+
name = "foo"
2565+
version = "0.1.0"
2566+
2567+
[dependencies]
2568+
bar = { path = "bar" }
2569+
2570+
[workspace]
2571+
"#)
2572+
.file("src/main.rs", r#"
2573+
fn main() {}
2574+
"#)
2575+
.file("bar/Cargo.toml", r#"
2576+
[project]
2577+
name = "bar"
2578+
version = "0.1.0"
2579+
"#)
2580+
.file("bar/src/lib.rs", r#"
2581+
pub fn bar() {}
2582+
"#);
2583+
p.build();
2584+
2585+
assert_that(p.cargo_process("build")
2586+
.arg("--all"),
2587+
execs().with_stderr("[..] Compiling bar v0.1.0 ([..])\n\
2588+
[..] Compiling foo v0.1.0 ([..])\n\
2589+
[..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
2590+
}
2591+
2592+
#[test]
2593+
fn build_all_virtual_manifest() {
2594+
let p = project("workspace")
2595+
.file("Cargo.toml", r#"
2596+
[workspace]
2597+
members = ["foo", "bar"]
2598+
"#)
2599+
.file("foo/Cargo.toml", r#"
2600+
[project]
2601+
name = "foo"
2602+
version = "0.1.0"
2603+
"#)
2604+
.file("foo/src/lib.rs", r#"
2605+
pub fn foo() {}
2606+
"#)
2607+
.file("bar/Cargo.toml", r#"
2608+
[project]
2609+
name = "bar"
2610+
version = "0.1.0"
2611+
"#)
2612+
.file("bar/src/lib.rs", r#"
2613+
pub fn bar() {}
2614+
"#);
2615+
p.build();
2616+
2617+
// The order in which foo and bar are built is not guaranteed
2618+
assert_that(p.cargo_process("build")
2619+
.arg("--all"),
2620+
execs().with_stderr_contains("[..] Compiling bar v0.1.0 ([..])")
2621+
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
2622+
.with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\
2623+
[..] Compiling [..] v0.1.0 ([..])\n\
2624+
[..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
2625+
}
2626+
2627+
#[test]
2628+
fn build_all_member_dependency_same_name() {
2629+
let p = project("workspace")
2630+
.file("Cargo.toml", r#"
2631+
[workspace]
2632+
members = ["a"]
2633+
"#)
2634+
.file("a/Cargo.toml", r#"
2635+
[project]
2636+
name = "a"
2637+
version = "0.1.0"
2638+
2639+
[dependencies]
2640+
a = "0.1.0"
2641+
"#)
2642+
.file("a/src/lib.rs", r#"
2643+
pub fn a() {}
2644+
"#);
2645+
p.build();
2646+
2647+
Package::new("a", "0.1.0").publish();
2648+
2649+
assert_that(p.cargo_process("build")
2650+
.arg("--all"),
2651+
execs().with_stderr("[..] Updating registry `[..]`\n\
2652+
[..] Downloading a v0.1.0 ([..])\n\
2653+
[..] Compiling a v0.1.0\n\
2654+
[..] Compiling a v0.1.0 ([..])\n\
2655+
[..] Finished debug [unoptimized + debuginfo] target(s) in [..]\n"));
2656+
}
2657+

0 commit comments

Comments
 (0)