cargo/tests/test.rs

2401 lines
59 KiB
Rust
Raw Normal View History

extern crate cargo;
extern crate cargotest;
extern crate hamcrest;
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;
use cargotest::{sleep_ms, is_nightly};
use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest};
use cargotest::support::paths::CargoPathExt;
use hamcrest::{assert_that, existing_file, is_not};
2014-06-26 22:14:31 +00:00
use cargo::util::process;
#[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"))
2014-06-26 22:14:31 +00:00
.file("src/foo.rs", r#"
fn hello() -> &'static str {
"hello"
}
pub fn main() {
println!("{}", hello())
}
#[test]
fn test_hello() {
assert_eq!(hello(), "hello")
}"#);
assert_that(p.cargo_process("build"), execs());
2014-06-26 22:14:31 +00:00
assert_that(&p.bin("foo"), existing_file());
2015-10-28 09:20:00 +00:00
assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
2014-06-26 22:14:31 +00:00
assert_that(p.cargo("test"),
2016-05-15 21:07:04 +00:00
execs().with_stderr(format!("\
[COMPILING] foo v0.5.0 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]", p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 1 test
test test_hello ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
2014-07-21 19:23:01 +00:00
#[test]
fn cargo_test_release() {
2015-03-24 20:43:30 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
authors = []
version = "0.1.0"
2015-03-24 20:43:30 +00:00
[dependencies]
bar = { path = "bar" }
"#)
.file("src/lib.rs", r#"
extern crate bar;
pub fn foo() { bar::bar(); }
2015-03-24 20:43:30 +00:00
#[test]
fn test() { foo(); }
2015-03-24 20:43:30 +00:00
"#)
.file("tests/test.rs", r#"
extern crate foo;
2015-03-24 20:43:30 +00:00
#[test]
fn test() { foo::foo(); }
2015-03-24 20:43:30 +00:00
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("bar/src/lib.rs", "pub fn bar() {}");
2015-03-24 20:43:30 +00:00
assert_that(p.cargo_process("test").arg("-v").arg("--release"),
2016-05-15 21:07:04 +00:00
execs().with_stderr(format!("\
[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 [..]
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] `[..]target[/]release[/]deps[/]foo-[..][EXE]`
[RUNNING] `[..]target[/]release[/]deps[/]test-[..][EXE]`
2016-05-15 21:07:04 +00:00
[DOCTEST] foo
[RUNNING] `rustdoc --test [..]lib.rs[..]`", dir = p.url()))
.with_stdout("
2015-03-24 20:43:30 +00:00
running 1 test
test test ... ok
2015-03-24 20:43:30 +00:00
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
2014-07-21 19:23:01 +00:00
#[test]
fn cargo_test_verbose() {
let p = project("foo")
2015-03-26 18:17:44 +00:00
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
fn main() {}
#[test] fn test_hello() {}
"#);
assert_that(p.cargo_process("test").arg("-v").arg("hello"),
2016-05-15 21:07:04 +00:00
execs().with_stderr(format!("\
[COMPILING] foo v0.5.0 ({url})
[RUNNING] `rustc src[/]foo.rs [..]`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] `[..]target[/]debug[/]deps[/]foo-[..][EXE] hello`", url = p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 1 test
test test_hello ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
#[test]
fn many_similar_names() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "
pub fn foo() {}
#[test] fn lib_test() {}
")
.file("src/main.rs", "
extern crate foo;
fn main() {}
#[test] fn bin_test() { foo::foo() }
")
.file("tests/foo.rs", r#"
extern crate foo;
#[test] fn test_test() { foo::foo() }
"#);
let output = p.cargo_process("test").arg("-v").exec_with_output().unwrap();
let output = str::from_utf8(&output.stdout).unwrap();
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);
}
#[test]
fn cargo_test_failing_test() {
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"))
2014-07-21 19:23:01 +00:00
.file("src/foo.rs", r#"
fn hello() -> &'static str {
"hello"
}
pub fn main() {
println!("{}", hello())
}
#[test]
fn test_hello() {
assert_eq!(hello(), "nope")
}"#);
assert_that(p.cargo_process("build"), execs());
2014-07-21 19:23:01 +00:00
assert_that(&p.bin("foo"), existing_file());
2015-10-28 09:20:00 +00:00
assert_that(process(&p.bin("foo")),
execs().with_stdout("hello\n"));
2014-07-21 19:23:01 +00:00
assert_that(p.cargo("test"),
2016-05-18 23:41:30 +00:00
execs().with_stderr(format!("\
[COMPILING] foo v0.5.0 ({url})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
2016-05-19 00:51:07 +00:00
[ERROR] test failed", url = p.url()))
2016-05-18 23:41:30 +00:00
.with_stdout_contains("
running 1 test
test test_hello ... FAILED
failures:
---- test_hello stdout ----
2014-12-21 18:45:39 +00:00
<tab>thread 'test_hello' panicked at 'assertion failed: \
`(left == right)` (left: \
`\"hello\"`, right: `\"nope\"`)', src[/]foo.rs:12
2016-05-18 23:41:30 +00:00
")
.with_stdout_contains("\
failures:
test_hello
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
")
2016-05-18 23:41:30 +00:00
.with_status(101));
}
#[test]
fn test_with_lib_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[[bin]]
name = "baz"
path = "src/main.rs"
"#)
.file("src/lib.rs", r#"
///
/// ```rust
/// extern crate foo;
/// fn main() {
2015-01-13 16:41:04 +00:00
/// println!("{:?}", foo::foo());
/// }
/// ```
///
2014-07-10 19:08:13 +00:00
pub fn foo(){}
#[test] fn lib_test() {}
"#)
.file("src/main.rs", "
extern crate foo;
2014-07-10 19:08:13 +00:00
fn main() {}
2014-07-10 19:08:13 +00:00
#[test]
fn bin_test() {}
");
assert_that(p.cargo_process("test"),
2016-05-15 21:07:04 +00:00
execs().with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]baz-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] foo", p.url()))
.with_stdout("
2014-07-10 19:08:13 +00:00
running 1 test
test bin_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-07-10 19:08:13 +00:00
running 1 test
test lib_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-07-10 19:39:05 +00:00
2014-07-10 19:08:13 +00:00
running 1 test
test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"))
}
#[test]
fn test_with_deep_lib_dep() {
let p = project("bar")
.file("Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies.foo]
path = "../foo"
"#)
.file("src/lib.rs", "
extern crate foo;
/// ```
/// bar::bar();
/// ```
pub fn bar() {}
#[test]
fn bar_test() {
foo::foo();
}
");
let p2 = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "
pub fn foo() {}
#[test]
fn foo_test() {}
");
p2.build();
assert_that(p.cargo_process("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ([..])
[COMPILING] bar v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[..]
2016-05-15 21:07:04 +00:00
[DOCTEST] bar", dir = p.url()))
.with_stdout("
running 1 test
test bar_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-12-31 20:02:18 +00:00
running 1 test
test bar_0 ... ok
2014-12-31 20:02:18 +00:00
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
2014-07-11 00:08:19 +00:00
#[test]
fn external_test_explicit() {
2014-07-11 00:08:19 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[[test]]
name = "test"
path = "src/test.rs"
"#)
.file("src/lib.rs", r#"
pub fn get_hello() -> &'static str { "Hello" }
#[test]
fn internal_test() {}
"#)
.file("src/test.rs", r#"
extern crate foo;
#[test]
fn external_test() { assert_eq!(foo::get_hello(), "Hello") }
"#);
assert_that(p.cargo_process("test"),
2016-05-15 21:07:04 +00:00
execs().with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] foo", p.url()))
.with_stdout("
2014-07-11 00:08:19 +00:00
running 1 test
test internal_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-07-11 00:08:19 +00:00
running 1 test
test external_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-07-11 00:08:19 +00:00
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"))
}
2014-07-11 00:08:19 +00:00
#[test]
fn external_test_implicit() {
2014-07-11 00:08:19 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", r#"
pub fn get_hello() -> &'static str { "Hello" }
#[test]
fn internal_test() {}
"#)
.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") }
"#);
assert_that(p.cargo_process("test"),
2016-05-15 21:07:04 +00:00
execs().with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]external-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] foo", p.url()))
.with_stdout("
2014-07-11 00:08:19 +00:00
running 1 test
test external_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-07-11 00:08:19 +00:00
running 1 test
test internal_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-07-11 00:08:19 +00:00
running 0 tests
2014-07-11 00:08:19 +00:00
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2014-07-11 00:08:19 +00:00
2016-05-15 21:07:04 +00:00
"))
}
#[test]
fn dont_run_examples() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
"#)
.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'"); }
"#);
assert_that(p.cargo_process("test"),
execs().with_status(0));
}
#[test]
fn pass_through_command_line() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "
#[test] fn foo() {}
#[test] fn bar() {}
");
assert_that(p.cargo_process("test").arg("bar"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] foo", dir = p.url()))
.with_stdout("
running 1 test
test bar ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
assert_that(p.cargo("test").arg("foo"),
execs().with_status(0)
.with_stderr("\
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
[DOCTEST] foo")
.with_stdout("
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"));
}
// Regression test for running cargo-test twice with
// tests in an rlib
#[test]
fn cargo_test_twice() {
let p = project("test_twice")
2015-03-26 18:17:44 +00:00
.file("Cargo.toml", &basic_lib_manifest("test_twice"))
.file("src/test_twice.rs", r#"
#![crate_type = "rlib"]
#[test]
fn dummy_test() { }
"#);
p.cargo_process("build");
2015-03-22 23:58:11 +00:00
for _ in 0..2 {
assert_that(p.cargo("test"),
execs().with_status(0));
}
}
#[test]
fn lib_bin_same_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
2014-08-14 06:08:02 +00:00
[lib]
name = "foo"
[[bin]]
name = "foo"
"#)
.file("src/lib.rs", "
#[test] fn lib_test() {}
")
.file("src/main.rs", "
extern crate foo;
#[test]
fn bin_test() {}
");
assert_that(p.cargo_process("test"),
2016-05-15 21:07:04 +00:00
execs().with_stderr(format!("\
[COMPILING] foo v0.0.1 ({})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] foo", p.url()))
.with_stdout("
running 1 test
test [..] ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test [..] ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"))
}
#[test]
fn lib_with_standard_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "syntax"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "
/// ```
/// syntax::foo();
/// ```
pub fn foo() {}
#[test]
fn foo_test() {}
")
.file("tests/test.rs", "
extern crate syntax;
#[test]
fn test() { syntax::foo() }
");
assert_that(p.cargo_process("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] syntax v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]syntax-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] syntax", dir = p.url()))
.with_stdout("
running 1 test
test foo_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2014-12-31 20:02:18 +00:00
running 1 test
test foo_0 ... ok
2014-12-31 20:02:18 +00:00
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
#[test]
fn lib_with_standard_name2() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "syntax"
version = "0.0.1"
authors = []
2014-08-14 06:08:02 +00:00
[lib]
name = "syntax"
test = false
doctest = false
"#)
.file("src/lib.rs", "
pub fn foo() {}
")
.file("src/main.rs", "
extern crate syntax;
fn main() {}
#[test]
fn test() { syntax::foo() }
");
assert_that(p.cargo_process("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] syntax v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]syntax-[..][EXE]", dir = p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 1 test
test test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
#[test]
fn lib_without_name() {
2015-06-21 10:34:42 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "syntax"
version = "0.0.1"
authors = []
[lib]
test = false
doctest = false
"#)
.file("src/lib.rs", "
pub fn foo() {}
")
.file("src/main.rs", "
extern crate syntax;
fn main() {}
#[test]
fn test() { syntax::foo() }
");
assert_that(p.cargo_process("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] syntax v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]syntax-[..][EXE]", dir = p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
2015-06-21 10:34:42 +00:00
running 1 test
test test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
2015-06-21 10:34:42 +00:00
#[test]
fn bin_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "syntax"
version = "0.0.1"
authors = []
[lib]
test = false
doctest = false
[[bin]]
path = "src/main.rs"
"#)
.file("src/lib.rs", "
pub fn foo() {}
")
.file("src/main.rs", "
extern crate syntax;
fn main() {}
#[test]
fn test() { syntax::foo() }
");
assert_that(p.cargo_process("test"),
execs().with_status(101)
2016-05-12 17:06:36 +00:00
.with_stderr("\
[ERROR] failed to parse manifest at `[..]`
Caused by:
2016-05-12 17:06:36 +00:00
binary target bin.name is required"));
}
#[test]
fn bench_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "syntax"
version = "0.0.1"
authors = []
[lib]
test = false
doctest = false
[[bench]]
path = "src/bench.rs"
"#)
.file("src/lib.rs", "
pub fn foo() {}
")
.file("src/main.rs", "
extern crate syntax;
fn main() {}
#[test]
fn test() { syntax::foo() }
")
.file("src/bench.rs", "
#![feature(test)]
extern crate syntax;
extern crate test;
#[bench]
fn external_bench(_b: &mut test::Bencher) {}
");
assert_that(p.cargo_process("test"),
execs().with_status(101)
2016-05-12 17:06:36 +00:00
.with_stderr("\
[ERROR] failed to parse manifest at `[..]`
Caused by:
2016-05-12 17:06:36 +00:00
bench target bench.name is required"));
}
#[test]
fn test_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "syntax"
version = "0.0.1"
authors = []
[lib]
test = false
doctest = false
[[test]]
path = "src/test.rs"
"#)
.file("src/lib.rs", r#"
pub fn foo() {}
pub fn get_hello() -> &'static str { "Hello" }
"#)
.file("src/main.rs", "
extern crate syntax;
fn main() {}
#[test]
fn test() { syntax::foo() }
")
.file("src/test.rs", r#"
extern crate syntax;
#[test]
fn external_test() { assert_eq!(syntax::get_hello(), "Hello") }
"#);
assert_that(p.cargo_process("test"),
execs().with_status(101)
2016-05-12 17:06:36 +00:00
.with_stderr("\
[ERROR] failed to parse manifest at `[..]`
Caused by:
2016-05-12 17:06:36 +00:00
test target test.name is required"));
}
#[test]
fn example_without_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "syntax"
version = "0.0.1"
authors = []
[lib]
test = false
doctest = false
[[example]]
path = "examples/example.rs"
"#)
.file("src/lib.rs", "
pub fn foo() {}
")
.file("src/main.rs", "
extern crate syntax;
fn main() {}
#[test]
fn test() { syntax::foo() }
")
.file("examples/example.rs", r#"
extern crate syntax;
fn main() {
println!("example1");
}
"#);
assert_that(p.cargo_process("test"),
execs().with_status(101)
2016-05-12 17:06:36 +00:00
.with_stderr("\
[ERROR] failed to parse manifest at `[..]`
Caused by:
2016-05-12 17:06:36 +00:00
example target example.name is required"));
}
#[test]
fn bin_there_for_integration() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/main.rs", "
fn main() { std::process::exit(101); }
#[test] fn main_test() {}
")
.file("tests/foo.rs", r#"
2015-03-26 18:17:44 +00:00
use std::process::Command;
#[test]
fn test_test() {
let status = Command::new("target/debug/foo").status().unwrap();
2015-03-26 18:17:44 +00:00
assert_eq!(status.code(), Some(101));
}
"#);
2015-03-29 06:30:39 +00:00
let output = p.cargo_process("test").arg("-v").exec_with_output().unwrap();
let output = str::from_utf8(&output.stdout).unwrap();
assert!(output.contains("main_test ... ok"), "no main_test\n{}", output);
assert!(output.contains("test_test ... ok"), "no test_test\n{}", output);
}
#[test]
fn test_dylib() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
2014-08-14 06:08:02 +00:00
[lib]
name = "foo"
crate_type = ["dylib"]
[dependencies.bar]
path = "bar"
"#)
2014-08-18 01:34:50 +00:00
.file("src/lib.rs", r#"
2015-03-30 19:30:50 +00:00
extern crate bar as the_bar;
2014-08-18 01:34:50 +00:00
pub fn bar() { the_bar::baz(); }
#[test]
fn foo() { bar(); }
2014-08-18 01:34:50 +00:00
"#)
.file("tests/test.rs", r#"
2015-03-30 19:30:50 +00:00
extern crate foo as the_foo;
#[test]
2014-08-18 01:34:50 +00:00
fn foo() { the_foo::bar(); }
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
2014-08-14 06:08:02 +00:00
[lib]
name = "bar"
crate_type = ["dylib"]
"#)
.file("bar/src/lib.rs", "
pub fn baz() {}
");
assert_that(p.cargo_process("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] bar v0.0.1 ({dir}/bar)
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]", dir = p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
p.root().move_into_the_past();
assert_that(p.cargo("test"),
execs().with_status(0)
.with_stderr("\
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]test-[..][EXE]")
.with_stdout("
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn test_twice_with_build_cmd() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
build = "build.rs"
"#)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "
#[test]
fn foo() {}
");
assert_that(p.cargo_process("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] foo", dir = p.url()))
.with_stdout("
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
assert_that(p.cargo("test"),
execs().with_status(0)
.with_stderr("\
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
[DOCTEST] foo")
.with_stdout("
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn test_then_build() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "
#[test]
fn foo() {}
");
assert_that(p.cargo_process("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] foo", dir = p.url()))
.with_stdout("
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
assert_that(p.cargo("build"),
execs().with_status(0)
.with_stdout(""));
}
#[test]
fn test_no_run() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "
#[test]
2014-10-30 01:59:06 +00:00
fn foo() { panic!() }
");
assert_that(p.cargo_process("test").arg("--no-run"),
execs().with_status(0)
2016-05-14 21:44:18 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
",
2015-03-26 18:17:44 +00:00
dir = p.url())));
}
#[test]
fn test_run_specific_bin_target() {
let prj = project("foo")
.file("Cargo.toml" , r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[[bin]]
name="bin1"
path="src/bin1.rs"
[[bin]]
name="bin2"
path="src/bin2.rs"
"#)
.file("src/bin1.rs", "#[test] fn test1() { }")
.file("src/bin2.rs", "#[test] fn test2() { }");
2016-05-15 21:07:04 +00:00
assert_that(prj.cargo_process("test").arg("--bin").arg("bin2"),
execs().with_status(0)
.with_stderr(format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]bin2-[..][EXE]", dir = prj.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 1 test
test test2 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
#[test]
fn test_run_specific_test_target() {
let prj = project("foo")
.file("Cargo.toml" , r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.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() { }")
.file("tests/b.rs", "#[test] fn test_b() { }");
2016-05-15 21:07:04 +00:00
assert_that(prj.cargo_process("test").arg("--test").arg("b"),
execs().with_status(0)
.with_stderr(format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]b-[..][EXE]", dir = prj.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 1 test
test test_b ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
#[test]
fn test_no_harness() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[[bin]]
name = "foo"
test = false
[[test]]
name = "bar"
path = "foo.rs"
harness = false
"#)
.file("src/main.rs", "fn main() {}")
.file("foo.rs", "fn main() {}");
assert_that(p.cargo_process("test").arg("--").arg("--nocapture"),
execs().with_status(0)
2016-05-14 21:44:18 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]bar-[..][EXE]
",
2015-03-26 18:17:44 +00:00
dir = p.url())));
}
#[test]
fn selective_testing() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.d1]
path = "d1"
[dependencies.d2]
path = "d2"
[lib]
name = "foo"
doctest = false
"#)
.file("src/lib.rs", "")
.file("d1/Cargo.toml", r#"
[package]
name = "d1"
version = "0.0.1"
authors = []
[lib]
name = "d1"
doctest = false
"#)
.file("d1/src/lib.rs", "")
.file("d1/src/main.rs", "extern crate d1; fn main() {}")
.file("d2/Cargo.toml", r#"
[package]
name = "d2"
version = "0.0.1"
authors = []
[lib]
name = "d2"
doctest = false
"#)
.file("d2/src/lib.rs", "")
.file("d2/src/main.rs", "extern crate d2; fn main() {}");
p.build();
println!("d1");
assert_that(p.cargo("test").arg("-p").arg("d1"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] d1 v0.0.1 ({dir}/d1)
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]d1-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]d1-[..][EXE]", dir = p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
println!("d2");
assert_that(p.cargo("test").arg("-p").arg("d2"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] d2 v0.0.1 ({dir}/d2)
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]d2-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]d2-[..][EXE]", dir = p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
println!("whole");
assert_that(p.cargo("test"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ({dir})
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]", dir = p.url()))
2016-05-15 21:07:04 +00:00
.with_stdout("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
#[test]
fn almost_cyclic_but_not_quite() {
let p = project("a")
.file("Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
[dev-dependencies.b]
path = "b"
[dev-dependencies.c]
path = "c"
"#)
.file("src/lib.rs", r#"
#[cfg(test)] extern crate b;
#[cfg(test)] extern crate c;
"#)
.file("b/Cargo.toml", r#"
[package]
name = "b"
version = "0.0.1"
authors = []
[dependencies.a]
path = ".."
"#)
.file("b/src/lib.rs", r#"
extern crate a;
"#)
.file("c/Cargo.toml", r#"
[package]
name = "c"
version = "0.0.1"
authors = []
"#)
.file("c/src/lib.rs", "");
assert_that(p.cargo_process("build"), execs().with_status(0));
assert_that(p.cargo("test"),
execs().with_status(0));
}
#[test]
fn build_then_selective_test() {
let p = project("a")
.file("Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
[dependencies.b]
path = "b"
"#)
.file("src/lib.rs", "extern crate b;")
.file("src/main.rs", "extern crate b; extern crate a; fn main() {}")
.file("b/Cargo.toml", r#"
[package]
name = "b"
version = "0.0.1"
authors = []
"#)
.file("b/src/lib.rs", "");
assert_that(p.cargo_process("build"), execs().with_status(0));
p.root().move_into_the_past();
assert_that(p.cargo("test").arg("-p").arg("b"),
execs().with_status(0));
}
#[test]
fn example_dev_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dev-dependencies.bar]
path = "bar"
"#)
.file("src/lib.rs", r#"
"#)
.file("examples/e1.rs", r#"
extern crate bar;
fn main() { }
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("bar/src/lib.rs", r#"
// 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!())}) );
pub fn bar() {
f8!();
}
"#);
assert_that(p.cargo_process("test"),
execs().with_status(0));
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
assert_that(p.cargo("run")
.arg("--example").arg("e1").arg("--release").arg("-v"),
execs().with_status(0));
}
#[test]
fn selective_testing_with_docs() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.d1]
path = "d1"
"#)
.file("src/lib.rs", r#"
/// ```
/// not valid rust
/// ```
pub fn foo() {}
"#)
.file("d1/Cargo.toml", r#"
[package]
name = "d1"
version = "0.0.1"
authors = []
[lib]
name = "d1"
path = "d1.rs"
"#)
.file("d1/d1.rs", "");
p.build();
assert_that(p.cargo("test").arg("-p").arg("d1"),
execs().with_status(0)
2016-05-15 21:07:04 +00:00
.with_stderr(&format!("\
[COMPILING] d1 v0.0.1 ({dir}/d1)
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]d1[..][EXE]
2016-05-15 21:07:04 +00:00
[DOCTEST] d1", dir = p.url()))
.with_stdout("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-15 21:07:04 +00:00
"));
}
#[test]
fn example_bin_same_name() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#)
.file("examples/foo.rs", r#"fn main() { println!("example"); }"#);
assert_that(p.cargo_process("test").arg("--no-run").arg("-v"),
execs().with_status(0)
2016-05-14 21:44:18 +00:00
.with_stderr(&format!("\
[COMPILING] foo v0.0.1 ({dir})
[RUNNING] `rustc [..]`
[RUNNING] `rustc [..]`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
", dir = p.url())));
assert_that(&p.bin("foo"), is_not(existing_file()));
assert_that(&p.bin("examples/foo"), existing_file());
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("\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] [..]")
.with_stdout("\
bin
2016-05-12 17:06:36 +00:00
"));
assert_that(&p.bin("foo"), existing_file());
}
#[test]
fn test_with_example_twice() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#)
.file("examples/foo.rs", r#"fn main() { println!("example"); }"#);
println!("first");
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
assert_that(&p.bin("examples/foo"), existing_file());
println!("second");
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
assert_that(&p.bin("examples/foo"), existing_file());
}
#[test]
fn example_with_dev_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[lib]
name = "foo"
test = false
doctest = false
[dev-dependencies.a]
path = "a"
"#)
.file("src/lib.rs", "")
.file("examples/ex.rs", "extern crate a; fn main() {}")
.file("a/Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
"#)
.file("a/src/lib.rs", "");
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0)
2016-05-14 21:15:22 +00:00
.with_stderr("\
[..]
[..]
[..]
[..]
[RUNNING] `rustc [..] --crate-name ex [..] --extern a=[..]`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn bin_is_preserved() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "")
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());
println!("testing");
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
assert_that(&p.bin("foo"), existing_file());
}
#[test]
fn bad_example() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "");
assert_that(p.cargo_process("run").arg("--example").arg("foo"),
2016-05-12 17:06:36 +00:00
execs().with_status(101).with_stderr("\
[ERROR] no example target named `foo`
2016-05-12 17:06:36 +00:00
"));
assert_that(p.cargo_process("run").arg("--bin").arg("foo"),
2016-05-12 17:06:36 +00:00
execs().with_status(101).with_stderr("\
[ERROR] no bin target named `foo`
2016-05-12 17:06:36 +00:00
"));
}
2015-02-09 19:14:27 +00:00
#[test]
fn doctest_feature() {
2015-02-09 19:14:27 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[features]
bar = []
"#)
.file("src/lib.rs", r#"
/// ```rust
/// assert_eq!(foo::foo(), 1);
/// ```
#[cfg(feature = "bar")]
pub fn foo() -> i32 { 1 }
"#);
assert_that(p.cargo_process("test").arg("--features").arg("bar"),
execs().with_status(0)
.with_stderr("\
[COMPILING] foo [..]
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo[..][EXE]
[DOCTEST] foo")
.with_stdout("
2015-02-09 19:14:27 +00:00
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"))
}
#[test]
fn dashes_to_underscores() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo-bar"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", r#"
/// ```
/// assert_eq!(foo_bar::foo(), 1);
/// ```
pub fn foo() -> i32 { 1 }
"#);
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
}
#[test]
fn doctest_dev_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dev-dependencies]
b = { path = "b" }
"#)
.file("src/lib.rs", r#"
/// ```
/// extern crate b;
/// ```
pub fn foo() {}
"#)
.file("b/Cargo.toml", r#"
[package]
name = "b"
version = "0.0.1"
authors = []
"#)
.file("b/src/lib.rs", "");
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
}
#[test]
fn filter_no_doc_tests() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", r#"
/// ```
/// extern crate b;
/// ```
pub fn foo() {}
"#)
.file("tests/foo.rs", "");
assert_that(p.cargo_process("test").arg("--test=foo"),
execs().with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo[..][EXE]")
.with_stdout("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn dylib_doctest() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[lib]
name = "foo"
crate-type = ["rlib", "dylib"]
test = false
"#)
.file("src/lib.rs", r#"
/// ```
/// foo::foo();
/// ```
pub fn foo() {}
"#);
assert_that(p.cargo_process("test"),
execs().with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[DOCTEST] foo")
.with_stdout("
running 1 test
test foo_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn dylib_doctest2() {
// can't doctest dylibs as they're statically linked together
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[lib]
name = "foo"
crate-type = ["dylib"]
test = false
"#)
.file("src/lib.rs", r#"
/// ```
/// foo::foo();
/// ```
pub fn foo() {}
"#);
assert_that(p.cargo_process("test"),
execs().with_stdout(""));
}
#[test]
fn cyclic_dev_dep_doc_test() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dev-dependencies]
bar = { path = "bar" }
"#)
.file("src/lib.rs", r#"
//! ```
//! extern crate bar;
//! ```
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
foo = { path = ".." }
"#)
.file("bar/src/lib.rs", r#"
extern crate foo;
"#);
assert_that(p.cargo_process("test"),
execs().with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[COMPILING] bar v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo[..][EXE]
[DOCTEST] foo")
.with_stdout("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test _0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"))
}
#[test]
fn dev_dep_with_build_script() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dev-dependencies]
bar = { path = "bar" }
"#)
.file("src/lib.rs", "")
.file("examples/foo.rs", "fn main() {}")
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
build = "build.rs"
"#)
.file("bar/src/lib.rs", "")
.file("bar/build.rs", "fn main() {}");
assert_that(p.cargo_process("test"),
execs().with_status(0));
}
2015-08-28 02:37:45 +00:00
#[test]
fn no_fail_fast() {
2015-08-28 02:37:45 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", r#"
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
}
"#)
.file("tests/test_add_one.rs", r#"
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);
}
"#)
.file("tests/test_sub_one.rs", r#"
extern crate foo;
use foo::*;
#[test]
fn sub_one_test() {
assert_eq!(sub_one(1), 0);
}
"#);
assert_that(p.cargo_process("test").arg("--no-fail-fast"),
execs().with_status(101)
2016-05-19 00:02:41 +00:00
.with_stderr_contains("\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target[/]debug[/]deps[/]foo-[..][EXE]
[RUNNING] target[/]debug[/]deps[/]test_add_one-[..][EXE]")
2016-05-19 00:02:41 +00:00
.with_stdout_contains("
2015-08-28 02:37:45 +00:00
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
")
2016-05-19 00:02:41 +00:00
.with_stderr_contains("\
[RUNNING] target[/]debug[/]deps[/]test_sub_one-[..][EXE]
2016-05-19 00:02:41 +00:00
[DOCTEST] foo")
2016-05-12 17:06:36 +00:00
.with_stdout_contains("\
2015-08-28 02:37:45 +00:00
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured
running 1 test
test sub_one_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
running 1 test
test sub_one_0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
"))
}
#[test]
fn test_multiple_packages() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.d1]
path = "d1"
[dependencies.d2]
path = "d2"
[lib]
name = "foo"
doctest = false
"#)
.file("src/lib.rs", "")
.file("d1/Cargo.toml", r#"
[package]
name = "d1"
version = "0.0.1"
authors = []
[lib]
name = "d1"
doctest = false
"#)
.file("d1/src/lib.rs", "")
.file("d2/Cargo.toml", r#"
[package]
name = "d2"
version = "0.0.1"
authors = []
[lib]
name = "d2"
doctest = false
"#)
.file("d2/src/lib.rs", "");
p.build();
assert_that(p.cargo("test").arg("-p").arg("d1").arg("-p").arg("d2"),
execs().with_status(0)
2016-05-19 00:02:41 +00:00
.with_stderr_contains("\
[RUNNING] target[/]debug[/]deps[/]d1-[..][EXE]")
2016-05-19 00:02:41 +00:00
.with_stdout_contains("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +00:00
")
2016-05-19 00:02:41 +00:00
.with_stderr_contains("\
[RUNNING] target[/]debug[/]deps[/]d2-[..][EXE]")
2016-05-19 00:02:41 +00:00
.with_stdout_contains("
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
2016-05-12 17:06:36 +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
#[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")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", "")
.file("src/main.rs", "fn main() {}")
.file("tests/foo.rs", "");
p.build();
assert_that(p.cargo("test").arg("-v"),
execs().with_status(0));
sleep_ms(1000);
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::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)
2016-05-14 21:15:22 +00:00
.with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[RUNNING] `rustc src[/]main.rs [..]`
[RUNNING] `rustc src[/]main.rs [..]`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn selective_test_wonky_profile() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[profile.release]
opt-level = 2
[dependencies]
a = { path = "a" }
"#)
.file("src/lib.rs", "")
.file("a/Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
"#)
.file("a/src/lib.rs", "");
p.build();
assert_that(p.cargo("test").arg("-v").arg("--no-run").arg("--release")
.arg("-p").arg("foo").arg("-p").arg("a"),
execs().with_status(0));
}
#[test]
fn selective_test_optional_dep() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
a = { path = "a", optional = true }
"#)
.file("src/lib.rs", "")
.file("a/Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
"#)
.file("a/src/lib.rs", "");
p.build();
assert_that(p.cargo("test").arg("-v").arg("--no-run")
.arg("--features").arg("a").arg("-p").arg("a"),
2016-05-14 21:15:22 +00:00
execs().with_status(0).with_stderr("\
[COMPILING] a v0.0.1 ([..])
[RUNNING] `rustc a[/]src[/]lib.rs [..]`
[RUNNING] `rustc a[/]src[/]lib.rs [..]`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn only_test_docs() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", r#"
#[test]
fn foo() {
let a: u32 = "hello";
}
/// ```
/// println!("ok");
/// ```
pub fn bar() {
}
"#)
.file("tests/foo.rs", "this is not rust");
p.build();
assert_that(p.cargo("test").arg("--doc"),
2016-05-19 00:51:07 +00:00
execs().with_status(0)
2016-05-30 22:41:36 +00:00
.with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
2016-05-30 22:41:36 +00:00
[DOCTEST] foo")
2016-05-19 00:51:07 +00:00
.with_stdout("
running 1 test
test bar_0 ... ok
test result: ok.[..]
2016-05-16 19:35:01 +00:00
2016-05-19 00:51:07 +00:00
"));
}
#[test]
fn test_panic_abort_with_dep() {
if !is_nightly() {
return
}
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
bar = { path = "bar" }
[profile.dev]
panic = 'abort'
"#)
.file("src/lib.rs", r#"
extern crate bar;
#[test]
fn foo() {}
"#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("bar/src/lib.rs", "");
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0));
}
#[test]
fn cfg_test_even_with_no_harness() {
if !is_nightly() {
return
}
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[lib]
harness = false
doctest = false
"#)
.file("src/lib.rs", r#"
#[cfg(test)]
fn main() {
println!("hello!");
}
"#);
assert_that(p.cargo_process("test").arg("-v"),
execs().with_status(0)
.with_stdout("hello!\n")
.with_stderr("\
[COMPILING] foo v0.0.1 ([..])
[RUNNING] `rustc [..]`
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]
[RUNNING] `[..]`
"));
}
#[test]
fn panic_abort_multiple() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
a = { path = "a" }
[profile.release]
panic = 'abort'
"#)
.file("src/lib.rs", "extern crate a;")
.file("a/Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
"#)
.file("a/src/lib.rs", "");
assert_that(p.cargo_process("test")
.arg("--release").arg("-v")
.arg("-p").arg("foo")
.arg("-p").arg("a"),
execs().with_status(0));
}
#[test]
fn pass_correct_cfgs_flags_to_rustdoc() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
[features]
default = ["feature_a/default"]
nightly = ["feature_a/nightly"]
[dependencies.feature_a]
path = "libs/feature_a"
default-features = false
"#)
.file("src/lib.rs", r#"
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert!(true);
}
}
"#)
.file("libs/feature_a/Cargo.toml", r#"
[package]
name = "feature_a"
version = "0.1.0"
authors = []
[features]
default = ["serde_codegen"]
nightly = ["serde_derive"]
[dependencies]
serde_derive = { version = "0.8", optional = true }
[build-dependencies]
serde_codegen = { version = "0.8", optional = true }
"#)
.file("libs/feature_a/src/lib.rs", r#"
#[cfg(feature = "serde_derive")]
const MSG: &'static str = "This is safe";
#[cfg(feature = "serde_codegen")]
const MSG: &'static str = "This is risky";
pub fn get() -> &'static str {
MSG
}
"#);
assert_that(p.cargo_process("test")
.arg("--package").arg("feature_a")
.arg("--verbose"),
execs().with_status(0)
.with_stderr_contains("\
[DOCTEST] feature_a
[RUNNING] `rustdoc --test [..]serde_codegen[..]`"));
assert_that(p.cargo_process("test")
.arg("--verbose"),
execs().with_status(0)
.with_stderr_contains("\
[DOCTEST] foo
[RUNNING] `rustdoc --test [..]feature_a[..]`"));
}
#[test]
fn test_release_ignore_panic() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
a = { path = "a" }
[profile.test]
panic = 'abort'
[profile.release]
panic = 'abort'
"#)
.file("src/lib.rs", "extern crate a;")
.file("a/Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
"#)
.file("a/src/lib.rs", "");
p.build();
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));
}
#[test]
fn test_many_with_features() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
a = { path = "a" }
[features]
foo = []
[workspace]
"#)
.file("src/lib.rs", "")
.file("a/Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
"#)
.file("a/src/lib.rs", "");
p.build();
assert_that(p.cargo("test").arg("-v")
.arg("-p").arg("a")
.arg("-p").arg("foo")
.arg("--features").arg("foo"),
execs().with_status(0));
}