Skip to content

Commit

Permalink
Add tests for all-targets and update the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
infinity0 committed Mar 7, 2018
1 parent 9798f68 commit 1b1cae0
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Options:
--tests Benchmark all tests
--bench NAME ... Benchmark only the specified bench target
--benches Benchmark all benches
--all-targets Benchmark all targets (default)
--all-targets Benchmark all targets (lib and bin targets by default)
--no-run Compile, but don't run benchmarks
-p SPEC, --package SPEC ... Package to run benchmarks for
--all Benchmark all packages in the workspace
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Options:
--tests Build all tests
--bench NAME Build only the specified bench target
--benches Build all benches
--all-targets Build all targets (default)
--all-targets Build all targets (lib and bin targets by default)
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--all-features Build all available features
Expand Down
2 changes: 1 addition & 1 deletion src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Options:
--tests Test all tests
--bench NAME ... Test only the specified bench target
--benches Test all benches
--all-targets Test all targets (default)
--all-targets Test all targets (lib and bin targets by default)
--no-run Compile, but don't run tests
-p SPEC, --package SPEC ... Package to run tests for
--all Test all packages in the workspace
Expand Down
44 changes: 44 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,50 @@ fn build_filter_infer_profile() {
);
}

#[test]
fn all_targets_with_and_without() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#)
.file("src/main.rs", "fn main() {}")
.build();
assert_that(p.cargo("build").arg("-v").arg("--all-targets"),
execs().with_status(0)
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C debuginfo=2 --test [..]")
);
assert_that(p.cargo("clean"), execs().with_status(0));
assert_that(p.cargo("build").arg("-v"),
execs().with_status(0)
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_does_not_contain("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_does_not_contain("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C debuginfo=2 --test [..]")
);
}

#[test]
fn all_targets_no_lib() {
let p = project("foo")
Expand Down
11 changes: 10 additions & 1 deletion tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ fn check_virtual_all_implied() {
}

#[test]
fn check_all_targets() {
fn all_targets_with_and_without() {
let foo = project("foo")
.file("Cargo.toml", SIMPLE_MANIFEST)
.file("src/main.rs", "fn main() {}")
Expand All @@ -495,6 +495,15 @@ fn check_all_targets() {
.with_stderr_contains("[..] --crate-name test2 tests[/]test2.rs [..]")
.with_stderr_contains("[..] --crate-name bench3 benches[/]bench3.rs [..]")
);
assert_that(foo.cargo("clean"), execs().with_status(0));
assert_that(foo.cargo("check").arg("-v"),
execs().with_status(0)
.with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]")
.with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]")
.with_stderr_does_not_contain("[..] --crate-name example1 examples[/]example1.rs [..]")
.with_stderr_does_not_contain("[..] --crate-name test2 tests[/]test2.rs [..]")
.with_stderr_does_not_contain("[..] --crate-name bench3 benches[/]bench3.rs [..]")
);
}

#[test]
Expand Down
44 changes: 44 additions & 0 deletions tests/testsuite/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,50 @@ fn build_only_bar_dependency() {
"));
}

#[test]
fn all_targets_with_and_without() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#)
.file("src/main.rs", "fn main() {}")
.build();
assert_that(p.cargo("rustc").arg("-v").arg("--all-targets"),
execs().with_status(0)
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C debuginfo=2 --test [..]")
);
assert_that(p.cargo("clean"), execs().with_status(0));
assert_that(p.cargo("rustc").arg("-v"),
execs().with_status(0)
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_does_not_contain("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_does_not_contain("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C debuginfo=2 --test [..]")
);
}

#[test]
fn fail_with_multiple_packages() {
let foo = project("foo")
Expand Down

0 comments on commit 1b1cae0

Please sign in to comment.