Skip to content

Commit f1d46e3

Browse files
committed
Testing for binary built as an implicit dependency.
1 parent 8a0d4d9 commit f1d46e3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tests/testsuite/required_features.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use cargo_test_support::install::{
44
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
55
};
66
use cargo_test_support::is_nightly;
7+
use cargo_test_support::paths::CargoPathExt;
78
use cargo_test_support::project;
89

910
#[cargo_test]
@@ -910,7 +911,17 @@ fn dep_feature_in_cmd_line() {
910911
)
911912
.file("src/main.rs", "fn main() {}")
912913
.file("examples/foo.rs", "fn main() {}")
913-
.file("tests/foo.rs", "#[test]\nfn test() {}")
914+
.file(
915+
"tests/foo.rs",
916+
r#"
917+
#[test]
918+
fn bin_is_built() {
919+
let s = format!("target/debug/foo{}", std::env::consts::EXE_SUFFIX);
920+
let p = std::path::Path::new(&s);
921+
assert!(p.exists(), "foo does not exist");
922+
}
923+
"#,
924+
)
914925
.file(
915926
"benches/foo.rs",
916927
r#"
@@ -936,7 +947,9 @@ fn dep_feature_in_cmd_line() {
936947
.file("bar/src/lib.rs", "")
937948
.build();
938949

939-
p.cargo("build").run();
950+
// This is a no-op
951+
p.cargo("build").with_stderr("[FINISHED] dev [..]").run();
952+
assert!(!p.bin("foo").is_file());
940953

941954
// bin
942955
p.cargo("build --bin=foo")
@@ -967,19 +980,23 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"`
967980
assert!(p.bin("examples/foo").is_file());
968981

969982
// test
983+
// This is a no-op, since no tests are enabled
970984
p.cargo("test")
971985
.with_stderr("[FINISHED] test [unoptimized + debuginfo] target(s) in [..]")
972986
.with_stdout("")
973987
.run();
974988

989+
// Delete the target directory so this can check if the main.rs gets built.
990+
p.build_dir().rm_rf();
975991
p.cargo("test --test=foo --features bar/a")
976992
.with_stderr(
977993
"\
994+
[COMPILING] bar v0.0.1 ([CWD]/bar)
978995
[COMPILING] foo v0.0.1 ([CWD])
979996
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
980997
[RUNNING] target/debug/deps/foo-[..][EXE]",
981998
)
982-
.with_stdout_contains("test test ... ok")
999+
.with_stdout_contains("test bin_is_built ... ok")
9831000
.run();
9841001

9851002
// bench

0 commit comments

Comments
 (0)