Refactor Cargo's backend, again!
This commit started out identifying a relatively simple bug in Cargo. A recent
change made it such that the resolution graph included all target-specific
dependencies, relying on the structure of the backend to filter out those which
don't need to get built. This was unfortunately not accounted for in the portion
of the backend that schedules work, mistakenly causing spurious rebuilds if
different runs of the graph pulled in new crates. For example if `cargo build`
didn't build any target-specific dependencies but then later `cargo test` did
(e.g. a dev-dep pulled in a target-specific dep unconditionally) then it would
cause a rebuild of the entire graph.
This class of bug is certainly not the first in a long and storied history of
the backend having multiple points where dependencies are calculated and those
often don't quite agree with one another. The purpose of this rewrite is
twofold:
1. The `Stage` enum in the backend for scheduling work and ensuring that maximum
parallelism is achieved is removed entirely. There is already a function on
`Context` which expresses the dependency between targets (`dep_targets`)
which takes a much finer grain of dependencies into account as well as
already having all the logic for what-depends-on-what. This duplication has
caused numerous problems in the past, an unifying these two will truly grant
maximum parallelism while ensuring that everyone agrees on what their
dependencies are.
2. A large number of locations in the backend have grown to take a (Package,
Target, Profile, Kind) tuple, or some subset of this tuple. In general this
represents a "unit of work" and is much easier to pass around as one
variable, so a `Unit` was introduced which references all of these variables.
Almost the entire backend was altered to take a `Unit` instead of these
variables specifically, typically providing all of the contextual information
necessary for an operation.
A crucial part of this change is the inclusion of `Kind` in a `Unit` to ensure
that everyone *also* agrees on what architecture they're compiling everything
for. There have been many bugs in the past where one part of the backend
determined that a package was built for one architecture and then another part
thought it was built for another. With the inclusion of `Kind` in dependency
management this is handled in a much cleaner fashion as it's only calculated in
one location.
Some other miscellaneous changes made were:
* The `Platform` enumeration has finally been removed. This has been entirely
subsumed by `Kind`.
* The hokey logic for "build this crate once" even though it may be depended on
by both the host/target kinds has been removed. This is now handled in a much
nicer fashion where if there's no target then Kind::Target is just never used,
and multiple requests for a package are just naturally deduplicated.
* There's no longer any need to build up the "requirements" for a package in
terms of what platforms it's compiled for, this now just naturally falls out
of the dependency graph.
* If a build script is overridden then its entire tree of dependencies are not
compiled, not just the build script itself.
* The `threadpool` dependency has been replaced with one on `crossbeam`. The
method of calculating dependencies has quite a few non-static lifetimes and
the scoped threads of `crossbeam` are now used instead of a thread pool.
* Once any thread fails to execute a command work is no longer scheduled unlike
before where some extra pending work may continue to start.
* Many functions used early on, such as `compile` and `build_map` have been
massively simplified by farming out dependency management to
`Context::dep_targets`.
* There is now a new profile to represent running a build script. This is used
to inject dependencies as well as represent that a library depends on running
a build script, not just building it.
This change has currently been tested against cross-compiling Servo to Android
and passes the test suite (which has quite a few corner cases for build scripts
and such), so I'm pretty confident that this refactoring won't have at least too
many regressions!
2015-10-02 06:48:47 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::prelude::*;
|
2014-07-10 19:39:05 +00:00
|
|
|
use std::str;
|
|
|
|
|
2018-02-08 00:13:17 +00:00
|
|
|
use cargo;
|
2018-03-14 15:17:44 +00:00
|
|
|
use cargotest::{is_nightly, rustc_host, sleep_ms};
|
|
|
|
use cargotest::support::{basic_bin_manifest, basic_lib_manifest, cargo_exe, execs, project};
|
2016-05-26 00:06:25 +00:00
|
|
|
use cargotest::support::paths::CargoPathExt;
|
2016-10-20 20:14:54 +00:00
|
|
|
use cargotest::support::registry::Package;
|
2015-03-21 02:31:12 +00:00
|
|
|
use hamcrest::{assert_that, existing_file, is_not};
|
2014-06-26 22:14:31 +00:00
|
|
|
use cargo::util::process;
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_test_simple() {
|
2014-06-26 22:14:31 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-06-26 22:14:31 +00:00
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
assert_eq!(hello(), "hello")
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-06-26 22:14:31 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2014-06-26 22:14:31 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("hello\n"),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]",
|
|
|
|
p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test_hello ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_test_release() {
|
2015-03-24 20:43:30 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-04-29 18:19:53 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
2015-03-24 20:43:30 +00:00
|
|
|
|
2015-04-29 18:19:53 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-04-29 18:19:53 +00:00
|
|
|
extern crate bar;
|
|
|
|
pub fn foo() { bar::bar(); }
|
2015-03-24 20:43:30 +00:00
|
|
|
|
|
|
|
#[test]
|
2015-04-29 18:19:53 +00:00
|
|
|
fn test() { foo(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/test.rs",
|
|
|
|
r#"
|
2015-04-29 18:19:53 +00:00
|
|
|
extern crate foo;
|
2015-03-24 20:43:30 +00:00
|
|
|
|
|
|
|
#[test]
|
2015-04-29 18:19:53 +00:00
|
|
|
fn test() { foo::foo(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2015-03-24 20:43:30 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.build();
|
2015-03-24 20:43:30 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-v").arg("--release"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.0.1 ({dir}/bar)
|
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
|
|
|
[COMPILING] foo v0.1.0 ({dir})
|
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
2016-07-25 23:30:03 +00:00
|
|
|
[FINISHED] release [optimized] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] `[..]target[/]release[/]deps[/]foo-[..][EXE]`
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] `[..]target[/]release[/]deps[/]test-[..][EXE]`
|
2016-05-15 21:07:04 +00:00
|
|
|
[DOCTEST] foo
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `rustdoc --test [..]lib.rs[..]`",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains_n("test test ... ok", 2)
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2017-04-07 16:32:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_test_overflow_checks() {
|
|
|
|
if !is_nightly() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-07 16:32:42 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
|
|
|
|
[profile.release]
|
|
|
|
overflow-checks = true
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2017-04-07 16:32:42 +00:00
|
|
|
use std::panic;
|
|
|
|
pub fn main() {
|
|
|
|
let r = panic::catch_unwind(|| {
|
|
|
|
[1, i32::max_value()].iter().sum::<i32>();
|
|
|
|
});
|
|
|
|
assert!(r.is_err());
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-07 16:32:42 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("--release"), execs().with_status(0));
|
2017-04-07 16:32:42 +00:00
|
|
|
assert_that(&p.release_bin("foo"), existing_file());
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.release_bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout(""),
|
|
|
|
);
|
2017-04-07 16:32:42 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_test_verbose() {
|
2014-08-07 15:27:05 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-08-07 15:27:05 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn test_hello() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-08-07 15:27:05 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-v").arg("hello"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({url})
|
2017-07-09 12:57:25 +00:00
|
|
|
[RUNNING] `rustc [..] src[/]main.rs [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `[..]target[/]debug[/]deps[/]foo-[..][EXE] hello`",
|
|
|
|
url = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test_hello ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-07 15:27:05 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn many_similar_names() {
|
2014-07-23 18:44:15 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-23 18:44:15 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-07-23 18:44:15 +00:00
|
|
|
pub fn foo() {}
|
|
|
|
#[test] fn lib_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2014-07-23 18:44:15 +00:00
|
|
|
extern crate foo;
|
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_test() { foo::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
2014-07-23 18:44:15 +00:00
|
|
|
extern crate foo;
|
|
|
|
#[test] fn test_test() { foo::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 18:44:15 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let output = p.cargo("test").arg("-v").exec_with_output().unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
let output = str::from_utf8(&output.stdout).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert!(
|
|
|
|
output.contains("test bin_test"),
|
|
|
|
"bin_test missing\n{}",
|
|
|
|
output
|
|
|
|
);
|
|
|
|
assert!(
|
|
|
|
output.contains("test lib_test"),
|
|
|
|
"lib_test missing\n{}",
|
|
|
|
output
|
|
|
|
);
|
|
|
|
assert!(
|
|
|
|
output.contains("test test_test"),
|
|
|
|
"test_test missing\n{}",
|
|
|
|
output
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 18:44:15 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
2017-03-20 10:39:22 +00:00
|
|
|
fn cargo_test_failing_test_in_bin() {
|
2014-07-21 19:23:01 +00:00
|
|
|
let p = project("foo")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2014-07-21 19:23:01 +00:00
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
assert_eq!(hello(), "nope")
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2014-07-21 19:23:01 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("hello\n"),
|
|
|
|
);
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({url})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[ERROR] test failed, to rerun pass '--bin foo'",
|
|
|
|
url = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains(
|
|
|
|
"
|
2014-08-01 03:21:13 +00:00
|
|
|
running 1 test
|
|
|
|
test test_hello ... FAILED
|
|
|
|
|
|
|
|
failures:
|
|
|
|
|
|
|
|
---- test_hello stdout ----
|
2018-03-14 15:17:44 +00:00
|
|
|
<tab>thread 'test_hello' panicked at 'assertion failed:[..]",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("[..]`(left == right)`[..]")
|
|
|
|
.with_stdout_contains("[..]left: `\"hello\"`,[..]")
|
|
|
|
.with_stdout_contains("[..]right: `\"nope\"`[..]")
|
|
|
|
.with_stdout_contains("[..]src[/]main.rs:12[..]")
|
|
|
|
.with_stdout_contains(
|
|
|
|
"\
|
2014-08-01 03:21:13 +00:00
|
|
|
failures:
|
|
|
|
test_hello
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-09 20:08:44 +00:00
|
|
|
|
2017-03-20 10:39:22 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_test_failing_test_in_test() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-03-20 10:39:22 +00:00
|
|
|
pub fn main() {
|
|
|
|
println!("hello");
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/footest.rs",
|
|
|
|
r#"
|
2017-03-20 10:39:22 +00:00
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
assert!(false)
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-03-20 10:39:22 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2017-03-20 10:39:22 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
process(&p.bin("foo")),
|
|
|
|
execs().with_status(0).with_stdout("hello\n"),
|
|
|
|
);
|
2017-03-20 10:39:22 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({url})
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
|
|
|
[RUNNING] target[/]debug[/]deps[/]footest-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[ERROR] test failed, to rerun pass '--test footest'",
|
|
|
|
url = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.with_stdout_contains(
|
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
running 1 test
|
|
|
|
test test_hello ... FAILED
|
|
|
|
|
|
|
|
failures:
|
|
|
|
|
|
|
|
---- test_hello stdout ----
|
|
|
|
<tab>thread 'test_hello' panicked at 'assertion failed: false', \
|
2017-07-02 13:38:29 +00:00
|
|
|
tests[/]footest.rs:4[..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout_contains(
|
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
failures:
|
|
|
|
test_hello
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101),
|
|
|
|
);
|
2017-03-20 10:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cargo_test_failing_test_in_lib() {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-03-20 10:39:22 +00:00
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
assert!(false)
|
2018-03-14 15:17:44 +00:00
|
|
|
}"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-03-20 10:39:22 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
[COMPILING] foo v0.5.0 ({url})
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[ERROR] test failed, to rerun pass '--lib'",
|
|
|
|
url = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains(
|
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
test test_hello ... FAILED
|
|
|
|
|
|
|
|
failures:
|
|
|
|
|
|
|
|
---- test_hello stdout ----
|
|
|
|
<tab>thread 'test_hello' panicked at 'assertion failed: false', \
|
2017-07-02 13:38:29 +00:00
|
|
|
src[/]lib.rs:4[..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout_contains(
|
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
failures:
|
|
|
|
test_hello
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101),
|
|
|
|
);
|
2017-03-20 10:39:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_with_lib_dep() {
|
2014-07-09 20:08:44 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-09 20:08:44 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-17 01:44:30 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "baz"
|
|
|
|
path = "src/main.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-08-01 03:21:13 +00:00
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// extern crate foo;
|
|
|
|
/// fn main() {
|
2015-01-13 16:41:04 +00:00
|
|
|
/// println!("{:?}", foo::foo());
|
2014-08-01 03:21:13 +00:00
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
2014-07-10 19:08:13 +00:00
|
|
|
pub fn foo(){}
|
|
|
|
#[test] fn lib_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-07-09 20:08:44 +00:00
|
|
|
extern crate foo;
|
2014-07-10 19:08:13 +00:00
|
|
|
|
2014-07-09 20:08:44 +00:00
|
|
|
fn main() {}
|
2014-07-10 19:08:13 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bin_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-09 20:08:44 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2017-04-06 14:18:07 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]baz-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test lib_test ... ok")
|
|
|
|
.with_stdout_contains("test bin_test ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 3),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_with_deep_lib_dep() {
|
2014-07-10 18:50:03 +00:00
|
|
|
let p = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-10 18:50:03 +00:00
|
|
|
[package]
|
2014-07-09 20:55:00 +00:00
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.foo]
|
2014-07-10 18:50:03 +00:00
|
|
|
path = "../foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[cfg(test)]
|
2014-07-09 20:55:00 +00:00
|
|
|
extern crate foo;
|
2014-08-19 20:10:55 +00:00
|
|
|
/// ```
|
|
|
|
/// bar::bar();
|
|
|
|
/// ```
|
|
|
|
pub fn bar() {}
|
|
|
|
|
2014-07-10 18:50:03 +00:00
|
|
|
#[test]
|
|
|
|
fn bar_test() {
|
|
|
|
foo::foo();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
|
|
|
let _p2 = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-10 18:50:03 +00:00
|
|
|
[package]
|
2014-07-09 20:55:00 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-07-10 18:50:03 +00:00
|
|
|
pub fn foo() {}
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2014-07-10 18:50:03 +00:00
|
|
|
#[test]
|
|
|
|
fn foo_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-10 18:50:03 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
|
|
[COMPILING] bar v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] target[..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] bar",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test bar_test ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 2),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn external_test_explicit() {
|
2014-07-11 00:08:19 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-11 00:08:19 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "test"
|
|
|
|
path = "src/test.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-07-11 00:08:19 +00:00
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn internal_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/test.rs",
|
|
|
|
r#"
|
2014-07-11 00:08:19 +00:00
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(foo::get_hello(), "Hello") }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test internal_test ... ok")
|
|
|
|
.with_stdout_contains("test external_test ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2017-04-24 12:37:37 +00:00
|
|
|
#[test]
|
|
|
|
fn external_test_named_test() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-24 12:37:37 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "test"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-04-24 12:37:37 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"tests/test.rs",
|
|
|
|
r#"
|
2017-04-24 12:37:37 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() { }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-24 12:37:37 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0))
|
2017-04-24 12:37:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn external_test_implicit() {
|
2014-07-11 00:08:19 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-11 00:08:19 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-07-11 00:08:19 +00:00
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn internal_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/external.rs",
|
|
|
|
r#"
|
2014-07-11 00:08:19 +00:00
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(foo::get_hello(), "Hello") }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2017-04-06 14:18:07 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]external-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test internal_test ... ok")
|
|
|
|
.with_stdout_contains("test external_test ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 20:34:50 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dont_run_examples() {
|
2014-07-11 20:34:50 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-11 20:34:50 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/dont-run-me-i-will-fail.rs",
|
|
|
|
r#"
|
2014-10-30 01:59:06 +00:00
|
|
|
fn main() { panic!("Examples should not be run by 'cargo test'"); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-10 20:53:36 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn pass_through_command_line() {
|
2014-07-10 20:53:36 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-10 20:53:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-07-10 20:53:36 +00:00
|
|
|
#[test] fn foo() {}
|
|
|
|
#[test] fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-10 20:53:36 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("bar"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test bar ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("foo"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-21 00:02:09 +00:00
|
|
|
|
|
|
|
// Regression test for running cargo-test twice with
|
|
|
|
// tests in an rlib
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cargo_test_twice() {
|
2014-07-21 00:02:09 +00:00
|
|
|
let p = project("test_twice")
|
2015-03-26 18:17:44 +00:00
|
|
|
.file("Cargo.toml", &basic_lib_manifest("test_twice"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/test_twice.rs",
|
|
|
|
r#"
|
2014-07-21 00:02:09 +00:00
|
|
|
#![crate_type = "rlib"]
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dummy_test() { }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-21 00:02:09 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
p.cargo("build");
|
2014-07-21 00:02:09 +00:00
|
|
|
|
2015-03-22 23:58:11 +00:00
|
|
|
for _ in 0..2 {
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2014-07-21 00:02:09 +00:00
|
|
|
}
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn lib_bin_same_name() {
|
2014-07-22 14:45:46 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-22 14:45:46 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-22 14:45:46 +00:00
|
|
|
name = "foo"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-07-22 14:45:46 +00:00
|
|
|
#[test] fn lib_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-07-22 14:45:46 +00:00
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bin_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 2)
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn lib_with_standard_name() {
|
2014-07-23 00:53:38 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-23 00:53:38 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-08-07 15:26:38 +00:00
|
|
|
/// ```
|
|
|
|
/// syntax::foo();
|
|
|
|
/// ```
|
2014-07-23 00:53:38 +00:00
|
|
|
pub fn foo() {}
|
2014-08-07 15:26:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn foo_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/test.rs",
|
|
|
|
"
|
2014-07-23 00:53:38 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]syntax-[..][EXE]
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] syntax",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test foo_test ... ok")
|
|
|
|
.with_stdout_contains("test test ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 3),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn lib_with_standard_name2() {
|
2014-07-23 00:53:38 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-23 00:53:38 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-23 00:53:38 +00:00
|
|
|
name = "syntax"
|
|
|
|
test = false
|
2014-08-11 04:27:17 +00:00
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-07-23 00:53:38 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2014-07-23 00:53:38 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]syntax-[..][EXE]",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 18:58:09 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn lib_without_name() {
|
2015-06-21 10:34:42 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-06-21 10:34:42 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-06-21 10:34:42 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-06-21 10:34:42 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-06-21 10:34:42 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]syntax-[..][EXE]",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-21 10:34:42 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bin_without_name() {
|
2015-06-30 19:44:46 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-06-30 19:44:46 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
path = "src/main.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-06-30 19:44:46 +00:00
|
|
|
|
|
|
|
Caused by:
|
2018-03-14 15:17:44 +00:00
|
|
|
binary target bin.name is required",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bench_without_name() {
|
2015-06-30 19:44:46 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-06-30 19:44:46 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
|
|
|
|
[[bench]]
|
|
|
|
path = "src/bench.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bench.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
#![feature(test)]
|
|
|
|
extern crate syntax;
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn external_bench(_b: &mut test::Bencher) {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-06-30 19:44:46 +00:00
|
|
|
|
|
|
|
Caused by:
|
2018-03-14 15:17:44 +00:00
|
|
|
benchmark target bench.name is required",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_without_name() {
|
2015-06-30 19:44:46 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-06-30 19:44:46 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
path = "src/test.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-06-30 19:44:46 +00:00
|
|
|
pub fn foo() {}
|
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/test.rs",
|
|
|
|
r#"
|
2015-06-30 19:44:46 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(syntax::get_hello(), "Hello") }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-06-30 19:44:46 +00:00
|
|
|
|
|
|
|
Caused by:
|
2018-03-14 15:17:44 +00:00
|
|
|
test target test.name is required",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn example_without_name() {
|
2015-06-30 19:44:46 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-06-30 19:44:46 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
|
|
|
|
[[example]]
|
|
|
|
path = "examples/example.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-06-30 19:44:46 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/example.rs",
|
|
|
|
r#"
|
2015-06-30 19:44:46 +00:00
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("example1");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs().with_status(101).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[ERROR] failed to parse manifest at `[..]`
|
2015-06-30 19:44:46 +00:00
|
|
|
|
|
|
|
Caused by:
|
2018-03-14 15:17:44 +00:00
|
|
|
example target example.name is required",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bin_there_for_integration() {
|
2014-07-23 18:58:09 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-23 18:58:09 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
"
|
2015-06-26 22:51:53 +00:00
|
|
|
fn main() { std::process::exit(101); }
|
2014-07-23 18:58:09 +00:00
|
|
|
#[test] fn main_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
2015-03-26 18:17:44 +00:00
|
|
|
use std::process::Command;
|
2014-07-23 18:58:09 +00:00
|
|
|
#[test]
|
|
|
|
fn test_test() {
|
2015-03-03 21:46:02 +00:00
|
|
|
let status = Command::new("target/debug/foo").status().unwrap();
|
2015-03-26 18:17:44 +00:00
|
|
|
assert_eq!(status.code(), Some(101));
|
2014-07-23 18:58:09 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 18:58:09 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let output = p.cargo("test").arg("-v").exec_with_output().unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
let output = str::from_utf8(&output.stdout).unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert!(
|
|
|
|
output.contains("main_test ... ok"),
|
|
|
|
"no main_test\n{}",
|
|
|
|
output
|
|
|
|
);
|
|
|
|
assert!(
|
|
|
|
output.contains("test_test ... ok"),
|
|
|
|
"no test_test\n{}",
|
|
|
|
output
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 16:09:33 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_dylib() {
|
2014-07-23 16:09:33 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-23 16:09:33 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-23 16:09:33 +00:00
|
|
|
name = "foo"
|
|
|
|
crate_type = ["dylib"]
|
2014-08-07 00:50:55 +00:00
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-03-30 19:30:50 +00:00
|
|
|
extern crate bar as the_bar;
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2014-08-18 01:34:50 +00:00
|
|
|
pub fn bar() { the_bar::baz(); }
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2014-07-23 16:09:33 +00:00
|
|
|
#[test]
|
2014-08-07 00:50:55 +00:00
|
|
|
fn foo() { bar(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/test.rs",
|
|
|
|
r#"
|
2015-03-30 19:30:50 +00:00
|
|
|
extern crate foo as the_foo;
|
2014-08-07 00:50:55 +00:00
|
|
|
|
|
|
|
#[test]
|
2014-08-18 01:34:50 +00:00
|
|
|
fn foo() { the_foo::bar(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-08-07 00:50:55 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-08-07 00:50:55 +00:00
|
|
|
name = "bar"
|
|
|
|
crate_type = ["dylib"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
"
|
2014-08-07 00:50:55 +00:00
|
|
|
pub fn baz() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 16:09:33 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] bar v0.0.1 ({dir}/bar)
|
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains_n("test foo ... ok", 2),
|
|
|
|
);
|
2014-08-01 03:21:13 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
p.root().move_into_the_past();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]",
|
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test foo ... ok", 2),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 16:36:49 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_twice_with_build_cmd() {
|
2014-07-23 16:36:49 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-07-23 16:36:49 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-01-19 22:27:51 +00:00
|
|
|
build = "build.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-01-19 22:27:51 +00:00
|
|
|
.file("build.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-07-23 16:36:49 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 16:36:49 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-19 04:38:04 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_then_build() {
|
2014-08-19 04:38:04 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-19 04:38:04 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-08-19 04:38:04 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-08-19 04:38:04 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2014-08-19 04:38:04 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0).with_stdout(""));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-21 21:09:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_no_run() {
|
2014-08-21 21:09:27 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-21 21:09:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2014-08-21 21:09:27 +00:00
|
|
|
#[test]
|
2014-10-30 01:59:06 +00:00
|
|
|
fn foo() { panic!() }
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-08-21 21:09:27 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--no-run"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2014-08-21 21:09:27 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.url()
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-25 12:54:47 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_run_specific_bin_target() {
|
2014-10-28 08:31:34 +00:00
|
|
|
let prj = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-28 08:31:34 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="bin1"
|
|
|
|
path="src/bin1.rs"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="bin2"
|
|
|
|
path="src/bin2.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-28 08:31:34 +00:00
|
|
|
.file("src/bin1.rs", "#[test] fn test1() { }")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/bin2.rs", "#[test] fn test2() { }")
|
|
|
|
.build();
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
prj.cargo("test").arg("--bin").arg("bin2"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]bin2-[..][EXE]",
|
|
|
|
dir = prj.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test2 ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2017-04-05 19:48:15 +00:00
|
|
|
#[test]
|
|
|
|
fn test_run_implicit_bin_target() {
|
|
|
|
let prj = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-05 19:48:15 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="mybin"
|
|
|
|
path="src/mybin.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
2017-04-05 19:48:15 +00:00
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
|
|
|
.file("benches/mybench.rs", "#[test] fn test_in_bench() { }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/myexm.rs",
|
|
|
|
"#[test] fn test_in_exm() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
prj.cargo("test").arg("--bins"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2017-04-05 19:48:15 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]mybin-[..][EXE]",
|
|
|
|
dir = prj.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test_in_bin ... ok"),
|
|
|
|
);
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_run_specific_test_target() {
|
2014-10-28 08:31:34 +00:00
|
|
|
let prj = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-28 08:31:34 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-28 08:31:34 +00:00
|
|
|
.file("src/bin/a.rs", "fn main() { }")
|
|
|
|
.file("src/bin/b.rs", "#[test] fn test_b() { } fn main() { }")
|
|
|
|
.file("tests/a.rs", "#[test] fn test_a() { }")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("tests/b.rs", "#[test] fn test_b() { }")
|
|
|
|
.build();
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
prj.cargo("test").arg("--test").arg("b"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]b-[..][EXE]",
|
|
|
|
dir = prj.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test_b ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2017-04-05 19:48:15 +00:00
|
|
|
#[test]
|
|
|
|
fn test_run_implicit_test_target() {
|
|
|
|
let prj = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-05 19:48:15 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="mybin"
|
|
|
|
path="src/mybin.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
2017-04-05 19:48:15 +00:00
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
|
|
|
.file("benches/mybench.rs", "#[test] fn test_in_bench() { }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/myexm.rs",
|
|
|
|
"#[test] fn test_in_exm() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
prj.cargo("test").arg("--tests"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2017-04-05 19:48:15 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2017-10-20 21:34:21 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]mybin-[..][EXE]
|
|
|
|
[RUNNING] target[/]debug[/]deps[/]mytest-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]examples[/]myexm-[..][EXE]",
|
|
|
|
dir = prj.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test_in_test ... ok"),
|
|
|
|
);
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_run_implicit_bench_target() {
|
|
|
|
let prj = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-05 19:48:15 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="mybin"
|
|
|
|
path="src/mybin.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
2017-04-05 19:48:15 +00:00
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
|
|
|
.file("benches/mybench.rs", "#[test] fn test_in_bench() { }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/myexm.rs",
|
|
|
|
"#[test] fn test_in_exm() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
prj.cargo("test").arg("--benches"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(format!(
|
|
|
|
"\
|
2017-04-05 19:48:15 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2017-10-20 21:34:21 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]mybin-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]mybench-[..][EXE]",
|
|
|
|
dir = prj.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("test test_in_bench ... ok"),
|
|
|
|
);
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_run_implicit_example_target() {
|
|
|
|
let prj = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-05 19:48:15 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="mybin"
|
|
|
|
path="src/mybin.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
2017-04-05 19:48:15 +00:00
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
|
|
|
.file("benches/mybench.rs", "#[test] fn test_in_bench() { }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/myexm.rs",
|
|
|
|
"#[test] fn test_in_exm() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-05 19:48:15 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
prj.cargo("test").arg("--examples"),
|
|
|
|
execs().with_status(0).with_stderr(format!(
|
|
|
|
"\
|
2017-04-05 19:48:15 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-10-08 01:55:00 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]examples[/]myexm-[..][EXE]",
|
|
|
|
dir = prj.url()
|
|
|
|
)),
|
|
|
|
);
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_no_harness() {
|
2014-08-25 12:54:47 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-08-25 12:54:47 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "bar"
|
|
|
|
path = "foo.rs"
|
|
|
|
harness = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-08-25 12:54:47 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("foo.rs", "fn main() {}")
|
|
|
|
.build();
|
2014-08-25 12:54:47 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--").arg("--nocapture"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]bar-[..][EXE]
|
2014-08-25 12:54:47 +00:00
|
|
|
",
|
2018-03-14 15:17:44 +00:00
|
|
|
dir = p.url()
|
|
|
|
)),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-24 01:10:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn selective_testing() {
|
2014-09-24 01:10:27 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-09-24 01:10:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
[dependencies.d2]
|
|
|
|
path = "d2"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-09-24 01:10:27 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2014-09-24 01:10:27 +00:00
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-09-24 01:10:27 +00:00
|
|
|
.file("d1/src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d1/src/main.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate d1; fn main() {}",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"d2/Cargo.toml",
|
|
|
|
r#"
|
2014-09-24 01:10:27 +00:00
|
|
|
[package]
|
|
|
|
name = "d2"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d2"
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-03-21 01:53:00 +00:00
|
|
|
.file("d2/src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d2/src/main.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate d2; fn main() {}",
|
|
|
|
);
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2014-09-24 01:10:27 +00:00
|
|
|
|
|
|
|
println!("d1");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-p").arg("d1"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] d1 v0.0.1 ({dir}/d1)
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]d1-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]d1-[..][EXE]",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains_n("running 0 tests", 2),
|
|
|
|
);
|
2014-09-24 01:10:27 +00:00
|
|
|
|
|
|
|
println!("d2");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-p").arg("d2"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] d2 v0.0.1 ({dir}/d2)
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]d2-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]d2-[..][EXE]",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains_n("running 0 tests", 2),
|
|
|
|
);
|
2014-09-24 01:10:27 +00:00
|
|
|
|
|
|
|
println!("whole");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-24 05:14:02 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn almost_cyclic_but_not_quite() {
|
2014-09-24 05:14:02 +00:00
|
|
|
let p = project("a")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-09-24 05:14:02 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies.b]
|
|
|
|
path = "b"
|
|
|
|
[dev-dependencies.c]
|
|
|
|
path = "c"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-09-24 05:14:02 +00:00
|
|
|
#[cfg(test)] extern crate b;
|
|
|
|
#[cfg(test)] extern crate c;
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2014-09-24 05:14:02 +00:00
|
|
|
[package]
|
|
|
|
name = "b"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.a]
|
|
|
|
path = ".."
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/src/lib.rs",
|
|
|
|
r#"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2014-09-24 05:14:02 +00:00
|
|
|
extern crate a;
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"c/Cargo.toml",
|
|
|
|
r#"
|
2014-09-24 05:14:02 +00:00
|
|
|
[package]
|
|
|
|
name = "c"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("c/src/lib.rs", "")
|
|
|
|
.build();
|
2014-09-24 05:14:02 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-06 18:27:16 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn build_then_selective_test() {
|
2014-10-06 18:27:16 +00:00
|
|
|
let p = project("a")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-06 18:27:16 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.b]
|
|
|
|
path = "b"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate b;",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate b;
|
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate a;
|
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2014-10-06 18:27:16 +00:00
|
|
|
[package]
|
|
|
|
name = "b"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
2014-10-06 18:27:16 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
assert_that(p.cargo("build"), execs().with_status(0));
|
2016-05-26 00:06:25 +00:00
|
|
|
p.root().move_into_the_past();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-p").arg("b"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-03 01:57:33 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn example_dev_dep() {
|
2014-10-06 03:00:42 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-06 03:00:42 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies.bar]
|
|
|
|
path = "bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/e1.rs",
|
|
|
|
r#"
|
2014-10-06 03:00:42 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() { }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2014-10-06 03:00:42 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2014-10-06 03:00:42 +00:00
|
|
|
// make sure this file takes awhile to compile
|
Overhaul how cargo treats profiles
This commit is a complete overhaul of how Cargo handles compilation profiles
internally. The external interface of Cargo is not affected by this change.
Previously each Target had a Profile embedded within it. Conceptually a Target
is an entry in the manifest (a binary, benchmark, etc) and a Profile controlled
various flags (e.g. --test, -C opt-level, etc). Each Package then contained many
profiles for each possible compilation mode. For example a Package would have
one target for testing a library, benchmarking a library, documenting a library,
etc. When it came to building these targets, Cargo would filter out the targets
listed to determine what needed to be built.
This filtering was largely done based off an "environment" represented as a
string. Each mode of compilation got a separate environment string like `"test"`
or `"bench"`. Altogether, however, this approach had a number of drawbacks:
* Examples in release mode do not currently work. This is due to how examples
are classified and how release mode is handled (e.g. the "release" environment
where examples are meant to be built in the "test" environment).
* It is not trivial to implement `cargo test --release` today.
* It is not trivial to implement `cargo build --bin foo` where *only* the binary
`foo` is built. The same is true for examples.
* It is not trivial to add selective building of a number of
binaries/examples/etc.
* Filtering the list of targets to build has some pretty hokey logic that
involves pseudo-environments like "doc-all" vs "doc". This logic is duplicated
in a few places and in general is quite brittle.
* The TOML parser greatly affects compilation due to the time at which profiles
are generated, which seems somewhat backwards.
* Profiles must be overridden, but only partially, at compile time becuase only
the top-level package's profile is applied.
In general, this system just needed an overhaul. This commit made a single
change of separating `Profile` from `Target` and then basically hit `make` until
all the tests passed again. The other large architectural changes are:
* Environment strings are now entirely gone.
* Filters are implemented in a much more robust fashion.
* Release mode is now handled much more gracefully.
* The unit of compilation in the backend is no longer (package, target) but
rather (package, target, profile). This change had to be propagated many
location in the `cargo_rustc` module.
* The backend does not filter targets to build *at all*. All filtering now
happens entirely in the frontend.
I'll test issues after this change lands, but the motivation behind this is to
open the door to quickly fixing a number of outstanding issues against Cargo.
This change itself is not intended to close many bugs.
2015-02-19 19:30:35 +00:00
|
|
|
macro_rules! f0( () => (1) );
|
2014-12-19 18:38:32 +00:00
|
|
|
macro_rules! f1( () => ({(f0!()) + (f0!())}) );
|
|
|
|
macro_rules! f2( () => ({(f1!()) + (f1!())}) );
|
|
|
|
macro_rules! f3( () => ({(f2!()) + (f2!())}) );
|
|
|
|
macro_rules! f4( () => ({(f3!()) + (f3!())}) );
|
|
|
|
macro_rules! f5( () => ({(f4!()) + (f4!())}) );
|
|
|
|
macro_rules! f6( () => ({(f5!()) + (f5!())}) );
|
|
|
|
macro_rules! f7( () => ({(f6!()) + (f6!())}) );
|
|
|
|
macro_rules! f8( () => ({(f7!()) + (f7!())}) );
|
2014-10-06 03:00:42 +00:00
|
|
|
pub fn bar() {
|
2015-04-02 18:12:21 +00:00
|
|
|
f8!();
|
2014-10-06 03:00:42 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
|
|
|
assert_that(
|
|
|
|
p.cargo("run")
|
|
|
|
.arg("--example")
|
|
|
|
.arg("e1")
|
|
|
|
.arg("--release")
|
|
|
|
.arg("-v"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-06 03:00:42 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn selective_testing_with_docs() {
|
2014-10-03 01:57:33 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-03 01:57:33 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2014-10-03 01:57:33 +00:00
|
|
|
/// ```
|
|
|
|
/// not valid rust
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2014-10-03 01:57:33 +00:00
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-10-07 19:01:10 +00:00
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
path = "d1.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-07 19:01:10 +00:00
|
|
|
.file("d1/d1.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2014-10-03 01:57:33 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-p").arg("d1"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] d1 v0.0.1 ({dir}/d1)
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]d1[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] d1",
|
|
|
|
dir = p.url()
|
|
|
|
))
|
|
|
|
.with_stdout_contains_n("running 0 tests", 2),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-24 16:18:19 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn example_bin_same_name() {
|
2014-10-24 16:18:19 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-24 16:18:19 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-24 16:18:19 +00:00
|
|
|
.file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/foo.rs", r#"fn main() { println!("example"); }"#)
|
|
|
|
.build();
|
2014-10-24 16:18:19 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--no-run").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr(&format!(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ({dir})
|
|
|
|
[RUNNING] `rustc [..]`
|
|
|
|
[RUNNING] `rustc [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
dir = p.url()
|
|
|
|
)),
|
|
|
|
);
|
2014-10-24 16:18:19 +00:00
|
|
|
|
2015-03-21 02:31:12 +00:00
|
|
|
assert_that(&p.bin("foo"), is_not(existing_file()));
|
2014-10-24 16:18:19 +00:00
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.process(&p.bin("examples/foo")),
|
|
|
|
execs().with_status(0).with_stdout("example\n"),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("run"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] [..]",
|
|
|
|
)
|
2018-03-14 15:43:41 +00:00
|
|
|
.with_stdout("bin"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2015-03-21 02:31:12 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-29 23:33:52 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_with_example_twice() {
|
2014-10-29 23:33:52 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-10-29 23:33:52 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-10-29 23:33:52 +00:00
|
|
|
.file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("examples/foo.rs", r#"fn main() { println!("example"); }"#)
|
|
|
|
.build();
|
2014-10-29 23:33:52 +00:00
|
|
|
|
|
|
|
println!("first");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2014-10-29 23:33:52 +00:00
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
|
|
|
println!("second");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2014-10-29 23:33:52 +00:00
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-12-28 09:04:10 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn example_with_dev_dep() {
|
2014-12-28 09:04:10 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2014-12-28 09:04:10 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
|
|
|
|
[dev-dependencies.a]
|
|
|
|
path = "a"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2014-12-28 09:04:10 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/ex.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate a; fn main() {}",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2014-12-28 09:04:10 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
2014-12-28 09:04:10 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-v"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2014-12-28 09:04:10 +00:00
|
|
|
[..]
|
|
|
|
[..]
|
|
|
|
[..]
|
|
|
|
[..]
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc --crate-name ex [..] --extern a=[..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-14 05:23:43 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bin_is_preserved() {
|
2015-01-14 05:23:43 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-01-14 05:23:43 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-01-14 05:23:43 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2015-01-14 05:23:43 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
|
2015-01-14 05:23:43 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
|
|
|
println!("testing");
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2015-01-14 05:23:43 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-02-09 16:28:36 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bad_example() {
|
2015-02-09 16:28:36 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-02-09 16:28:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-02-09 16:28:36 +00:00
|
|
|
.file("src/lib.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2015-02-09 16:28:36 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--example").arg("foo"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] no example target named `foo`"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
p.cargo("run").arg("--bin").arg("foo"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] no bin target named `foo`"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-02-09 19:14:27 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_feature() {
|
2015-02-09 19:14:27 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-02-09 19:14:27 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
[features]
|
|
|
|
bar = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-02-09 19:14:27 +00:00
|
|
|
/// ```rust
|
|
|
|
/// assert_eq!(foo::foo(), 1);
|
|
|
|
/// ```
|
|
|
|
#[cfg(feature = "bar")]
|
|
|
|
pub fn foo() -> i32 { 1 }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-02-09 19:14:27 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--features").arg("bar"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo [..]
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.with_stdout_contains("test [..] ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-03-26 19:07:11 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dashes_to_underscores() {
|
2015-03-26 19:07:11 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-03-26 19:07:11 +00:00
|
|
|
[package]
|
|
|
|
name = "foo-bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-03-26 19:07:11 +00:00
|
|
|
/// ```
|
|
|
|
/// assert_eq!(foo_bar::foo(), 1);
|
|
|
|
/// ```
|
|
|
|
pub fn foo() -> i32 { 1 }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-03-26 19:07:11 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-02 18:51:29 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn doctest_dev_dep() {
|
2015-04-02 18:51:29 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-04-02 18:51:29 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
b = { path = "b" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-04-02 18:51:29 +00:00
|
|
|
/// ```
|
|
|
|
/// extern crate b;
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2015-04-02 18:51:29 +00:00
|
|
|
[package]
|
|
|
|
name = "b"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
2015-04-02 18:51:29 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-07 23:56:45 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn filter_no_doc_tests() {
|
2015-04-07 23:56:45 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-04-07 23:56:45 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-04-07 23:56:45 +00:00
|
|
|
/// ```
|
|
|
|
/// extern crate b;
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("tests/foo.rs", "")
|
|
|
|
.build();
|
2015-04-07 23:56:45 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--test=foo"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo[..][EXE]",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dylib_doctest() {
|
2015-04-09 17:43:49 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-04-09 17:43:49 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
crate-type = ["rlib", "dylib"]
|
|
|
|
test = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-04-09 17:43:49 +00:00
|
|
|
/// ```
|
|
|
|
/// foo::foo();
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("test [..] ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dylib_doctest2() {
|
2015-04-09 17:43:49 +00:00
|
|
|
// can't doctest dylibs as they're statically linked together
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-04-09 17:43:49 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
crate-type = ["dylib"]
|
|
|
|
test = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-04-09 17:43:49 +00:00
|
|
|
/// ```
|
|
|
|
/// foo::foo();
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0).with_stdout(""));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-06 08:22:36 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn cyclic_dev_dep_doc_test() {
|
2015-06-06 08:22:36 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-06-06 08:22:36 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
bar = { path = "bar" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-06-06 08:22:36 +00:00
|
|
|
//! ```
|
|
|
|
//! extern crate bar;
|
|
|
|
//! ```
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2015-06-06 08:22:36 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
foo = { path = ".." }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
2015-06-06 08:22:36 +00:00
|
|
|
extern crate foo;
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
|
|
[COMPILING] bar v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.with_stdout_contains("test [..] ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-01 17:37:21 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn dev_dep_with_build_script() {
|
2015-07-01 17:37:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-07-01 17:37:21 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
bar = { path = "bar" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-07-01 17:37:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("examples/foo.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2015-07-01 17:37:21 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-07-01 17:37:21 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/build.rs", "fn main() {}")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-28 02:37:45 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn no_fail_fast() {
|
2015-08-28 02:37:45 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-08-28 02:37:45 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2015-08-28 02:37:45 +00:00
|
|
|
pub fn add_one(x: i32) -> i32{
|
|
|
|
x + 1
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ```rust
|
|
|
|
/// use foo::sub_one;
|
|
|
|
/// assert_eq!(sub_one(101), 100);
|
|
|
|
/// ```
|
|
|
|
pub fn sub_one(x: i32) -> i32{
|
|
|
|
x - 1
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/test_add_one.rs",
|
|
|
|
r#"
|
2015-08-28 02:37:45 +00:00
|
|
|
extern crate foo;
|
|
|
|
use foo::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn add_one_test() {
|
|
|
|
assert_eq!(add_one(1), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fail_add_one_test() {
|
|
|
|
assert_eq!(add_one(1), 1);
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/test_sub_one.rs",
|
|
|
|
r#"
|
2015-08-28 02:37:45 +00:00
|
|
|
extern crate foo;
|
|
|
|
use foo::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sub_one_test() {
|
|
|
|
assert_eq!(sub_one(1), 0);
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--no-fail-fast"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-11-06 02:14:16 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]test_add_one-[..][EXE]",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
2016-10-04 23:16:30 +00:00
|
|
|
[RUNNING] target[/]debug[/]deps[/]test_sub_one-[..][EXE]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("test result: FAILED. [..]")
|
|
|
|
.with_stdout_contains("test sub_one_test ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 3),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_multiple_packages() {
|
2015-07-16 20:35:40 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-07-16 20:35:40 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
[dependencies.d2]
|
|
|
|
path = "d2"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-07-16 20:35:40 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2015-07-16 20:35:40 +00:00
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-07-16 20:35:40 +00:00
|
|
|
.file("d1/src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d2/Cargo.toml",
|
|
|
|
r#"
|
2015-07-16 20:35:40 +00:00
|
|
|
[package]
|
|
|
|
name = "d2"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d2"
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-07-16 20:35:40 +00:00
|
|
|
.file("d2/src/lib.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-p").arg("d1").arg("-p").arg("d2"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
2018-03-14 15:43:41 +00:00
|
|
|
.with_stderr_contains("[RUNNING] target[/]debug[/]deps[/]d1-[..][EXE]")
|
|
|
|
.with_stderr_contains("[RUNNING] target[/]debug[/]deps[/]d2-[..][EXE]")
|
2018-03-14 15:17:44 +00:00
|
|
|
.with_stdout_contains_n("running 0 tests", 2),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
Refactor Cargo's backend, again!
This commit started out identifying a relatively simple bug in Cargo. A recent
change made it such that the resolution graph included all target-specific
dependencies, relying on the structure of the backend to filter out those which
don't need to get built. This was unfortunately not accounted for in the portion
of the backend that schedules work, mistakenly causing spurious rebuilds if
different runs of the graph pulled in new crates. For example if `cargo build`
didn't build any target-specific dependencies but then later `cargo test` did
(e.g. a dev-dep pulled in a target-specific dep unconditionally) then it would
cause a rebuild of the entire graph.
This class of bug is certainly not the first in a long and storied history of
the backend having multiple points where dependencies are calculated and those
often don't quite agree with one another. The purpose of this rewrite is
twofold:
1. The `Stage` enum in the backend for scheduling work and ensuring that maximum
parallelism is achieved is removed entirely. There is already a function on
`Context` which expresses the dependency between targets (`dep_targets`)
which takes a much finer grain of dependencies into account as well as
already having all the logic for what-depends-on-what. This duplication has
caused numerous problems in the past, an unifying these two will truly grant
maximum parallelism while ensuring that everyone agrees on what their
dependencies are.
2. A large number of locations in the backend have grown to take a (Package,
Target, Profile, Kind) tuple, or some subset of this tuple. In general this
represents a "unit of work" and is much easier to pass around as one
variable, so a `Unit` was introduced which references all of these variables.
Almost the entire backend was altered to take a `Unit` instead of these
variables specifically, typically providing all of the contextual information
necessary for an operation.
A crucial part of this change is the inclusion of `Kind` in a `Unit` to ensure
that everyone *also* agrees on what architecture they're compiling everything
for. There have been many bugs in the past where one part of the backend
determined that a package was built for one architecture and then another part
thought it was built for another. With the inclusion of `Kind` in dependency
management this is handled in a much cleaner fashion as it's only calculated in
one location.
Some other miscellaneous changes made were:
* The `Platform` enumeration has finally been removed. This has been entirely
subsumed by `Kind`.
* The hokey logic for "build this crate once" even though it may be depended on
by both the host/target kinds has been removed. This is now handled in a much
nicer fashion where if there's no target then Kind::Target is just never used,
and multiple requests for a package are just naturally deduplicated.
* There's no longer any need to build up the "requirements" for a package in
terms of what platforms it's compiled for, this now just naturally falls out
of the dependency graph.
* If a build script is overridden then its entire tree of dependencies are not
compiled, not just the build script itself.
* The `threadpool` dependency has been replaced with one on `crossbeam`. The
method of calculating dependencies has quite a few non-static lifetimes and
the scoped threads of `crossbeam` are now used instead of a thread pool.
* Once any thread fails to execute a command work is no longer scheduled unlike
before where some extra pending work may continue to start.
* Many functions used early on, such as `compile` and `build_map` have been
massively simplified by farming out dependency management to
`Context::dep_targets`.
* There is now a new profile to represent running a build script. This is used
to inject dependencies as well as represent that a library depends on running
a build script, not just building it.
This change has currently been tested against cross-compiling Servo to Android
and passes the test suite (which has quite a few corner cases for build scripts
and such), so I'm pretty confident that this refactoring won't have at least too
many regressions!
2015-10-02 06:48:47 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn bin_does_not_rebuild_tests() {
|
Refactor Cargo's backend, again!
This commit started out identifying a relatively simple bug in Cargo. A recent
change made it such that the resolution graph included all target-specific
dependencies, relying on the structure of the backend to filter out those which
don't need to get built. This was unfortunately not accounted for in the portion
of the backend that schedules work, mistakenly causing spurious rebuilds if
different runs of the graph pulled in new crates. For example if `cargo build`
didn't build any target-specific dependencies but then later `cargo test` did
(e.g. a dev-dep pulled in a target-specific dep unconditionally) then it would
cause a rebuild of the entire graph.
This class of bug is certainly not the first in a long and storied history of
the backend having multiple points where dependencies are calculated and those
often don't quite agree with one another. The purpose of this rewrite is
twofold:
1. The `Stage` enum in the backend for scheduling work and ensuring that maximum
parallelism is achieved is removed entirely. There is already a function on
`Context` which expresses the dependency between targets (`dep_targets`)
which takes a much finer grain of dependencies into account as well as
already having all the logic for what-depends-on-what. This duplication has
caused numerous problems in the past, an unifying these two will truly grant
maximum parallelism while ensuring that everyone agrees on what their
dependencies are.
2. A large number of locations in the backend have grown to take a (Package,
Target, Profile, Kind) tuple, or some subset of this tuple. In general this
represents a "unit of work" and is much easier to pass around as one
variable, so a `Unit` was introduced which references all of these variables.
Almost the entire backend was altered to take a `Unit` instead of these
variables specifically, typically providing all of the contextual information
necessary for an operation.
A crucial part of this change is the inclusion of `Kind` in a `Unit` to ensure
that everyone *also* agrees on what architecture they're compiling everything
for. There have been many bugs in the past where one part of the backend
determined that a package was built for one architecture and then another part
thought it was built for another. With the inclusion of `Kind` in dependency
management this is handled in a much cleaner fashion as it's only calculated in
one location.
Some other miscellaneous changes made were:
* The `Platform` enumeration has finally been removed. This has been entirely
subsumed by `Kind`.
* The hokey logic for "build this crate once" even though it may be depended on
by both the host/target kinds has been removed. This is now handled in a much
nicer fashion where if there's no target then Kind::Target is just never used,
and multiple requests for a package are just naturally deduplicated.
* There's no longer any need to build up the "requirements" for a package in
terms of what platforms it's compiled for, this now just naturally falls out
of the dependency graph.
* If a build script is overridden then its entire tree of dependencies are not
compiled, not just the build script itself.
* The `threadpool` dependency has been replaced with one on `crossbeam`. The
method of calculating dependencies has quite a few non-static lifetimes and
the scoped threads of `crossbeam` are now used instead of a thread pool.
* Once any thread fails to execute a command work is no longer scheduled unlike
before where some extra pending work may continue to start.
* Many functions used early on, such as `compile` and `build_map` have been
massively simplified by farming out dependency management to
`Context::dep_targets`.
* There is now a new profile to represent running a build script. This is used
to inject dependencies as well as represent that a library depends on running
a build script, not just building it.
This change has currently been tested against cross-compiling Servo to Android
and passes the test suite (which has quite a few corner cases for build scripts
and such), so I'm pretty confident that this refactoring won't have at least too
many regressions!
2015-10-02 06:48:47 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
Refactor Cargo's backend, again!
This commit started out identifying a relatively simple bug in Cargo. A recent
change made it such that the resolution graph included all target-specific
dependencies, relying on the structure of the backend to filter out those which
don't need to get built. This was unfortunately not accounted for in the portion
of the backend that schedules work, mistakenly causing spurious rebuilds if
different runs of the graph pulled in new crates. For example if `cargo build`
didn't build any target-specific dependencies but then later `cargo test` did
(e.g. a dev-dep pulled in a target-specific dep unconditionally) then it would
cause a rebuild of the entire graph.
This class of bug is certainly not the first in a long and storied history of
the backend having multiple points where dependencies are calculated and those
often don't quite agree with one another. The purpose of this rewrite is
twofold:
1. The `Stage` enum in the backend for scheduling work and ensuring that maximum
parallelism is achieved is removed entirely. There is already a function on
`Context` which expresses the dependency between targets (`dep_targets`)
which takes a much finer grain of dependencies into account as well as
already having all the logic for what-depends-on-what. This duplication has
caused numerous problems in the past, an unifying these two will truly grant
maximum parallelism while ensuring that everyone agrees on what their
dependencies are.
2. A large number of locations in the backend have grown to take a (Package,
Target, Profile, Kind) tuple, or some subset of this tuple. In general this
represents a "unit of work" and is much easier to pass around as one
variable, so a `Unit` was introduced which references all of these variables.
Almost the entire backend was altered to take a `Unit` instead of these
variables specifically, typically providing all of the contextual information
necessary for an operation.
A crucial part of this change is the inclusion of `Kind` in a `Unit` to ensure
that everyone *also* agrees on what architecture they're compiling everything
for. There have been many bugs in the past where one part of the backend
determined that a package was built for one architecture and then another part
thought it was built for another. With the inclusion of `Kind` in dependency
management this is handled in a much cleaner fashion as it's only calculated in
one location.
Some other miscellaneous changes made were:
* The `Platform` enumeration has finally been removed. This has been entirely
subsumed by `Kind`.
* The hokey logic for "build this crate once" even though it may be depended on
by both the host/target kinds has been removed. This is now handled in a much
nicer fashion where if there's no target then Kind::Target is just never used,
and multiple requests for a package are just naturally deduplicated.
* There's no longer any need to build up the "requirements" for a package in
terms of what platforms it's compiled for, this now just naturally falls out
of the dependency graph.
* If a build script is overridden then its entire tree of dependencies are not
compiled, not just the build script itself.
* The `threadpool` dependency has been replaced with one on `crossbeam`. The
method of calculating dependencies has quite a few non-static lifetimes and
the scoped threads of `crossbeam` are now used instead of a thread pool.
* Once any thread fails to execute a command work is no longer scheduled unlike
before where some extra pending work may continue to start.
* Many functions used early on, such as `compile` and `build_map` have been
massively simplified by farming out dependency management to
`Context::dep_targets`.
* There is now a new profile to represent running a build script. This is used
to inject dependencies as well as represent that a library depends on running
a build script, not just building it.
This change has currently been tested against cross-compiling Servo to Android
and passes the test suite (which has quite a few corner cases for build scripts
and such), so I'm pretty confident that this refactoring won't have at least too
many regressions!
2015-10-02 06:48:47 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
Refactor Cargo's backend, again!
This commit started out identifying a relatively simple bug in Cargo. A recent
change made it such that the resolution graph included all target-specific
dependencies, relying on the structure of the backend to filter out those which
don't need to get built. This was unfortunately not accounted for in the portion
of the backend that schedules work, mistakenly causing spurious rebuilds if
different runs of the graph pulled in new crates. For example if `cargo build`
didn't build any target-specific dependencies but then later `cargo test` did
(e.g. a dev-dep pulled in a target-specific dep unconditionally) then it would
cause a rebuild of the entire graph.
This class of bug is certainly not the first in a long and storied history of
the backend having multiple points where dependencies are calculated and those
often don't quite agree with one another. The purpose of this rewrite is
twofold:
1. The `Stage` enum in the backend for scheduling work and ensuring that maximum
parallelism is achieved is removed entirely. There is already a function on
`Context` which expresses the dependency between targets (`dep_targets`)
which takes a much finer grain of dependencies into account as well as
already having all the logic for what-depends-on-what. This duplication has
caused numerous problems in the past, an unifying these two will truly grant
maximum parallelism while ensuring that everyone agrees on what their
dependencies are.
2. A large number of locations in the backend have grown to take a (Package,
Target, Profile, Kind) tuple, or some subset of this tuple. In general this
represents a "unit of work" and is much easier to pass around as one
variable, so a `Unit` was introduced which references all of these variables.
Almost the entire backend was altered to take a `Unit` instead of these
variables specifically, typically providing all of the contextual information
necessary for an operation.
A crucial part of this change is the inclusion of `Kind` in a `Unit` to ensure
that everyone *also* agrees on what architecture they're compiling everything
for. There have been many bugs in the past where one part of the backend
determined that a package was built for one architecture and then another part
thought it was built for another. With the inclusion of `Kind` in dependency
management this is handled in a much cleaner fashion as it's only calculated in
one location.
Some other miscellaneous changes made were:
* The `Platform` enumeration has finally been removed. This has been entirely
subsumed by `Kind`.
* The hokey logic for "build this crate once" even though it may be depended on
by both the host/target kinds has been removed. This is now handled in a much
nicer fashion where if there's no target then Kind::Target is just never used,
and multiple requests for a package are just naturally deduplicated.
* There's no longer any need to build up the "requirements" for a package in
terms of what platforms it's compiled for, this now just naturally falls out
of the dependency graph.
* If a build script is overridden then its entire tree of dependencies are not
compiled, not just the build script itself.
* The `threadpool` dependency has been replaced with one on `crossbeam`. The
method of calculating dependencies has quite a few non-static lifetimes and
the scoped threads of `crossbeam` are now used instead of a thread pool.
* Once any thread fails to execute a command work is no longer scheduled unlike
before where some extra pending work may continue to start.
* Many functions used early on, such as `compile` and `build_map` have been
massively simplified by farming out dependency management to
`Context::dep_targets`.
* There is now a new profile to represent running a build script. This is used
to inject dependencies as well as represent that a library depends on running
a build script, not just building it.
This change has currently been tested against cross-compiling Servo to Android
and passes the test suite (which has quite a few corner cases for build scripts
and such), so I'm pretty confident that this refactoring won't have at least too
many regressions!
2015-10-02 06:48:47 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("tests/foo.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
Refactor Cargo's backend, again!
This commit started out identifying a relatively simple bug in Cargo. A recent
change made it such that the resolution graph included all target-specific
dependencies, relying on the structure of the backend to filter out those which
don't need to get built. This was unfortunately not accounted for in the portion
of the backend that schedules work, mistakenly causing spurious rebuilds if
different runs of the graph pulled in new crates. For example if `cargo build`
didn't build any target-specific dependencies but then later `cargo test` did
(e.g. a dev-dep pulled in a target-specific dep unconditionally) then it would
cause a rebuild of the entire graph.
This class of bug is certainly not the first in a long and storied history of
the backend having multiple points where dependencies are calculated and those
often don't quite agree with one another. The purpose of this rewrite is
twofold:
1. The `Stage` enum in the backend for scheduling work and ensuring that maximum
parallelism is achieved is removed entirely. There is already a function on
`Context` which expresses the dependency between targets (`dep_targets`)
which takes a much finer grain of dependencies into account as well as
already having all the logic for what-depends-on-what. This duplication has
caused numerous problems in the past, an unifying these two will truly grant
maximum parallelism while ensuring that everyone agrees on what their
dependencies are.
2. A large number of locations in the backend have grown to take a (Package,
Target, Profile, Kind) tuple, or some subset of this tuple. In general this
represents a "unit of work" and is much easier to pass around as one
variable, so a `Unit` was introduced which references all of these variables.
Almost the entire backend was altered to take a `Unit` instead of these
variables specifically, typically providing all of the contextual information
necessary for an operation.
A crucial part of this change is the inclusion of `Kind` in a `Unit` to ensure
that everyone *also* agrees on what architecture they're compiling everything
for. There have been many bugs in the past where one part of the backend
determined that a package was built for one architecture and then another part
thought it was built for another. With the inclusion of `Kind` in dependency
management this is handled in a much cleaner fashion as it's only calculated in
one location.
Some other miscellaneous changes made were:
* The `Platform` enumeration has finally been removed. This has been entirely
subsumed by `Kind`.
* The hokey logic for "build this crate once" even though it may be depended on
by both the host/target kinds has been removed. This is now handled in a much
nicer fashion where if there's no target then Kind::Target is just never used,
and multiple requests for a package are just naturally deduplicated.
* There's no longer any need to build up the "requirements" for a package in
terms of what platforms it's compiled for, this now just naturally falls out
of the dependency graph.
* If a build script is overridden then its entire tree of dependencies are not
compiled, not just the build script itself.
* The `threadpool` dependency has been replaced with one on `crossbeam`. The
method of calculating dependencies has quite a few non-static lifetimes and
the scoped threads of `crossbeam` are now used instead of a thread pool.
* Once any thread fails to execute a command work is no longer scheduled unlike
before where some extra pending work may continue to start.
* Many functions used early on, such as `compile` and `build_map` have been
massively simplified by farming out dependency management to
`Context::dep_targets`.
* There is now a new profile to represent running a build script. This is used
to inject dependencies as well as represent that a library depends on running
a build script, not just building it.
This change has currently been tested against cross-compiling Servo to Android
and passes the test suite (which has quite a few corner cases for build scripts
and such), so I'm pretty confident that this refactoring won't have at least too
many regressions!
2015-10-02 06:48:47 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
Refactor Cargo's backend, again!
This commit started out identifying a relatively simple bug in Cargo. A recent
change made it such that the resolution graph included all target-specific
dependencies, relying on the structure of the backend to filter out those which
don't need to get built. This was unfortunately not accounted for in the portion
of the backend that schedules work, mistakenly causing spurious rebuilds if
different runs of the graph pulled in new crates. For example if `cargo build`
didn't build any target-specific dependencies but then later `cargo test` did
(e.g. a dev-dep pulled in a target-specific dep unconditionally) then it would
cause a rebuild of the entire graph.
This class of bug is certainly not the first in a long and storied history of
the backend having multiple points where dependencies are calculated and those
often don't quite agree with one another. The purpose of this rewrite is
twofold:
1. The `Stage` enum in the backend for scheduling work and ensuring that maximum
parallelism is achieved is removed entirely. There is already a function on
`Context` which expresses the dependency between targets (`dep_targets`)
which takes a much finer grain of dependencies into account as well as
already having all the logic for what-depends-on-what. This duplication has
caused numerous problems in the past, an unifying these two will truly grant
maximum parallelism while ensuring that everyone agrees on what their
dependencies are.
2. A large number of locations in the backend have grown to take a (Package,
Target, Profile, Kind) tuple, or some subset of this tuple. In general this
represents a "unit of work" and is much easier to pass around as one
variable, so a `Unit` was introduced which references all of these variables.
Almost the entire backend was altered to take a `Unit` instead of these
variables specifically, typically providing all of the contextual information
necessary for an operation.
A crucial part of this change is the inclusion of `Kind` in a `Unit` to ensure
that everyone *also* agrees on what architecture they're compiling everything
for. There have been many bugs in the past where one part of the backend
determined that a package was built for one architecture and then another part
thought it was built for another. With the inclusion of `Kind` in dependency
management this is handled in a much cleaner fashion as it's only calculated in
one location.
Some other miscellaneous changes made were:
* The `Platform` enumeration has finally been removed. This has been entirely
subsumed by `Kind`.
* The hokey logic for "build this crate once" even though it may be depended on
by both the host/target kinds has been removed. This is now handled in a much
nicer fashion where if there's no target then Kind::Target is just never used,
and multiple requests for a package are just naturally deduplicated.
* There's no longer any need to build up the "requirements" for a package in
terms of what platforms it's compiled for, this now just naturally falls out
of the dependency graph.
* If a build script is overridden then its entire tree of dependencies are not
compiled, not just the build script itself.
* The `threadpool` dependency has been replaced with one on `crossbeam`. The
method of calculating dependencies has quite a few non-static lifetimes and
the scoped threads of `crossbeam` are now used instead of a thread pool.
* Once any thread fails to execute a command work is no longer scheduled unlike
before where some extra pending work may continue to start.
* Many functions used early on, such as `compile` and `build_map` have been
massively simplified by farming out dependency management to
`Context::dep_targets`.
* There is now a new profile to represent running a build script. This is used
to inject dependencies as well as represent that a library depends on running
a build script, not just building it.
This change has currently been tested against cross-compiling Servo to Android
and passes the test suite (which has quite a few corner cases for build scripts
and such), so I'm pretty confident that this refactoring won't have at least too
many regressions!
2015-10-02 06:48:47 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
sleep_ms(1000);
|
2018-03-14 15:17:44 +00:00
|
|
|
File::create(&p.root().join("src/main.rs"))
|
|
|
|
.unwrap()
|
|
|
|
.write_all(b"fn main() { 3; }")
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-v").arg("--no-run"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc [..] src[/]main.rs [..]`
|
|
|
|
[RUNNING] `rustc [..] src[/]main.rs [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-20 22:50:58 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn selective_test_wonky_profile() {
|
2015-10-20 22:50:58 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-10-20 22:50:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[profile.release]
|
|
|
|
opt-level = 2
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-10-20 22:50:58 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2015-10-20 22:50:58 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-10-20 22:50:58 +00:00
|
|
|
.file("a/src/lib.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2015-10-20 22:50:58 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
2018-03-16 17:03:27 +00:00
|
|
|
p.cargo("test -v --no-run --release -p foo -p a"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-21 00:19:56 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn selective_test_optional_dep() {
|
2015-10-21 00:19:56 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2015-10-21 00:19:56 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = "a", optional = true }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-10-21 00:19:56 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2015-10-21 00:19:56 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2015-10-21 00:19:56 +00:00
|
|
|
.file("a/src/lib.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2015-10-21 00:19:56 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test")
|
|
|
|
.arg("-v")
|
|
|
|
.arg("--no-run")
|
|
|
|
.arg("--features")
|
|
|
|
.arg("a")
|
|
|
|
.arg("-p")
|
|
|
|
.arg("a"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] a v0.0.1 ([..])
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc [..] a[/]src[/]lib.rs [..]`
|
|
|
|
[RUNNING] `rustc [..] a[/]src[/]lib.rs [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-04-14 17:37:16 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn only_test_docs() {
|
2016-05-17 13:08:29 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-04-14 17:37:16 +00:00
|
|
|
[package]
|
2016-05-17 13:08:29 +00:00
|
|
|
name = "foo"
|
2016-04-14 17:37:16 +00:00
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-04-14 17:37:16 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() {
|
|
|
|
let a: u32 = "hello";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ```
|
2016-12-20 00:28:06 +00:00
|
|
|
/// foo::bar();
|
2016-04-14 17:37:16 +00:00
|
|
|
/// println!("ok");
|
|
|
|
/// ```
|
|
|
|
pub fn bar() {
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-05-17 13:08:29 +00:00
|
|
|
.file("tests/foo.rs", "this is not rust");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2016-04-14 17:37:16 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--doc"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-17 13:08:29 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("test [..] ... ok"),
|
|
|
|
);
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-05-16 18:56:40 +00:00
|
|
|
|
2016-05-25 20:55:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_panic_abort_with_dep() {
|
2016-05-13 18:35:52 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-05-13 18:35:52 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
panic = 'abort'
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-05-13 18:35:52 +00:00
|
|
|
extern crate bar;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2016-05-13 18:35:52 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-06-20 16:28:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cfg_test_even_with_no_harness() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-06-20 16:28:09 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
harness = false
|
|
|
|
doctest = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-06-20 16:28:09 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
fn main() {
|
|
|
|
println!("hello!");
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("-v"),
|
|
|
|
execs().with_status(0).with_stdout("hello!\n").with_stderr(
|
|
|
|
"\
|
2016-06-20 16:28:09 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
|
|
[RUNNING] `rustc [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2016-06-20 16:28:09 +00:00
|
|
|
[RUNNING] `[..]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2016-06-20 16:28:09 +00:00
|
|
|
}
|
2016-08-19 20:25:13 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn panic_abort_multiple() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-08-19 20:25:13 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
|
|
|
|
|
|
|
[profile.release]
|
|
|
|
panic = 'abort'
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate a;",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2016-08-19 20:25:13 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
2018-03-16 17:03:27 +00:00
|
|
|
p.cargo("test --release -v -p foo -p a"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-08-19 20:25:13 +00:00
|
|
|
}
|
2016-10-31 18:15:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pass_correct_cfgs_flags_to_rustdoc() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-10-31 18:15:03 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
2016-11-01 17:14:41 +00:00
|
|
|
default = ["feature_a/default"]
|
|
|
|
nightly = ["feature_a/nightly"]
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2016-11-01 17:14:41 +00:00
|
|
|
[dependencies.feature_a]
|
|
|
|
path = "libs/feature_a"
|
2016-10-31 18:15:03 +00:00
|
|
|
default-features = false
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-10-31 18:15:03 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
assert!(true);
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"libs/feature_a/Cargo.toml",
|
|
|
|
r#"
|
2016-10-31 18:15:03 +00:00
|
|
|
[package]
|
2016-11-01 17:14:41 +00:00
|
|
|
name = "feature_a"
|
2016-10-31 18:15:03 +00:00
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[features]
|
2017-02-14 19:40:48 +00:00
|
|
|
default = ["mock_serde_codegen"]
|
|
|
|
nightly = ["mock_serde_derive"]
|
2016-10-31 18:15:03 +00:00
|
|
|
|
|
|
|
[dependencies]
|
2017-02-14 19:40:48 +00:00
|
|
|
mock_serde_derive = { path = "../mock_serde_derive", optional = true }
|
2016-10-31 18:15:03 +00:00
|
|
|
|
|
|
|
[build-dependencies]
|
2017-02-14 19:40:48 +00:00
|
|
|
mock_serde_codegen = { path = "../mock_serde_codegen", optional = true }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"libs/feature_a/src/lib.rs",
|
|
|
|
r#"
|
2017-02-14 19:40:48 +00:00
|
|
|
#[cfg(feature = "mock_serde_derive")]
|
2016-10-31 18:15:03 +00:00
|
|
|
const MSG: &'static str = "This is safe";
|
|
|
|
|
2017-02-14 19:40:48 +00:00
|
|
|
#[cfg(feature = "mock_serde_codegen")]
|
2016-10-31 18:15:03 +00:00
|
|
|
const MSG: &'static str = "This is risky";
|
|
|
|
|
|
|
|
pub fn get() -> &'static str {
|
|
|
|
MSG
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"libs/mock_serde_derive/Cargo.toml",
|
|
|
|
r#"
|
2017-02-14 19:40:48 +00:00
|
|
|
[package]
|
|
|
|
name = "mock_serde_derive"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-14 19:40:48 +00:00
|
|
|
.file("libs/mock_serde_derive/src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"libs/mock_serde_codegen/Cargo.toml",
|
|
|
|
r#"
|
2017-02-14 19:40:48 +00:00
|
|
|
[package]
|
|
|
|
name = "mock_serde_codegen"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-14 19:40:48 +00:00
|
|
|
.file("libs/mock_serde_codegen/src/lib.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test")
|
|
|
|
.arg("--package")
|
|
|
|
.arg("feature_a")
|
|
|
|
.arg("--verbose"),
|
|
|
|
execs().with_status(0).with_stderr_contains(
|
|
|
|
"\
|
2016-11-01 17:14:41 +00:00
|
|
|
[DOCTEST] feature_a
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `rustdoc --test [..]mock_serde_codegen[..]`",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--verbose"),
|
|
|
|
execs().with_status(0).with_stderr_contains(
|
|
|
|
"\
|
2016-10-31 18:15:03 +00:00
|
|
|
[DOCTEST] foo
|
2018-03-14 15:17:44 +00:00
|
|
|
[RUNNING] `rustdoc --test [..]feature_a[..]`",
|
|
|
|
),
|
|
|
|
);
|
2016-10-31 18:15:03 +00:00
|
|
|
}
|
2016-10-06 22:32:15 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_release_ignore_panic() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-10-06 22:32:15 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
|
|
|
|
|
|
|
[profile.test]
|
|
|
|
panic = 'abort'
|
|
|
|
[profile.release]
|
|
|
|
panic = 'abort'
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate a;",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2016-10-06 22:32:15 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-10-06 22:32:15 +00:00
|
|
|
.file("a/src/lib.rs", "");
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = p.build();
|
2016-10-06 22:32:15 +00:00
|
|
|
println!("test");
|
|
|
|
assert_that(p.cargo("test").arg("-v"), execs().with_status(0));
|
|
|
|
println!("bench");
|
|
|
|
assert_that(p.cargo("bench").arg("-v"), execs().with_status(0));
|
|
|
|
}
|
2016-11-10 23:44:39 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_many_with_features() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-10 23:44:39 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
foo = []
|
|
|
|
|
|
|
|
[workspace]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-11-10 23:44:39 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2016-11-10 23:44:39 +00:00
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
2016-11-10 23:44:39 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
2018-03-16 17:03:27 +00:00
|
|
|
p.cargo("test -v -p a -p foo --features foo"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-11-10 23:44:39 +00:00
|
|
|
}
|
2016-10-20 20:14:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_all_workspace() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[workspace]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
#[test]
|
|
|
|
fn foo_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
#[test]
|
|
|
|
fn bar_test() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-10-20 20:14:54 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--all"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stdout_contains("test foo_test ... ok")
|
|
|
|
.with_stdout_contains("test bar_test ... ok"),
|
|
|
|
);
|
2016-10-20 20:14:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:44:15 +00:00
|
|
|
#[test]
|
|
|
|
fn test_all_exclude() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
fn main() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
#[test]
|
|
|
|
pub fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/Cargo.toml",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
[project]
|
|
|
|
name = "baz"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"baz/src/lib.rs",
|
|
|
|
r#"
|
2017-05-12 13:44:15 +00:00
|
|
|
#[test]
|
|
|
|
pub fn baz() {
|
|
|
|
assert!(false);
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-12 13:44:15 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--all").arg("--exclude").arg("baz"),
|
|
|
|
execs().with_status(0).with_stdout_contains(
|
|
|
|
"running 1 test
|
|
|
|
test bar ... ok",
|
|
|
|
),
|
|
|
|
);
|
2017-05-12 13:44:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 20:14:54 +00:00
|
|
|
#[test]
|
|
|
|
fn test_all_virtual_manifest() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
#[test]
|
|
|
|
fn a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
[project]
|
|
|
|
name = "b"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/src/lib.rs",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
#[test]
|
|
|
|
fn b() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-10-20 20:14:54 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--all"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stdout_contains("test a ... ok")
|
|
|
|
.with_stdout_contains("test b ... ok"),
|
|
|
|
);
|
2016-10-20 20:14:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 21:00:45 +00:00
|
|
|
#[test]
|
|
|
|
fn test_virtual_manifest_all_implied() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
#[test]
|
|
|
|
fn a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[project]
|
|
|
|
name = "b"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/src/lib.rs",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
#[test]
|
|
|
|
fn b() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stdout_contains("test a ... ok")
|
|
|
|
.with_stdout_contains("test b ... ok"),
|
|
|
|
);
|
2017-05-26 21:00:45 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 20:14:54 +00:00
|
|
|
#[test]
|
|
|
|
fn test_all_member_dependency_same_name() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
r#"
|
2016-10-20 20:14:54 +00:00
|
|
|
#[test]
|
|
|
|
fn a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-10-20 20:14:54 +00:00
|
|
|
|
|
|
|
Package::new("a", "0.1.0").publish();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--all"),
|
|
|
|
execs().with_status(0).with_stdout_contains("test a ... ok"),
|
|
|
|
);
|
2016-10-20 20:14:54 +00:00
|
|
|
}
|
2016-12-20 00:28:06 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_only_with_dev_dep() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-12-20 00:28:06 +00:00
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
b = { path = "b" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-12-20 00:28:06 +00:00
|
|
|
/// ```
|
|
|
|
/// extern crate b;
|
|
|
|
///
|
|
|
|
/// b::b();
|
|
|
|
/// ```
|
|
|
|
pub fn a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2016-12-20 00:28:06 +00:00
|
|
|
[project]
|
|
|
|
name = "b"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/src/lib.rs",
|
|
|
|
r#"
|
2016-12-20 00:28:06 +00:00
|
|
|
pub fn b() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-12-20 00:28:06 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--doc").arg("-v"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2016-12-20 00:28:06 +00:00
|
|
|
}
|
2017-02-16 16:46:39 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_many_targets() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/b.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_b() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/c.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_c() { panic!(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn example_a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/b.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn example_b() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/c.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
#[test] fn example_c() { panic!(); }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/a.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
#[test] fn test_a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/b.rs",
|
|
|
|
r#"
|
2017-02-16 16:46:39 +00:00
|
|
|
#[test] fn test_b() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/c.rs",
|
|
|
|
r#"
|
2017-02-17 07:04:30 +00:00
|
|
|
does not compile
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
p.cargo("test")
|
|
|
|
.arg("--verbose")
|
|
|
|
.arg("--bin")
|
|
|
|
.arg("a")
|
|
|
|
.arg("--bin")
|
|
|
|
.arg("b")
|
|
|
|
.arg("--example")
|
|
|
|
.arg("a")
|
|
|
|
.arg("--example")
|
|
|
|
.arg("b")
|
|
|
|
.arg("--test")
|
|
|
|
.arg("a")
|
|
|
|
.arg("--test")
|
|
|
|
.arg("b"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stdout_contains("test bin_a ... ok")
|
|
|
|
.with_stdout_contains("test bin_b ... ok")
|
|
|
|
.with_stdout_contains("test test_a ... ok")
|
|
|
|
.with_stdout_contains("test test_b ... ok")
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc --crate-name a examples[/]a.rs [..]`")
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc --crate-name b examples[/]b.rs [..]`"),
|
|
|
|
)
|
2017-02-16 16:46:39 +00:00
|
|
|
}
|
2017-02-16 16:04:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn doctest_and_registry() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-16 16:04:09 +00:00
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
b = { path = "b" }
|
|
|
|
c = { path = "c" }
|
|
|
|
|
|
|
|
[workspace]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-16 16:04:09 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2017-02-16 16:04:09 +00:00
|
|
|
[project]
|
|
|
|
name = "b"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/src/lib.rs",
|
|
|
|
"
|
2017-02-16 16:04:09 +00:00
|
|
|
/// ```
|
|
|
|
/// b::foo();
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"c/Cargo.toml",
|
|
|
|
r#"
|
2017-02-16 16:04:09 +00:00
|
|
|
[project]
|
|
|
|
name = "c"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
b = "0.1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("c/src/lib.rs", "")
|
|
|
|
.build();
|
2017-02-16 16:04:09 +00:00
|
|
|
|
|
|
|
Package::new("b", "0.1.0").publish();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--all").arg("-v"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-02-16 16:04:09 +00:00
|
|
|
}
|
2017-03-02 06:38:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cargo_test_env() {
|
2018-03-14 15:17:44 +00:00
|
|
|
let src = format!(
|
|
|
|
r#"
|
2017-03-02 06:38:54 +00:00
|
|
|
#![crate_type = "rlib"]
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn env_test() {{
|
|
|
|
use std::env;
|
|
|
|
println!("{{}}", env::var("{}").unwrap());
|
|
|
|
}}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
cargo::CARGO_ENV
|
|
|
|
);
|
2017-03-02 06:38:54 +00:00
|
|
|
|
|
|
|
let p = project("env_test")
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("env_test"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", &src)
|
|
|
|
.build();
|
2017-03-02 06:38:54 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let mut pr = p.cargo("test");
|
2017-03-02 06:38:54 +00:00
|
|
|
let cargo = cargo_exe().canonicalize().unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
pr.args(&["--lib", "--", "--nocapture"]),
|
|
|
|
execs().with_status(0).with_stdout_contains(format!(
|
|
|
|
"\
|
2017-03-02 06:38:54 +00:00
|
|
|
{}
|
|
|
|
test env_test ... ok
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
cargo.to_str().unwrap()
|
|
|
|
)),
|
|
|
|
);
|
2017-03-02 06:38:54 +00:00
|
|
|
}
|
2017-04-06 14:18:07 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_order() {
|
2018-03-14 15:17:44 +00:00
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-06 14:18:07 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-04-06 14:18:07 +00:00
|
|
|
#[test] fn test_lib() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/a.rs",
|
|
|
|
r#"
|
2017-04-06 14:18:07 +00:00
|
|
|
#[test] fn test_a() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/z.rs",
|
|
|
|
r#"
|
2017-04-06 14:18:07 +00:00
|
|
|
#[test] fn test_z() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-06 14:18:07 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--all"),
|
|
|
|
execs().with_status(0).with_stdout_contains(
|
|
|
|
"
|
2017-04-06 14:18:07 +00:00
|
|
|
running 1 test
|
|
|
|
test test_lib ... ok
|
|
|
|
|
2017-05-16 02:13:43 +00:00
|
|
|
test result: ok. [..]
|
2017-04-06 14:18:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test_a ... ok
|
|
|
|
|
2017-05-16 02:13:43 +00:00
|
|
|
test result: ok. [..]
|
2017-04-06 14:18:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test_z ... ok
|
|
|
|
|
2017-05-16 02:13:43 +00:00
|
|
|
test result: ok. [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2017-04-06 14:18:07 +00:00
|
|
|
}
|
2017-04-13 21:40:08 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cyclic_dev() {
|
2018-03-14 15:17:44 +00:00
|
|
|
let p = project("foo")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-04-13 21:40:08 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
foo = { path = "." }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-04-13 21:40:08 +00:00
|
|
|
#[test] fn test_lib() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
2017-04-13 21:40:08 +00:00
|
|
|
extern crate foo;
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-13 21:40:08 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("test").arg("--all"), execs().with_status(0));
|
2017-04-13 21:40:08 +00:00
|
|
|
}
|
2017-08-09 21:54:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn publish_a_crate_without_tests() {
|
|
|
|
Package::new("testless", "0.1.0")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "testless"
|
|
|
|
version = "0.1.0"
|
|
|
|
exclude = ["tests/*"]
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "a_test"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
|
|
|
|
// In real life, the package will have a test,
|
|
|
|
// which would be excluded from .crate file by the
|
|
|
|
// `exclude` field. Our test harness does not honor
|
|
|
|
// exclude though, so let's just not add the file!
|
|
|
|
// .file("tests/a_test.rs", "")
|
|
|
|
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-08-09 21:54:09 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
testless = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
2017-08-09 21:54:09 +00:00
|
|
|
|
|
|
|
assert_that(p.cargo("test"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--package").arg("testless"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-08-09 21:54:09 +00:00
|
|
|
}
|
2017-08-29 10:43:41 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn find_dependency_of_proc_macro_dependency_with_target() {
|
|
|
|
let workspace = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-08-29 10:43:41 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["root", "proc_macro_dep"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"root/Cargo.toml",
|
|
|
|
r#"
|
2017-08-29 10:43:41 +00:00
|
|
|
[project]
|
|
|
|
name = "root"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
proc_macro_dep = { path = "../proc_macro_dep" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"root/src/lib.rs",
|
|
|
|
r#"
|
2017-08-29 10:43:41 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macro_dep;
|
|
|
|
|
|
|
|
#[derive(Noop)]
|
|
|
|
pub struct X;
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"proc_macro_dep/Cargo.toml",
|
|
|
|
r#"
|
2017-08-29 10:43:41 +00:00
|
|
|
[project]
|
|
|
|
name = "proc_macro_dep"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
|
|
|
|
|
|
|
[dependencies]
|
2017-08-31 17:55:19 +00:00
|
|
|
bar = "^0.1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"proc_macro_dep/src/lib.rs",
|
|
|
|
r#"
|
2017-08-31 17:55:19 +00:00
|
|
|
extern crate bar;
|
2017-08-29 10:43:41 +00:00
|
|
|
extern crate proc_macro;
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
|
|
|
#[proc_macro_derive(Noop)]
|
|
|
|
pub fn noop(_input: TokenStream) -> TokenStream {
|
|
|
|
"".parse().unwrap()
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-08-31 17:55:19 +00:00
|
|
|
Package::new("foo", "0.1.0").publish();
|
|
|
|
Package::new("bar", "0.1.0")
|
|
|
|
.dep("foo", "0.1")
|
|
|
|
.file("src/lib.rs", "extern crate foo;")
|
|
|
|
.publish();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
workspace
|
|
|
|
.cargo("test")
|
|
|
|
.arg("--all")
|
|
|
|
.arg("--target")
|
|
|
|
.arg(rustc_host()),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-08-29 10:43:41 +00:00
|
|
|
}
|
2017-10-06 16:14:23 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hint_not_masked_by_doctest() {
|
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-10-06 16:14:23 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-10-06 16:14:23 +00:00
|
|
|
/// ```
|
|
|
|
/// assert_eq!(1, 1);
|
|
|
|
/// ```
|
|
|
|
pub fn this_works() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/integ.rs",
|
|
|
|
r#"
|
2017-10-06 16:14:23 +00:00
|
|
|
#[test]
|
|
|
|
fn this_fails() {
|
|
|
|
panic!();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("test").arg("--no-fail-fast"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stdout_contains("test this_fails ... FAILED")
|
|
|
|
.with_stdout_contains("[..]this_works (line [..]ok")
|
|
|
|
.with_stderr_contains(
|
|
|
|
"[ERROR] test failed, to rerun pass \
|
|
|
|
'--test integ'",
|
|
|
|
),
|
|
|
|
);
|
2017-10-06 16:14:23 +00:00
|
|
|
}
|
2018-02-26 00:51:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hint_workspace() {
|
2018-03-14 15:17:44 +00:00
|
|
|
let workspace = project("workspace")
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2018-02-26 00:51:48 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2018-02-26 00:51:48 +00:00
|
|
|
[project]
|
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"a/src/lib.rs",
|
|
|
|
r#"
|
2018-02-26 00:51:48 +00:00
|
|
|
#[test]
|
|
|
|
fn t1() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2018-02-26 00:51:48 +00:00
|
|
|
[project]
|
|
|
|
name = "b"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"b/src/lib.rs",
|
|
|
|
r#"
|
2018-02-26 00:51:48 +00:00
|
|
|
#[test]
|
|
|
|
fn t1() {assert!(false)}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-02-26 00:51:48 +00:00
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
workspace.cargo("test"),
|
|
|
|
execs()
|
|
|
|
.with_stderr_contains("[ERROR] test failed, to rerun pass '-p b --lib'")
|
|
|
|
.with_status(101),
|
|
|
|
);
|
2018-02-26 00:51:48 +00:00
|
|
|
}
|