2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo test` command.
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::paths::CargoPathExt;
|
|
|
|
use cargo_test_support::registry::Package;
|
2019-09-12 19:52:46 +00:00
|
|
|
use cargo_test_support::{
|
|
|
|
basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, project,
|
|
|
|
};
|
2021-09-09 06:10:33 +00:00
|
|
|
use cargo_test_support::{cross_compile, paths};
|
2022-08-28 00:45:11 +00:00
|
|
|
use cargo_test_support::{rustc_host, rustc_host_env, sleep_ms};
|
2019-10-23 15:14:40 +00:00
|
|
|
use std::fs;
|
2014-06-26 22:14:31 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_test_simple() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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")
|
2020-09-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-06-26 22:14:31 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2014-06-26 22:14:31 +00:00
|
|
|
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(&p.bin("foo")).with_stdout("hello\n").run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test_hello ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_test_release() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
authors = []
|
|
|
|
version = "0.1.0"
|
2015-03-24 20:43:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate bar;
|
|
|
|
pub fn foo() { bar::bar(); }
|
2015-03-24 20:43:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn test() { foo(); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/test.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
2015-03-24 20:43:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn test() { foo::foo(); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v --release")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] bar v0.0.1 ([CWD]/bar)
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] [..] -C opt-level=3 [..]
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.1.0 ([CWD])
|
2016-05-11 16:55:43 +00:00
|
|
|
[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 [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `[..]target/release/deps/foo-[..][EXE]`
|
|
|
|
[RUNNING] `[..]target/release/deps/test-[..][EXE]`
|
2016-05-15 21:07:04 +00:00
|
|
|
[DOCTEST] foo
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--test [..]lib.rs[..]`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test test ... ok", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-07 16:32:42 +00:00
|
|
|
fn cargo_test_overflow_checks() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2017-04-07 16:32:42 +00:00
|
|
|
use std::panic;
|
|
|
|
pub fn main() {
|
|
|
|
let r = panic::catch_unwind(|| {
|
2020-04-06 21:37:06 +00:00
|
|
|
[1, i32::MAX].iter().sum::<i32>();
|
2017-04-07 16:32:42 +00:00
|
|
|
});
|
|
|
|
assert!(r.is_err());
|
2020-09-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-04-07 16:32:42 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build --release").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.release_bin("foo").is_file());
|
2017-04-07 16:32:42 +00:00
|
|
|
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(&p.release_bin("foo")).with_stdout("").run();
|
2017-04-07 16:32:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-02-21 15:16:49 +00:00
|
|
|
fn cargo_test_quiet_with_harness() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2019-02-21 15:16:49 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[test]]
|
|
|
|
name = "foo"
|
|
|
|
path = "src/foo.rs"
|
|
|
|
harness = true
|
|
|
|
"#,
|
2019-02-21 15:16:49 +00:00
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/foo.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn test_hello() {}
|
|
|
|
"#,
|
2019-04-05 19:55:01 +00:00
|
|
|
)
|
|
|
|
.build();
|
2019-02-21 15:16:49 +00:00
|
|
|
|
2019-04-05 19:55:01 +00:00
|
|
|
p.cargo("test -q")
|
|
|
|
.with_stdout(
|
|
|
|
"
|
2019-02-21 15:16:49 +00:00
|
|
|
running 1 test
|
|
|
|
.
|
2020-11-22 23:25:46 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
2019-02-21 15:16:49 +00:00
|
|
|
|
2019-04-05 19:55:01 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stderr("")
|
|
|
|
.run();
|
2019-02-21 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-02-21 15:16:49 +00:00
|
|
|
fn cargo_test_quiet_no_harness() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2019-02-21 15:16:49 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
2019-02-21 15:16:49 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[test]]
|
|
|
|
name = "foo"
|
|
|
|
path = "src/main.rs"
|
|
|
|
harness = false
|
|
|
|
"#,
|
2019-02-21 15:16:49 +00:00
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn test_hello() {}
|
|
|
|
"#,
|
2019-04-05 19:55:01 +00:00
|
|
|
)
|
|
|
|
.build();
|
2019-02-21 15:16:49 +00:00
|
|
|
|
2019-04-05 19:55:01 +00:00
|
|
|
p.cargo("test -q").with_stdout("").with_stderr("").run();
|
2019-02-21 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
2021-07-27 07:49:59 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn cargo_doc_test_quiet() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
/// ```
|
|
|
|
/// let result = foo::add(2, 3);
|
|
|
|
/// assert_eq!(result, 5);
|
|
|
|
/// ```
|
|
|
|
pub fn add(a: i32, b: i32) -> i32 {
|
|
|
|
a + b
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
/// let result = foo::div(10, 2);
|
|
|
|
/// assert_eq!(result, 5);
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// The function panics if the second argument is zero.
|
|
|
|
///
|
|
|
|
/// ```rust,should_panic
|
|
|
|
/// // panics on division by zero
|
|
|
|
/// foo::div(10, 0);
|
|
|
|
/// ```
|
|
|
|
pub fn div(a: i32, b: i32) -> i32 {
|
|
|
|
if b == 0 {
|
|
|
|
panic!("Divide-by-zero error");
|
|
|
|
}
|
|
|
|
|
|
|
|
a / b
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test] fn test_hello() {}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -q")
|
|
|
|
.with_stdout(
|
|
|
|
"
|
|
|
|
running 1 test
|
|
|
|
.
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
|
|
|
|
|
|
|
|
|
|
|
running 3 tests
|
|
|
|
...
|
|
|
|
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
|
|
|
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stderr("")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_test_verbose() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn test_hello() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-08-07 15:27:05 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v hello")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `rustc [..] src/main.rs [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2019-02-19 18:21:58 +00:00
|
|
|
[RUNNING] `[CWD]/target/debug/deps/foo-[..] hello`
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test_hello ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-07 15:27:05 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn many_similar_names() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
|
|
|
#[test] fn test_test() { foo::foo() }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-23 18:44:15 +00:00
|
|
|
|
2018-08-28 22:11:30 +00:00
|
|
|
p.cargo("test -v")
|
|
|
|
.with_stdout_contains("test bin_test ... ok")
|
|
|
|
.with_stdout_contains("test lib_test ... ok")
|
|
|
|
.with_stdout_contains("test test_test ... ok")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 18:44:15 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-03-20 10:39:22 +00:00
|
|
|
fn cargo_test_failing_test_in_bin() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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")
|
2020-09-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(&p.bin("foo")).with_stdout("hello\n").run();
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2022-08-28 00:45:11 +00:00
|
|
|
[ERROR] test failed, to rerun pass `--bin foo`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains(
|
2018-08-28 09:20:03 +00:00
|
|
|
"
|
2014-08-01 03:21:13 +00:00
|
|
|
running 1 test
|
|
|
|
test test_hello ... FAILED
|
|
|
|
|
|
|
|
failures:
|
|
|
|
|
|
|
|
---- test_hello stdout ----
|
2023-07-29 16:12:46 +00:00
|
|
|
[..]thread '[..]' panicked at [..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2023-08-14 18:10:17 +00:00
|
|
|
.with_stdout_contains("[..]assertion [..]failed[..]")
|
|
|
|
.with_stdout_contains("[..]left == right[..]")
|
|
|
|
.with_stdout_contains("[..]left: [..]\"hello\"[..]")
|
|
|
|
.with_stdout_contains("[..]right: [..]\"nope\"[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-09 20:08:44 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-03-20 10:39:22 +00:00
|
|
|
fn cargo_test_failing_test_in_test() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2017-03-20 10:39:22 +00:00
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", r#"pub fn main() { println!("hello"); }"#)
|
2018-08-28 09:20:03 +00:00
|
|
|
.file(
|
|
|
|
"tests/footest.rs",
|
|
|
|
"#[test] fn test_hello() { assert!(false) }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-03-20 10:39:22 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2017-03-20 10:39:22 +00:00
|
|
|
|
2018-08-28 21:05:39 +00:00
|
|
|
p.process(&p.bin("foo")).with_stdout("hello\n").run();
|
2017-03-20 10:39:22 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/footest-[..][EXE])
|
2022-08-28 00:45:11 +00:00
|
|
|
[ERROR] test failed, to rerun pass `--test footest`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains(
|
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
running 1 test
|
|
|
|
test test_hello ... FAILED
|
|
|
|
|
|
|
|
failures:
|
|
|
|
|
|
|
|
---- test_hello stdout ----
|
2023-07-29 16:12:46 +00:00
|
|
|
[..]thread '[..]' panicked at [..]tests/footest.rs:1:[..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2023-07-29 16:12:46 +00:00
|
|
|
.with_stdout_contains("[..]assertion failed[..]")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_stdout_contains(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
failures:
|
|
|
|
test_hello
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-03-20 10:39:22 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-03-20 10:39:22 +00:00
|
|
|
fn cargo_test_failing_test_in_lib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2017-03-20 10:39:22 +00:00
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "#[test] fn test_hello() { assert!(false) }")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-03-20 10:39:22 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2022-08-28 00:45:11 +00:00
|
|
|
[ERROR] test failed, to rerun pass `--lib`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
test test_hello ... FAILED
|
|
|
|
|
|
|
|
failures:
|
|
|
|
|
|
|
|
---- test_hello stdout ----
|
2023-07-29 16:12:46 +00:00
|
|
|
[..]thread '[..]' panicked at [..]src/lib.rs:1:[..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2023-07-29 16:12:46 +00:00
|
|
|
.with_stdout_contains("[..]assertion failed[..]")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_stdout_contains(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2017-03-20 10:39:22 +00:00
|
|
|
failures:
|
|
|
|
test_hello
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-03-20 10:39:22 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_with_lib_dep() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-17 01:44:30 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name = "baz"
|
|
|
|
path = "src/main.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// extern crate foo;
|
|
|
|
/// fn main() {
|
|
|
|
/// println!("{:?}", foo::foo());
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
pub fn foo(){}
|
|
|
|
#[test] fn lib_test() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-09 20:08:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/baz-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test lib_test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test bin_test ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 3)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_with_deep_lib_dep() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2017-08-27 07:31:16 +00:00
|
|
|
#[cfg(test)]
|
2018-07-20 17:41:44 +00:00
|
|
|
extern crate bar;
|
2014-08-19 20:10:55 +00:00
|
|
|
/// ```
|
2018-07-20 17:41:44 +00:00
|
|
|
/// foo::foo();
|
2014-08-19 20:10:55 +00:00
|
|
|
/// ```
|
2018-07-20 17:41:44 +00:00
|
|
|
pub fn foo() {}
|
2014-08-19 20:10:55 +00:00
|
|
|
|
2014-07-10 18:50:03 +00:00
|
|
|
#[test]
|
|
|
|
fn bar_test() {
|
2018-07-20 17:41:44 +00:00
|
|
|
bar::bar();
|
2014-07-10 18:50:03 +00:00
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _p2 = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn bar() {} #[test] fn foo_test() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-10 18:50:03 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-07-20 17:41:44 +00:00
|
|
|
[COMPILING] bar v0.0.1 ([..])
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target[..])
|
2018-07-20 17:41:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test bar_test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains_n("test [..] ... ok", 2)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn external_test_explicit() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[test]]
|
|
|
|
name = "test"
|
|
|
|
path = "src/test.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn internal_test() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/test.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(foo::get_hello(), "Hello") }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/test-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test internal_test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test external_test ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-24 12:37:37 +00:00
|
|
|
fn external_test_named_test() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2017-04-24 12:37:37 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[test]]
|
|
|
|
name = "test"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("tests/test.rs", "#[test] fn foo() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-24 12:37:37 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test").run();
|
2017-04-24 12:37:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn external_test_implicit() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn internal_test() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/external.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(foo::get_hello(), "Hello") }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/external-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test internal_test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test external_test ... ok")
|
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-11 20:34:50 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn dont_run_examples() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/dont-run-me-i-will-fail.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() { panic!("Examples should not be run by 'cargo test'"); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-10 20:53:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2022-10-07 15:08:26 +00:00
|
|
|
fn pass_through_escaped() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
2022-10-07 15:08:26 +00:00
|
|
|
/// ```rust
|
|
|
|
/// assert!(foo::foo());
|
|
|
|
/// ```
|
|
|
|
pub fn foo() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ```rust
|
|
|
|
/// assert!(!foo::bar());
|
|
|
|
/// ```
|
|
|
|
pub fn bar() -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test] fn test_foo() {
|
|
|
|
assert!(foo());
|
|
|
|
}
|
|
|
|
#[test] fn test_bar() {
|
|
|
|
assert!(!bar());
|
|
|
|
}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -- bar")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2022-10-07 15:15:50 +00:00
|
|
|
[DOCTEST] foo
|
2022-10-07 15:08:26 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 1 test")
|
|
|
|
.with_stdout_contains("test test_bar ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test -- foo")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2022-10-07 15:15:50 +00:00
|
|
|
[DOCTEST] foo
|
2022-10-07 15:08:26 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 1 test")
|
|
|
|
.with_stdout_contains("test test_foo ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test -- foo bar")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2022-10-07 15:15:50 +00:00
|
|
|
[DOCTEST] foo
|
2022-10-07 15:08:26 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 2 tests")
|
|
|
|
.with_stdout_contains("test test_foo ... ok")
|
|
|
|
.with_stdout_contains("test test_bar ... ok")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlike `pass_through_escaped`, doctests won't run when using `testname` as an optimization
|
|
|
|
#[cargo_test]
|
|
|
|
fn pass_through_testname() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"
|
|
|
|
/// ```rust
|
|
|
|
/// assert!(foo::foo());
|
|
|
|
/// ```
|
|
|
|
pub fn foo() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ```rust
|
|
|
|
/// assert!(!foo::bar());
|
|
|
|
/// ```
|
|
|
|
pub fn bar() -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test] fn test_foo() {
|
|
|
|
assert!(foo());
|
|
|
|
}
|
|
|
|
#[test] fn test_bar() {
|
|
|
|
assert!(!bar());
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-10 20:53:36 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test bar")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2019-02-19 18:21:58 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2019-02-19 18:21:58 +00:00
|
|
|
.with_stdout_contains("running 1 test")
|
2022-10-07 15:08:26 +00:00
|
|
|
.with_stdout_contains("test test_bar ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test foo")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2019-02-19 18:21:58 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2019-02-19 18:21:58 +00:00
|
|
|
.with_stdout_contains("running 1 test")
|
2022-10-07 15:08:26 +00:00
|
|
|
.with_stdout_contains("test test_foo ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test foo -- bar")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("running 2 tests")
|
|
|
|
.with_stdout_contains("test test_foo ... ok")
|
|
|
|
.with_stdout_contains("test test_bar ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
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
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cargo_test_twice() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2018-07-20 17:41:44 +00:00
|
|
|
"src/foo.rs",
|
2018-03-14 15:17:44 +00:00
|
|
|
r#"
|
2014-07-21 00:02:09 +00:00
|
|
|
#![crate_type = "rlib"]
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dummy_test() { }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-21 00:02:09 +00:00
|
|
|
|
2015-03-22 23:58:11 +00:00
|
|
|
for _ in 0..2 {
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test").run();
|
2014-07-21 00:02:09 +00:00
|
|
|
}
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn lib_bin_same_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "#[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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn lib_with_standard_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("syntax", "0.0.1"))
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/syntax-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/test-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] syntax",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo_test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test test ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 3)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn lib_with_standard_name2() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "syntax"
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-23 00:53:38 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/syntax-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 18:58:09 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn lib_without_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-06-21 10:34:42 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-06-21 10:34:42 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] syntax v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/syntax-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-21 10:34:42 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bin_without_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
path = "src/main.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
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",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bench_without_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bench]]
|
|
|
|
path = "src/bench.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
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",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_without_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[test]]
|
|
|
|
path = "src/test.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn foo() {}
|
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/test.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate syntax;
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(syntax::get_hello(), "Hello") }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
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",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn example_without_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
doctest = false
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[example]]
|
|
|
|
path = "examples/example.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"examples/example.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate syntax;
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {
|
|
|
|
println!("example1");
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
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",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-30 19:44:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bin_there_for_integration() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/foo.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
use std::process::Command;
|
|
|
|
#[test]
|
|
|
|
fn test_test() {
|
|
|
|
let status = Command::new("target/debug/foo").status().unwrap();
|
|
|
|
assert_eq!(status.code(), Some(101));
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2014-07-23 18:58:09 +00:00
|
|
|
|
2018-08-28 22:11:30 +00:00
|
|
|
p.cargo("test -v")
|
|
|
|
.with_stdout_contains("test main_test ... ok")
|
|
|
|
.with_stdout_contains("test test_test ... ok")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 16:09:33 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_dylib() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-23 16:09:33 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
crate_type = ["dylib"]
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate bar as the_bar;
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn bar() { the_bar::baz(); }
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() { bar(); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/test.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo as the_foo;
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() { the_foo::bar(); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "bar"
|
|
|
|
crate_type = ["dylib"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 16:09:33 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] bar v0.0.1 ([CWD]/bar)
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/test-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test foo ... ok", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2014-08-01 03:21:13 +00:00
|
|
|
|
2016-05-26 00:06:25 +00:00
|
|
|
p.root().move_into_the_past();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/test-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("test foo ... ok", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-07-23 16:36:49 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_twice_with_build_cmd() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("build.rs", "fn main() {}")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "#[test] fn foo() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-07-23 16:36:49 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-19 04:38:04 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_then_build() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().file("src/lib.rs", "#[test] fn foo() {}").build();
|
2014-08-19 04:38:04 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test foo ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.run();
|
2014-08-19 04:38:04 +00:00
|
|
|
|
2023-11-15 22:33:27 +00:00
|
|
|
p.cargo("build").with_stderr("[FINISHED] [..]").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-21 21:09:27 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_no_run() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "#[test] fn foo() { panic!() }")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2014-08-21 21:09:27 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --no-run")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2022-01-31 18:37:02 +00:00
|
|
|
[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE])
|
2014-08-21 21:09:27 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-08-25 12:54:47 +00:00
|
|
|
|
2022-05-21 16:18:20 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn test_no_run_emit_json() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "#[test] fn foo() { panic!() }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --no-run --message-format json")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_run_specific_bin_target() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let prj = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name="bin1"
|
|
|
|
path="src/bin1.rs"
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name="bin2"
|
|
|
|
path="src/bin2.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --bin bin2")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/bin2-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test2 ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-05 19:48:15 +00:00
|
|
|
fn test_run_implicit_bin_target() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let prj = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2017-04-05 19:48:15 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name="mybin"
|
|
|
|
path="src/mybin.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
2017-04-05 19:48:15 +00:00
|
|
|
.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!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --bins")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/mybin-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test_in_bin ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_run_specific_test_target() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let prj = project()
|
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-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --test b")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/b-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test_b ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-05 19:48:15 +00:00
|
|
|
fn test_run_implicit_test_target() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let prj = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="mybin"
|
|
|
|
path="src/mybin.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
2017-04-05 19:48:15 +00:00
|
|
|
.file("benches/mybench.rs", "#[test] fn test_in_bench() { }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/myexm.rs",
|
2018-04-21 17:41:05 +00:00
|
|
|
"fn main() { compile_error!(\"Don't build me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --tests")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/mybin-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/mytest-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test_in_test ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-05 19:48:15 +00:00
|
|
|
fn test_run_implicit_bench_target() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let prj = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2017-04-05 19:48:15 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name="mybin"
|
|
|
|
path="src/mybin.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
2017-04-05 19:48:15 +00:00
|
|
|
.file("benches/mybench.rs", "#[test] fn test_in_bench() { }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"examples/myexm.rs",
|
2018-04-21 17:41:05 +00:00
|
|
|
"fn main() { compile_error!(\"Don't build me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --benches")
|
2018-08-29 17:56:48 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/mybin-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/mybench-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test test_in_bench ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-05 19:48:15 +00:00
|
|
|
fn test_run_implicit_example_target() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let prj = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2017-04-05 19:48:15 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name = "mybin"
|
|
|
|
path = "src/mybin.rs"
|
2018-05-03 03:17:53 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[example]]
|
|
|
|
name = "myexm1"
|
2018-05-03 03:17:53 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[example]]
|
|
|
|
name = "myexm2"
|
|
|
|
test = true
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
2017-04-05 19:48:15 +00:00
|
|
|
.file("benches/mybench.rs", "#[test] fn test_in_bench() { }")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2018-05-03 03:17:53 +00:00
|
|
|
"examples/myexm1.rs",
|
|
|
|
"#[test] fn test_in_exm() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-05-03 03:17:53 +00:00
|
|
|
"examples/myexm2.rs",
|
|
|
|
"#[test] fn test_in_exm() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-04-05 19:48:15 +00:00
|
|
|
|
2018-05-03 03:17:53 +00:00
|
|
|
// Compiles myexm1 as normal, but does not run it.
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test -v")
|
2018-09-09 17:39:55 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]myexm1.rs [..]--crate-type bin[..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]myexm2.rs [..]--test[..]")
|
|
|
|
.with_stderr_does_not_contain("[RUNNING] [..]myexm1-[..]")
|
|
|
|
.with_stderr_contains("[RUNNING] [..]target/debug/examples/myexm2-[..]")
|
|
|
|
.run();
|
2018-05-03 03:17:53 +00:00
|
|
|
|
|
|
|
// Only tests myexm2.
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --tests")
|
|
|
|
.with_stderr_does_not_contain("[RUNNING] [..]myexm1-[..]")
|
|
|
|
.with_stderr_contains("[RUNNING] [..]target/debug/examples/myexm2-[..]")
|
|
|
|
.run();
|
2018-05-03 03:17:53 +00:00
|
|
|
|
|
|
|
// Tests all examples.
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --examples")
|
|
|
|
.with_stderr_contains("[RUNNING] [..]target/debug/examples/myexm1-[..]")
|
|
|
|
.with_stderr_contains("[RUNNING] [..]target/debug/examples/myexm2-[..]")
|
|
|
|
.run();
|
2018-05-03 03:17:53 +00:00
|
|
|
|
|
|
|
// Test an example, even without `test` set.
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --example myexm1")
|
|
|
|
.with_stderr_contains("[RUNNING] [..]target/debug/examples/myexm1-[..]")
|
|
|
|
.run();
|
2018-05-03 03:17:53 +00:00
|
|
|
|
|
|
|
// Tests all examples.
|
2018-08-28 09:20:03 +00:00
|
|
|
prj.cargo("test --all-targets")
|
|
|
|
.with_stderr_contains("[RUNNING] [..]target/debug/examples/myexm1-[..]")
|
|
|
|
.with_stderr_contains("[RUNNING] [..]target/debug/examples/myexm2-[..]")
|
|
|
|
.run();
|
2017-04-05 19:48:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-02-19 18:21:58 +00:00
|
|
|
fn test_filtered_excludes_compiling_examples() {
|
|
|
|
let p = project()
|
2022-01-18 18:22:58 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "mybin"
|
|
|
|
test = false
|
|
|
|
"#,
|
|
|
|
)
|
2019-02-19 18:21:58 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
2022-01-18 18:22:58 +00:00
|
|
|
"#[cfg(test)] mod tests { #[test] fn test_in_lib() { } }",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/bin/mybin.rs",
|
|
|
|
"#[test] fn test_in_bin() { }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
|
|
|
)
|
|
|
|
.file("tests/mytest.rs", "#[test] fn test_in_test() { }")
|
|
|
|
.file(
|
|
|
|
"benches/mybench.rs",
|
|
|
|
"#[test] fn test_in_bench() { assert!(false) }",
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/myexm1.rs",
|
|
|
|
"#[test] fn test_in_exm() { assert!(false) }
|
|
|
|
fn main() { panic!(\"Don't execute me!\"); }",
|
2019-02-19 18:21:58 +00:00
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2022-01-18 18:22:58 +00:00
|
|
|
p.cargo("test -v test_in_")
|
2019-02-19 18:21:58 +00:00
|
|
|
.with_stdout(
|
|
|
|
"
|
|
|
|
running 1 test
|
2022-01-18 18:22:58 +00:00
|
|
|
test tests::test_in_lib ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
|
|
|
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test_in_test ... ok
|
2019-02-19 18:21:58 +00:00
|
|
|
|
2020-11-22 23:25:46 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
2019-02-19 18:21:58 +00:00
|
|
|
|
|
|
|
",
|
|
|
|
)
|
2022-01-18 18:22:58 +00:00
|
|
|
.with_stderr_unordered(
|
2019-04-05 19:55:01 +00:00
|
|
|
"\
|
2019-02-19 18:21:58 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2022-01-18 18:22:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src/lib.rs [..] --crate-type lib [..]`
|
2019-02-19 18:21:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo src/lib.rs [..] --test [..]`
|
2022-01-18 18:22:58 +00:00
|
|
|
[RUNNING] `rustc --crate-name mybin src/bin/mybin.rs [..] --crate-type bin [..]`
|
|
|
|
[RUNNING] `rustc --crate-name mytest tests/mytest.rs [..] --test [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2022-01-18 18:22:58 +00:00
|
|
|
[RUNNING] `[CWD]/target/debug/deps/foo-[..] test_in_`
|
|
|
|
[RUNNING] `[CWD]/target/debug/deps/mytest-[..] test_in_`
|
2019-02-19 18:21:58 +00:00
|
|
|
",
|
|
|
|
)
|
2022-01-18 18:22:58 +00:00
|
|
|
.with_stderr_does_not_contain("[RUNNING][..]rustc[..]myexm1[..]")
|
2022-01-18 18:45:05 +00:00
|
|
|
.with_stderr_does_not_contain("[RUNNING][..]deps/mybin-[..] test_in_")
|
2019-02-19 18:21:58 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_no_harness() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-08-25 12:54:47 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
2014-08-25 12:54:47 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[test]]
|
|
|
|
name = "bar"
|
|
|
|
path = "foo.rs"
|
|
|
|
harness = false
|
|
|
|
"#,
|
2018-12-08 11:19: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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -- --nocapture")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/bar-[..][EXE])
|
2014-08-25 12:54:47 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-24 01:10:27 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn selective_testing() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-09-24 01:10:27 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
[dependencies.d2]
|
|
|
|
path = "d2"
|
2014-09-24 01:10:27 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
2014-09-24 01:10:27 +00:00
|
|
|
name = "d1"
|
2020-09-27 00:59:58 +00:00
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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() {}",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"d2/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
2014-09-24 01:10:27 +00:00
|
|
|
name = "d2"
|
2020-09-27 00:59:58 +00:00
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d2"
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -p d1")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] d1 v0.0.1 ([CWD]/d1)
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/d1-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/d1-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("running 0 tests", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2014-09-24 01:10:27 +00:00
|
|
|
|
|
|
|
println!("d2");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -p d2")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] d2 v0.0.1 ([CWD]/d2)
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/d2-[..][EXE])
|
|
|
|
[RUNNING] [..] (target/debug/deps/d2-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("running 0 tests", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2014-09-24 01:10:27 +00:00
|
|
|
|
|
|
|
println!("whole");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-09-24 05:14:02 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn almost_cyclic_but_not_quite() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-09-24 05:14:02 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies.b]
|
|
|
|
path = "b"
|
|
|
|
[dev-dependencies.c]
|
|
|
|
path = "c"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[cfg(test)] extern crate b;
|
|
|
|
#[cfg(test)] extern crate c;
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "b"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-09-24 05:14:02 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.foo]
|
|
|
|
path = ".."
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"b/src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate foo;
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("c/Cargo.toml", &basic_manifest("c", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("c/src/lib.rs", "")
|
|
|
|
.build();
|
2014-09-24 05:14:02 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
|
|
|
p.cargo("test").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-06 18:27:16 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn build_then_selective_test() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-10-06 18:27:16 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.b]
|
|
|
|
path = "b"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-08-28 09:20:03 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate b;",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate b;
|
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate foo;
|
|
|
|
fn main() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
2014-10-06 18:27:16 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build").run();
|
2016-05-26 00:06:25 +00:00
|
|
|
p.root().move_into_the_past();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -p b").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-03 01:57:33 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn example_dev_dep() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-10-06 03:00:42 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("examples/e1.rs", "extern crate bar; fn main() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
// make sure this file takes awhile to compile
|
|
|
|
macro_rules! f0( () => (1) );
|
|
|
|
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!();
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test").run();
|
|
|
|
p.cargo("run --example e1 --release -v").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-06 03:00:42 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn selective_testing_with_docs() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-10-03 01:57:33 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// not valid rust
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-10-07 19:01:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
path = "d1.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -p d1")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] d1 v0.0.1 ([CWD]/d1)
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/d1[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] d1",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains_n("running 0 tests", 2)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-24 16:18:19 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn example_bin_same_name() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --no-run -v")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2016-05-11 16:55:43 +00:00
|
|
|
[RUNNING] `rustc [..]`
|
|
|
|
[RUNNING] `rustc [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-10-04 21:52:02 +00:00
|
|
|
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2014-10-24 16:18:19 +00:00
|
|
|
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.bin("foo").is_file());
|
|
|
|
assert!(p.bin("examples/foo").is_file());
|
2014-10-24 16:18:19 +00:00
|
|
|
|
2018-08-28 20:38:26 +00:00
|
|
|
p.process(&p.bin("examples/foo"))
|
|
|
|
.with_stdout("example\n")
|
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("run")
|
|
|
|
.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-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout("bin")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-10-29 23:33:52 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_with_example_twice() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("examples/foo").is_file());
|
2014-10-29 23:33:52 +00:00
|
|
|
println!("second");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("examples/foo").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2014-12-28 09:04:10 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn example_with_dev_dep() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-12-28 09:04:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
|
|
|
doctest = false
|
2014-12-28 09:04:10 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies.a]
|
|
|
|
path = "a"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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() {}",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
2014-12-28 09:04:10 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2014-12-28 09:04:10 +00:00
|
|
|
[..]
|
|
|
|
[..]
|
|
|
|
[..]
|
|
|
|
[..]
|
2016-11-30 19:04:14 +00:00
|
|
|
[RUNNING] `rustc --crate-name ex [..] --extern a=[..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-01-14 05:23:43 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bin_is_preserved() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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-08-28 09:20:03 +00:00
|
|
|
p.cargo("build -v").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2015-01-14 05:23:43 +00:00
|
|
|
|
2020-07-12 14:52:31 +00:00
|
|
|
println!("test");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(p.bin("foo").is_file());
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-02-09 16:28:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bad_example() {
|
2018-08-28 09:20:03 +00:00
|
|
|
let p = project().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-08-28 09:20:03 +00:00
|
|
|
p.cargo("run --example foo")
|
|
|
|
.with_status(101)
|
2022-08-17 14:28:36 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] no example target named `foo`.
|
|
|
|
|
|
|
|
",
|
|
|
|
)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
|
|
|
p.cargo("run --bin foo")
|
|
|
|
.with_status(101)
|
2022-08-17 14:28:36 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[ERROR] no bin target named `foo`.
|
|
|
|
|
|
|
|
",
|
|
|
|
)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-02-09 19:14:27 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doctest_feature() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
[features]
|
|
|
|
bar = []
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```rust
|
|
|
|
/// assert_eq!(foo::foo(), 1);
|
|
|
|
/// ```
|
|
|
|
#[cfg(feature = "bar")]
|
|
|
|
pub fn foo() -> i32 { 1 }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-02-09 19:14:27 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --features bar")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo [..]
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test [..] ... ok")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-03-26 19:07:11 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn dashes_to_underscores() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("foo-bar", "0.0.1"))
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// assert_eq!(foo_bar::foo(), 1);
|
|
|
|
/// ```
|
|
|
|
pub fn foo() -> i32 { 1 }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-03-26 19:07:11 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-02 18:51:29 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn doctest_dev_dep() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-04-02 18:51:29 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies]
|
|
|
|
b = { path = "b" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// extern crate b;
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
2015-04-02 18:51:29 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-07 23:56:45 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn filter_no_doc_tests() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// extern crate b;
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("tests/foo.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2015-04-07 23:56:45 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --test=foo")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo[..][EXE])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn dylib_doctest() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
crate-type = ["rlib", "dylib"]
|
|
|
|
test = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// foo::foo();
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test [..] ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn dylib_doctest2() {
|
2019-02-03 04:01:23 +00:00
|
|
|
// Can't doc-test dylibs, as they're statically linked together.
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
crate-type = ["dylib"]
|
|
|
|
test = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// foo::foo();
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-04-09 17:43:49 +00:00
|
|
|
|
2023-11-15 22:33:27 +00:00
|
|
|
p.cargo("test").with_stderr("[FINISHED] [..]").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-06-06 08:22:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn cyclic_dev_dep_doc_test() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-06-06 08:22:36 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
//! ```
|
|
|
|
//! extern crate bar;
|
|
|
|
//! ```
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-06-06 08:22:36 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
foo = { path = ".." }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[allow(unused_extern_crates)]
|
|
|
|
extern crate foo;
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
|
|
[COMPILING] bar v0.0.1 ([..])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo[..][EXE])
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test [..] ... ok")
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-01 17:37:21 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn dev_dep_with_build_script() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-07-01 17:37:21 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2015-07-01 17:37:21 +00:00
|
|
|
.file("examples/foo.rs", "fn main() {}")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/build.rs", "fn main() {}")
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-08-28 02:37:45 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn no_fail_fast() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +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-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/test_add_one.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
|
|
|
use foo::*;
|
2015-08-28 02:37:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn add_one_test() {
|
|
|
|
assert_eq!(add_one(1), 2);
|
|
|
|
}
|
2015-08-28 02:37:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn fail_add_one_test() {
|
|
|
|
assert_eq!(add_one(1), 1);
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/test_sub_one.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
|
|
|
use foo::*;
|
2015-08-28 02:37:45 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn sub_one_test() {
|
|
|
|
assert_eq!(sub_one(1), 0);
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --no-fail-fast")
|
|
|
|
.with_status(101)
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stderr(
|
2018-08-28 09:20:03 +00:00
|
|
|
"\
|
2022-08-28 00:45:11 +00:00
|
|
|
[COMPILING] foo v0.0.1 [..]
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] unittests src/lib.rs (target/debug/deps/foo[..])
|
|
|
|
[RUNNING] tests/test_add_one.rs (target/debug/deps/test_add_one[..])
|
|
|
|
[ERROR] test failed, to rerun pass `--test test_add_one`
|
|
|
|
[RUNNING] tests/test_sub_one.rs (target/debug/deps/test_sub_one[..])
|
|
|
|
[DOCTEST] foo
|
|
|
|
[ERROR] 1 target failed:
|
|
|
|
`--test test_add_one`
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("running 0 tests")
|
|
|
|
.with_stdout_contains("test result: FAILED. [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test sub_one_test ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 3)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_multiple_packages() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
[dependencies.d2]
|
|
|
|
path = "d2"
|
2015-07-16 20:35:40 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d1/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
2015-07-16 20:35:40 +00:00
|
|
|
name = "d1"
|
2020-09-27 00:59:58 +00:00
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("d1/src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"d2/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
2015-07-16 20:35:40 +00:00
|
|
|
name = "d2"
|
2020-09-27 00:59:58 +00:00
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d2"
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -p d1 -p d2")
|
2021-02-21 22:37:42 +00:00
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/debug/deps/d1-[..][EXE])")
|
|
|
|
.with_stderr_contains("[RUNNING] [..] (target/debug/deps/d2-[..][EXE])")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains_n("running 0 tests", 2)
|
|
|
|
.run();
|
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
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn bin_does_not_rebuild_tests() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
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);
|
2019-10-23 15:14:40 +00:00
|
|
|
fs::write(p.root().join("src/main.rs"), "fn main() { 3; }").unwrap();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v --no-run")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2022-11-21 17:39:02 +00:00
|
|
|
[DIRTY] foo v0.0.1 ([..]): the file `src/main.rs` has changed ([..])
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `rustc [..] src/main.rs [..]`
|
|
|
|
[RUNNING] `rustc [..] src/main.rs [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-10-04 21:52:02 +00:00
|
|
|
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
|
|
|
|
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
|
|
|
|
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-20 22:50:58 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn selective_test_wonky_profile() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-10-20 22:50:58 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.release]
|
|
|
|
opt-level = 2
|
2015-10-20 22:50:58 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v --no-run --release -p foo -p a").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-10-21 00:19:56 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn selective_test_optional_dep() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-10-21 00:19:56 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
a = { path = "a", optional = true }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v --no-run --features a -p a")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2016-05-11 16:55:43 +00:00
|
|
|
[COMPILING] a v0.0.1 ([..])
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `rustc [..] a/src/lib.rs [..]`
|
|
|
|
[RUNNING] `rustc [..] a/src/lib.rs [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-10-04 21:52:02 +00:00
|
|
|
[EXECUTABLE] `[..]/target/debug/deps/a-[..][EXE]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-04-14 17:37:16 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn only_test_docs() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() {
|
|
|
|
let a: u32 = "hello";
|
|
|
|
}
|
2016-04-14 17:37:16 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// foo::bar();
|
|
|
|
/// println!("ok");
|
|
|
|
/// ```
|
|
|
|
pub fn bar() {
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --doc")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2016-05-17 13:08:29 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
[DOCTEST] foo",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains("test [..] ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-05-16 18:56:40 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn test_panic_abort_with_dep() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2016-05-13 18:35:52 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
2016-05-13 18:35:52 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.dev]
|
|
|
|
panic = 'abort'
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate bar;
|
2016-05-13 18:35:52 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2016-06-20 16:28:09 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-06-20 16:28:09 +00:00
|
|
|
fn cfg_test_even_with_no_harness() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2016-06-20 16:28:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
harness = false
|
|
|
|
doctest = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-08-28 09:20:03 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"#[cfg(test)] fn main() { println!("hello!"); }"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v")
|
|
|
|
.with_stdout("hello!\n")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2016-06-20 16:28:09 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([..])
|
|
|
|
[RUNNING] `rustc [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2016-06-20 16:28:09 +00:00
|
|
|
[RUNNING] `[..]`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-06-20 16:28:09 +00:00
|
|
|
}
|
2016-08-19 20:25:13 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-08-19 20:25:13 +00:00
|
|
|
fn panic_abort_multiple() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2016-08-19 20:25:13 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
2016-08-19 20:25:13 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.release]
|
|
|
|
panic = 'abort'
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate a;",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --release -v -p foo -p a").run();
|
2016-08-19 20:25:13 +00:00
|
|
|
}
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-10-31 18:15:03 +00:00
|
|
|
fn pass_correct_cfgs_flags_to_rustdoc() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[features]
|
|
|
|
default = ["feature_a/default"]
|
|
|
|
nightly = ["feature_a/nightly"]
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.feature_a]
|
|
|
|
path = "libs/feature_a"
|
|
|
|
default-features = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
assert!(true);
|
|
|
|
}
|
2016-10-31 18:15:03 +00:00
|
|
|
}
|
2020-09-27 00:59:58 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"libs/feature_a/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "feature_a"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[features]
|
|
|
|
default = ["mock_serde_codegen"]
|
|
|
|
nightly = ["mock_serde_derive"]
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
mock_serde_derive = { path = "../mock_serde_derive", optional = true }
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[build-dependencies]
|
|
|
|
mock_serde_codegen = { path = "../mock_serde_codegen", optional = true }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"libs/feature_a/src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[cfg(feature = "mock_serde_derive")]
|
|
|
|
const MSG: &'static str = "This is safe";
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[cfg(feature = "mock_serde_codegen")]
|
|
|
|
const MSG: &'static str = "This is risky";
|
2016-10-31 18:15:03 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn get() -> &'static str {
|
|
|
|
MSG
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-08-28 09:20:03 +00:00
|
|
|
"libs/mock_serde_derive/Cargo.toml",
|
|
|
|
&basic_manifest("mock_serde_derive", "0.1.0"),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("libs/mock_serde_derive/src/lib.rs", "")
|
2018-08-28 09:20:03 +00:00
|
|
|
.file(
|
|
|
|
"libs/mock_serde_codegen/Cargo.toml",
|
|
|
|
&basic_manifest("mock_serde_codegen", "0.1.0"),
|
2018-12-08 11:19:47 +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-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --package feature_a --verbose")
|
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2016-11-01 17:14:41 +00:00
|
|
|
[DOCTEST] feature_a
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--test [..]mock_serde_codegen[..]`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-03-14 15:17:44 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --verbose")
|
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2016-10-31 18:15:03 +00:00
|
|
|
[DOCTEST] foo
|
2019-09-12 17:38:10 +00:00
|
|
|
[RUNNING] `rustdoc [..]--test [..]feature_a[..]`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2016-10-31 18:15:03 +00:00
|
|
|
}
|
2016-10-06 22:32:15 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-10-06 22:32:15 +00:00
|
|
|
fn test_release_ignore_panic() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2016-10-06 22:32:15 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
2016-10-06 22:32:15 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.test]
|
|
|
|
panic = 'abort'
|
|
|
|
[profile.release]
|
|
|
|
panic = 'abort'
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
"#[allow(unused_extern_crates)] extern crate a;",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
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");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v").run();
|
2016-10-06 22:32:15 +00:00
|
|
|
println!("bench");
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench -v").run();
|
2016-10-06 22:32:15 +00:00
|
|
|
}
|
2016-11-10 23:44:39 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-28 14:28:39 +00:00
|
|
|
fn test_many_with_features() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-28 14:28:39 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-04-28 14:28:39 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
a = { path = "a" }
|
2018-04-28 14:28:39 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[features]
|
|
|
|
foo = []
|
2018-04-28 14:28:39 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
|
2018-04-28 14:28:39 +00:00
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test -v -p a -p foo --features foo").run();
|
2018-04-28 14:28:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-10-20 20:14:54 +00:00
|
|
|
fn test_all_workspace() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2016-10-20 20:14:54 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
2016-10-20 20:14:54 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "#[test] fn foo_test() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "#[test] fn bar_test() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-10-20 20:14:54 +00:00
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test foo_test ... ok")
|
|
|
|
.with_stdout_contains("test bar_test ... ok")
|
|
|
|
.run();
|
2016-10-20 20:14:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-05-12 13:44:15 +00:00
|
|
|
fn test_all_exclude() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2017-05-12 13:44:15 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("bar/src/lib.rs", "#[test] pub fn bar() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("baz/src/lib.rs", "#[test] pub fn baz() { assert!(false); }")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-12 13:44:15 +00:00
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace --exclude baz")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"running 1 test
|
|
|
|
test bar ... ok",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-05-12 13:44:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 15:31:22 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn test_all_exclude_not_found() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-10-09 23:44:57 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2020-10-04 15:31:22 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar"]
|
|
|
|
"#,
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[test] pub fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --workspace --exclude baz")
|
2020-10-09 22:58:06 +00:00
|
|
|
.with_stderr_contains("[WARNING] excluded package(s) `baz` not found in workspace [..]")
|
2020-10-04 15:31:22 +00:00
|
|
|
.with_stdout_contains(
|
|
|
|
"running 1 test
|
|
|
|
test bar ... ok",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_all_exclude_glob() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-10-09 23:44:57 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2020-10-04 15:31:22 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[test] pub fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "#[test] pub fn baz() { assert!(false); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --workspace --exclude '*z'")
|
|
|
|
.with_stdout_contains(
|
|
|
|
"running 1 test
|
|
|
|
test bar ... ok",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_all_exclude_glob_not_found() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-10-09 23:44:57 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2020-10-04 15:31:22 +00:00
|
|
|
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar"]
|
|
|
|
"#,
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[test] pub fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --workspace --exclude '*z'")
|
|
|
|
.with_stderr_contains(
|
2020-10-09 22:58:06 +00:00
|
|
|
"[WARNING] excluded package pattern(s) `*z` not found in workspace [..]",
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.with_stdout_contains(
|
|
|
|
"running 1 test
|
|
|
|
test bar ... ok",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_all_exclude_broken_glob() {
|
|
|
|
let p = project().file("src/main.rs", "fn main() {}").build();
|
|
|
|
|
|
|
|
p.cargo("test --workspace --exclude '[*z'")
|
|
|
|
.with_status(101)
|
2020-10-09 22:58:06 +00:00
|
|
|
.with_stderr_contains("[ERROR] cannot build glob pattern from `[*z`")
|
2020-10-04 15:31:22 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-10-20 20:14:54 +00:00
|
|
|
fn test_all_virtual_manifest() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("a/src/lib.rs", "#[test] fn a() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("b/src/lib.rs", "#[test] fn b() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-10-20 20:14:54 +00:00
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace")
|
2020-10-04 15:31:22 +00:00
|
|
|
.with_stdout_contains("running 1 test\ntest a ... ok")
|
|
|
|
.with_stdout_contains("running 1 test\ntest b ... ok")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-10-20 20:14:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-05-26 21:00:45 +00:00
|
|
|
fn test_virtual_manifest_all_implied() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("a/src/lib.rs", "#[test] fn a() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("b/src/lib.rs", "#[test] fn b() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2020-10-04 15:31:22 +00:00
|
|
|
.with_stdout_contains("running 1 test\ntest a ... ok")
|
|
|
|
.with_stdout_contains("running 1 test\ntest b ... ok")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_virtual_manifest_one_project() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[test] fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "#[test] fn baz() { assert!(false); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -p bar")
|
|
|
|
.with_stdout_contains("running 1 test\ntest bar ... ok")
|
|
|
|
.with_stdout_does_not_contain("running 1 test\ntest baz ... ok")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_virtual_manifest_glob() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[test] fn bar() { assert!(false); }")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "#[test] fn baz() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -p '*z'")
|
|
|
|
.with_stdout_does_not_contain("running 1 test\ntest bar ... ok")
|
|
|
|
.with_stdout_contains("running 1 test\ntest baz ... ok")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_virtual_manifest_glob_not_found() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar"]
|
|
|
|
"#,
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[test] fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -p bar -p '*z'")
|
2020-10-10 01:50:36 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] package pattern(s) `*z` not found in workspace [..]")
|
2020-10-04 15:31:22 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_virtual_manifest_broken_glob() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar"]
|
|
|
|
"#,
|
2020-10-04 15:31:22 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[test] fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -p '[*z'")
|
|
|
|
.with_status(101)
|
2020-10-09 22:58:06 +00:00
|
|
|
.with_stderr_contains("[ERROR] cannot build glob pattern from `[*z`")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-05-26 21:00:45 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-10-20 20:14:54 +00:00
|
|
|
fn test_all_member_dependency_same_name() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["a"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"a/Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
2016-10-20 20:14:54 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
a = "0.1.0"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/src/lib.rs", "#[test] fn a() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-10-20 20:14:54 +00:00
|
|
|
|
|
|
|
Package::new("a", "0.1.0").publish();
|
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains("test a ... ok")
|
|
|
|
.run();
|
2016-10-20 20:14:54 +00:00
|
|
|
}
|
2016-12-20 00:28:06 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-12-20 00:28:06 +00:00
|
|
|
fn doctest_only_with_dev_dep() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
2016-12-20 00:28:06 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies]
|
|
|
|
b = { path = "b" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// extern crate b;
|
|
|
|
///
|
|
|
|
/// b::b();
|
|
|
|
/// ```
|
|
|
|
pub fn a() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("b/src/lib.rs", "pub fn b() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-12-20 00:28:06 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --doc -v").run();
|
2016-12-20 00:28:06 +00:00
|
|
|
}
|
2017-02-16 16:46:39 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-02-16 16:46:39 +00:00
|
|
|
fn test_many_targets() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/bin/a.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_a() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/bin/b.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_b() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"src/bin/c.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_c() { panic!(); }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"examples/a.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn example_a() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"examples/b.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
#[test] fn example_b() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("examples/c.rs", "#[test] fn example_c() { panic!(); }")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("tests/a.rs", "#[test] fn test_a() {}")
|
|
|
|
.file("tests/b.rs", "#[test] fn test_b() {}")
|
|
|
|
.file("tests/c.rs", "does not compile")
|
2018-03-14 15:17:44 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --verbose --bin a --bin b --example a --example b --test a --test b")
|
|
|
|
.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 [..]`")
|
|
|
|
.run();
|
2017-02-16 16:46:39 +00:00
|
|
|
}
|
2017-02-16 16:04:09 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-02-16 16:04:09 +00:00
|
|
|
fn doctest_and_registry() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "a"
|
|
|
|
version = "0.1.0"
|
2017-02-16 16:04:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
b = { path = "b" }
|
|
|
|
c = { path = "c" }
|
2017-02-16 16:04:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"c/Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "c"
|
|
|
|
version = "0.1.0"
|
2017-02-16 16:04:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
b = "0.1"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("c/src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-16 16:04:09 +00:00
|
|
|
|
|
|
|
Package::new("b", "0.1.0").publish();
|
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace -v").run();
|
2017-02-16 16:04:09 +00:00
|
|
|
}
|
2017-03-02 06:38:54 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-03-02 06:38:54 +00:00
|
|
|
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;
|
2019-05-02 21:58:28 +00:00
|
|
|
eprintln!("{{}}", env::var("{}").unwrap());
|
2017-03-02 06:38:54 +00:00
|
|
|
}}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
cargo::CARGO_ENV
|
|
|
|
);
|
2017-03-02 06:38:54 +00:00
|
|
|
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/lib.rs", &src)
|
|
|
|
.build();
|
2017-03-02 06:38:54 +00:00
|
|
|
|
|
|
|
let cargo = cargo_exe().canonicalize().unwrap();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --lib -- --nocapture")
|
2019-07-14 22:19:33 +00:00
|
|
|
.with_stderr_contains(cargo.to_str().unwrap())
|
|
|
|
.with_stdout_contains("test env_test ... ok")
|
Make cargo forward pre-existing CARGO if set
Currently, Cargo will always set `$CARGO` to point to what it detects
its own path to be (using `std::env::current_exe`). Unfortunately, this
runs into trouble when Cargo is used as a library, or when `current_exe`
is not actually the binary itself (e.g., when invoked through Valgrind
or `ld.so`), since `$CARGO` will not point at something that can be used
as `cargo`. This, in turn, means that users can't currently rely on
`$CARGO` to do the right thing, and will sometimes have to invoke
`cargo` directly from `$PATH` instead, which may not reflect the `cargo`
that's currently in use.
This patch makes Cargo re-use the existing value of `$CARGO` if it's
already set in the environment. For Cargo subcommands, this will mean
that the initial invocation of `cargo` in `cargo foo` will set `$CARGO`,
and then Cargo-as-a-library inside of `cargo-foo` will inherit that
(correct) value instead of overwriting it with the incorrect value
`cargo-foo`. For other execution environments that do not have `cargo`
in their call stack, it gives them the opportunity to set a working
value for `$CARGO`.
One note about the implementation of this is that the test suite now
needs to override `$CARGO` explicitly so that the _user's_ `$CARGO` does
not interfere with the contents of the tests. It _could_ remove `$CARGO`
instead, but overriding it seemed less error-prone.
Fixes #10119.
Fixes #10113.
2022-10-25 18:49:23 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
// Check that `cargo test` propagates the environment's $CARGO
|
|
|
|
let rustc = cargo_util::paths::resolve_executable("rustc".as_ref())
|
|
|
|
.unwrap()
|
|
|
|
.canonicalize()
|
|
|
|
.unwrap();
|
|
|
|
let rustc = rustc.to_str().unwrap();
|
|
|
|
p.cargo("test --lib -- --nocapture")
|
|
|
|
// we use rustc since $CARGO is only used if it points to a path that exists
|
|
|
|
.env(cargo::CARGO_ENV, rustc)
|
|
|
|
.with_stderr_contains(rustc)
|
|
|
|
.with_stdout_contains("test env_test ... ok")
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2017-03-02 06:38:54 +00:00
|
|
|
}
|
2017-04-06 14:18:07 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-06 14:18:07 +00:00
|
|
|
fn test_order() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "#[test] fn test_lib() {}")
|
|
|
|
.file("tests/a.rs", "#[test] fn test_a() {}")
|
|
|
|
.file("tests/z.rs", "#[test] fn test_z() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-06 14:18:07 +00:00
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stdout_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-04-06 14:18:07 +00:00
|
|
|
}
|
2017-04-13 21:40:08 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-13 21:40:08 +00:00
|
|
|
fn cyclic_dev() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2017-04-13 21:40:08 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies]
|
|
|
|
foo = { path = "." }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "#[test] fn test_lib() {}")
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("tests/foo.rs", "extern crate foo;")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-04-13 21:40:08 +00:00
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace").run();
|
2017-04-13 21:40:08 +00:00
|
|
|
}
|
2017-08-09 21:54:09 +00:00
|
|
|
|
2023-11-14 20:18:43 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn cyclical_dep_with_missing_feature() {
|
|
|
|
// Checks for error handling when a cyclical dev-dependency specify a
|
|
|
|
// feature that doesn't exist.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
foo = { path = ".", features = ["missing"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
p.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2023-11-14 20:18:43 +00:00
|
|
|
"error: failed to select a version for `foo`.
|
|
|
|
... required by package `foo v0.1.0 ([..]/foo)`
|
|
|
|
versions that meet the requirements `*` are: 0.1.0
|
|
|
|
|
|
|
|
the package `foo` depends on `foo`, with features: `missing` but `foo` does not have these features.
|
|
|
|
|
|
|
|
|
|
|
|
failed to select a version for `foo` which could resolve this conflict",
|
2023-11-14 20:18:43 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-08-09 21:54:09 +00:00
|
|
|
fn publish_a_crate_without_tests() {
|
|
|
|
Package::new("testless", "0.1.0")
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "testless"
|
|
|
|
version = "0.1.0"
|
|
|
|
exclude = ["tests/*"]
|
2017-08-09 21:54:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[[test]]
|
|
|
|
name = "a_test"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2017-08-09 21:54:09 +00:00
|
|
|
.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();
|
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2017-08-09 21:54:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
testless = "0.1.0"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-08-09 21:54:09 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test").run();
|
|
|
|
p.cargo("test --package testless").run();
|
2017-08-09 21:54:09 +00:00
|
|
|
}
|
2017-08-29 10:43:41 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-08-29 10:43:41 +00:00
|
|
|
fn find_dependency_of_proc_macro_dependency_with_target() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["root", "proc_macro_dep"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"root/Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "root"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2017-08-29 10:43:41 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
proc_macro_dep = { path = "../proc_macro_dep" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"root/src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macro_dep;
|
2017-08-29 10:43:41 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[derive(Noop)]
|
|
|
|
pub struct X;
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"proc_macro_dep/Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2020-09-27 00:59:58 +00:00
|
|
|
name = "proc_macro_dep"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2017-08-29 10:43:41 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
2017-08-29 10:43:41 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
baz = "^0.1"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"proc_macro_dep/src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate baz;
|
|
|
|
extern crate proc_macro;
|
|
|
|
use proc_macro::TokenStream;
|
2017-08-29 10:43:41 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[proc_macro_derive(Noop)]
|
|
|
|
pub fn noop(_input: TokenStream) -> TokenStream {
|
|
|
|
"".parse().unwrap()
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-07-20 17:41:44 +00:00
|
|
|
Package::new("bar", "0.1.0").publish();
|
|
|
|
Package::new("baz", "0.1.0")
|
|
|
|
.dep("bar", "0.1")
|
|
|
|
.file("src/lib.rs", "extern crate bar;")
|
2017-08-31 17:55:19 +00:00
|
|
|
.publish();
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace --target").arg(rustc_host()).run();
|
2017-08-29 10:43:41 +00:00
|
|
|
}
|
2017-10-06 16:14:23 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-06 16:14:23 +00:00
|
|
|
fn test_hint_not_masked_by_doctest() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// assert_eq!(1, 1);
|
|
|
|
/// ```
|
|
|
|
pub fn this_works() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/integ.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[test]
|
|
|
|
fn this_fails() {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --no-fail-fast")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stdout_contains("test this_fails ... FAILED")
|
|
|
|
.with_stdout_contains("[..]this_works (line [..]ok")
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stderr_contains("[ERROR] test failed, to rerun pass `--test integ`")
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2017-10-06 16:14:23 +00:00
|
|
|
}
|
2018-02-26 00:51:48 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-06 01:52:22 +00:00
|
|
|
fn test_hint_workspace_virtual() {
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
2022-08-28 00:45:11 +00:00
|
|
|
members = ["a", "b", "c"]
|
2020-09-27 00:59:58 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("a/src/lib.rs", "#[test] fn t1() {}")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("b/src/lib.rs", "#[test] fn t1() {assert!(false)}")
|
2022-08-28 00:45:11 +00:00
|
|
|
.file("c/Cargo.toml", &basic_manifest("c", "0.1.0"))
|
|
|
|
.file(
|
|
|
|
"c/src/lib.rs",
|
|
|
|
r#"
|
|
|
|
/// ```rust
|
|
|
|
/// assert_eq!(1, 2);
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"c/src/main.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_main() { assert_eq!(1, 2); }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"c/tests/t1.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn from_int_test() { assert_eq!(1, 2); }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"c/examples/ex1.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_example() { assert_eq!(1, 2); }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
// This does not use #[bench] since it is unstable. #[test] works just
|
|
|
|
// the same for our purpose of checking the hint.
|
|
|
|
.file(
|
|
|
|
"c/benches/b1.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn from_bench() { assert_eq!(1, 2); }
|
|
|
|
"#,
|
|
|
|
)
|
2018-02-26 00:51:48 +00:00
|
|
|
.build();
|
|
|
|
|
2022-08-28 00:45:11 +00:00
|
|
|
// This depends on Units being sorted so that `b` fails first.
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stderr_unordered(
|
|
|
|
"\
|
|
|
|
[COMPILING] c v0.1.0 [..]
|
|
|
|
[COMPILING] a v0.1.0 [..]
|
|
|
|
[COMPILING] b v0.1.0 [..]
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] unittests src/lib.rs (target/debug/deps/a[..])
|
|
|
|
[RUNNING] unittests src/lib.rs (target/debug/deps/b[..])
|
|
|
|
[ERROR] test failed, to rerun pass `-p b --lib`
|
|
|
|
",
|
|
|
|
)
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2019-04-06 01:52:22 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.cwd("b")
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] unittests src/lib.rs ([ROOT]/foo/target/debug/deps/b[..])
|
|
|
|
[ERROR] test failed, to rerun pass `--lib`
|
|
|
|
",
|
|
|
|
)
|
2019-04-06 01:52:22 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2022-08-28 00:45:11 +00:00
|
|
|
p.cargo("test --no-fail-fast")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] unittests src/lib.rs (target/debug/deps/a[..])
|
|
|
|
[RUNNING] unittests src/lib.rs (target/debug/deps/b[..])
|
|
|
|
[ERROR] test failed, to rerun pass `-p b --lib`
|
|
|
|
[RUNNING] unittests src/lib.rs (target/debug/deps/c[..])
|
|
|
|
[RUNNING] unittests src/main.rs (target/debug/deps/c[..])
|
|
|
|
[ERROR] test failed, to rerun pass `-p c --bin c`
|
|
|
|
[RUNNING] tests/t1.rs (target/debug/deps/t1[..])
|
|
|
|
[ERROR] test failed, to rerun pass `-p c --test t1`
|
|
|
|
[DOCTEST] a
|
|
|
|
[DOCTEST] b
|
|
|
|
[DOCTEST] c
|
|
|
|
[ERROR] doctest failed, to rerun pass `-p c --doc`
|
|
|
|
[ERROR] 4 targets failed:
|
|
|
|
`-p b --lib`
|
|
|
|
`-p c --bin c`
|
|
|
|
`-p c --test t1`
|
|
|
|
`-p c --doc`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
// Check others that are not in the default set.
|
|
|
|
p.cargo("test -p c --examples --benches --no-fail-fast")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] c v0.1.0 [..]
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] unittests src/lib.rs (target/debug/deps/c[..])
|
|
|
|
[RUNNING] unittests src/main.rs (target/debug/deps/c[..])
|
|
|
|
[ERROR] test failed, to rerun pass `-p c --bin c`
|
|
|
|
[RUNNING] benches/b1.rs (target/debug/deps/b1[..])
|
|
|
|
[ERROR] test failed, to rerun pass `-p c --bench b1`
|
|
|
|
[RUNNING] unittests examples/ex1.rs (target/debug/examples/ex1[..])
|
|
|
|
[ERROR] test failed, to rerun pass `-p c --example ex1`
|
|
|
|
[ERROR] 3 targets failed:
|
|
|
|
`-p c --bin c`
|
|
|
|
`-p c --bench b1`
|
|
|
|
`-p c --example ex1`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run()
|
2019-04-06 01:52:22 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-06 01:52:22 +00:00
|
|
|
fn test_hint_workspace_nonvirtual() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
members = ["a"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
|
|
|
|
.file("a/src/lib.rs", "#[test] fn t1() {assert!(false)}")
|
|
|
|
.build();
|
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("test --workspace")
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stderr_contains("[ERROR] test failed, to rerun pass `-p a --lib`")
|
2019-04-06 01:52:22 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
p.cargo("test -p a")
|
2022-08-28 00:45:11 +00:00
|
|
|
.with_stderr_contains("[ERROR] test failed, to rerun pass `-p a --lib`")
|
2019-04-06 01:52:22 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2018-02-26 00:51:48 +00:00
|
|
|
}
|
2018-04-22 00:21:42 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-22 00:21:42 +00:00
|
|
|
fn json_artifact_includes_test_flag() {
|
|
|
|
// Verify that the JSON artifact output includes `test` flag.
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-22 00:21:42 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-04-22 00:21:42 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.test]
|
|
|
|
opt-level = 1
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-22 00:21:42 +00:00
|
|
|
.build();
|
|
|
|
|
2018-12-07 04:44:45 +00:00
|
|
|
p.cargo("test --lib -v --message-format=json")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_json(
|
2018-04-22 00:21:42 +00:00
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
{
|
|
|
|
"reason":"compiler-artifact",
|
|
|
|
"profile": {
|
|
|
|
"debug_assertions": true,
|
|
|
|
"debuginfo": 2,
|
|
|
|
"opt_level": "1",
|
|
|
|
"overflow_checks": true,
|
|
|
|
"test": true
|
|
|
|
},
|
|
|
|
"executable": "[..]/foo-[..]",
|
|
|
|
"features": [],
|
2024-01-17 14:44:41 +00:00
|
|
|
"package_id":"path+file:///[..]/foo#0.0.1",
|
2020-12-28 13:33:32 +00:00
|
|
|
"manifest_path": "[..]",
|
2020-09-27 00:59:58 +00:00
|
|
|
"target":{
|
|
|
|
"kind":["lib"],
|
|
|
|
"crate_types":["lib"],
|
2020-11-18 01:54:17 +00:00
|
|
|
"doc": true,
|
2020-09-27 00:59:58 +00:00
|
|
|
"doctest": true,
|
|
|
|
"edition": "2015",
|
|
|
|
"name":"foo",
|
|
|
|
"src_path":"[..]lib.rs",
|
|
|
|
"test": true
|
|
|
|
},
|
|
|
|
"filenames":"{...}",
|
|
|
|
"fresh": false
|
|
|
|
}
|
2020-04-05 01:54:20 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
{"reason": "build-finished", "success": true}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-04-22 00:21:42 +00:00
|
|
|
}
|
2018-07-11 16:27:08 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-11-30 14:31:01 +00:00
|
|
|
fn json_artifact_includes_executable_for_library_tests() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/main.rs", "fn main() { }")
|
|
|
|
.file("src/lib.rs", r#"#[test] fn lib_test() {}"#)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --lib -v --no-run --message-format=json")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_json(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
{
|
|
|
|
"executable": "[..]/foo/target/debug/deps/foo-[..][EXE]",
|
|
|
|
"features": [],
|
|
|
|
"filenames": "{...}",
|
|
|
|
"fresh": false,
|
2024-01-17 14:44:41 +00:00
|
|
|
"package_id": "path+file:///[..]/foo#0.0.1",
|
2020-12-28 13:33:32 +00:00
|
|
|
"manifest_path": "[..]",
|
2020-09-27 00:59:58 +00:00
|
|
|
"profile": "{...}",
|
|
|
|
"reason": "compiler-artifact",
|
|
|
|
"target": {
|
|
|
|
"crate_types": [ "lib" ],
|
|
|
|
"kind": [ "lib" ],
|
2020-11-18 01:54:17 +00:00
|
|
|
"doc": true,
|
2020-09-27 00:59:58 +00:00
|
|
|
"doctest": true,
|
|
|
|
"edition": "2015",
|
|
|
|
"name": "foo",
|
|
|
|
"src_path": "[..]/foo/src/lib.rs",
|
|
|
|
"test": true
|
|
|
|
}
|
2018-11-30 14:31:01 +00:00
|
|
|
}
|
2020-04-05 01:54:20 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
{"reason": "build-finished", "success": true}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2018-11-30 14:31:01 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-11-30 14:31:01 +00:00
|
|
|
fn json_artifact_includes_executable_for_integration_tests() {
|
|
|
|
let p = project()
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"tests/integration_test.rs",
|
|
|
|
r#"#[test] fn integration_test() {}"#,
|
|
|
|
)
|
2018-11-30 14:31:01 +00:00
|
|
|
.build();
|
|
|
|
|
2018-12-01 16:52:20 +00:00
|
|
|
p.cargo("test -v --no-run --message-format=json --test integration_test")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_json(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
{
|
|
|
|
"executable": "[..]/foo/target/debug/deps/integration_test-[..][EXE]",
|
|
|
|
"features": [],
|
|
|
|
"filenames": "{...}",
|
|
|
|
"fresh": false,
|
2024-01-17 14:44:41 +00:00
|
|
|
"package_id": "path+file:///[..]/foo#0.0.1",
|
2020-12-28 13:33:32 +00:00
|
|
|
"manifest_path": "[..]",
|
2020-09-27 00:59:58 +00:00
|
|
|
"profile": "{...}",
|
|
|
|
"reason": "compiler-artifact",
|
|
|
|
"target": {
|
|
|
|
"crate_types": [ "bin" ],
|
|
|
|
"kind": [ "test" ],
|
2020-11-18 01:54:17 +00:00
|
|
|
"doc": false,
|
2020-09-27 00:59:58 +00:00
|
|
|
"doctest": false,
|
|
|
|
"edition": "2015",
|
|
|
|
"name": "integration_test",
|
|
|
|
"src_path": "[..]/foo/tests/integration_test.rs",
|
|
|
|
"test": true
|
|
|
|
}
|
2018-11-30 14:31:01 +00:00
|
|
|
}
|
2020-04-05 01:54:20 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
{"reason": "build-finished", "success": true}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
2018-11-30 14:31:01 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-11 16:27:08 +00:00
|
|
|
fn test_build_script_links() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-11 16:27:08 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
links = 'something'
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
test = false
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("build.rs", "fn main() {}")
|
2018-07-11 16:27:08 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --no-run").run();
|
2018-07-11 16:27:08 +00:00
|
|
|
}
|
2018-07-26 05:40:46 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-26 05:40:46 +00:00
|
|
|
fn doctest_skip_staticlib() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["staticlib"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-07-26 05:40:46 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
//! ```
|
|
|
|
//! assert_eq!(1,2);
|
|
|
|
//! ```
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-07-26 05:40:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --doc")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
2018-08-07 20:05:22 +00:00
|
|
|
"\
|
|
|
|
[WARNING] doc tests are not supported for crate type(s) `staticlib` in package `foo`
|
|
|
|
[ERROR] no library targets found in package `foo`",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-07-26 05:40:46 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test")
|
|
|
|
.with_stderr(
|
2018-07-26 05:40:46 +00:00
|
|
|
"\
|
|
|
|
[COMPILING] foo [..]
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..])",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-07-26 05:40:46 +00:00
|
|
|
}
|
2018-09-16 20:33:32 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-16 20:33:32 +00:00
|
|
|
fn can_not_mix_doc_tests_and_regular_tests() {
|
|
|
|
let p = project()
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"\
|
2018-09-16 20:33:32 +00:00
|
|
|
/// ```
|
|
|
|
/// assert_eq!(1, 1)
|
|
|
|
/// ```
|
|
|
|
pub fn foo() -> u8 { 1 }
|
|
|
|
|
|
|
|
#[cfg(test)] mod tests {
|
|
|
|
#[test] fn it_works() { assert_eq!(2 + 2, 4); }
|
|
|
|
}
|
2018-12-08 11:19:47 +00:00
|
|
|
",
|
|
|
|
)
|
2018-09-16 20:33:32 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-09-16 20:33:32 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..])
|
2018-09-16 20:33:32 +00:00
|
|
|
[DOCTEST] foo
|
2018-12-08 11:19:47 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout(
|
|
|
|
"
|
2018-09-16 20:33:32 +00:00
|
|
|
running 1 test
|
|
|
|
test tests::it_works ... ok
|
|
|
|
|
2020-11-22 23:25:46 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
2018-09-16 20:33:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test src/lib.rs - foo (line 1) ... ok
|
|
|
|
|
2020-11-22 23:25:46 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
2018-12-08 11:19:47 +00:00
|
|
|
\n",
|
|
|
|
)
|
2018-09-16 20:33:32 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --lib")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2021-02-21 22:37:42 +00:00
|
|
|
[RUNNING] [..] (target/debug/deps/foo-[..])\n",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.with_stdout(
|
|
|
|
"
|
2018-09-16 20:33:32 +00:00
|
|
|
running 1 test
|
|
|
|
test tests::it_works ... ok
|
|
|
|
|
2020-11-22 23:25:46 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
2018-12-08 11:19:47 +00:00
|
|
|
\n",
|
|
|
|
)
|
2018-09-16 20:33:32 +00:00
|
|
|
.run();
|
|
|
|
|
2019-04-29 02:25:24 +00:00
|
|
|
// This has been modified to attempt to diagnose spurious errors on CI.
|
|
|
|
// For some reason, this is recompiling the lib when it shouldn't. If the
|
|
|
|
// root cause is ever found, the changes here should be reverted.
|
|
|
|
// See https://github.com/rust-lang/cargo/issues/6887
|
|
|
|
p.cargo("test --doc -vv")
|
|
|
|
.with_stderr_does_not_contain("[COMPILING] foo [..]")
|
|
|
|
.with_stderr_contains("[DOCTEST] foo")
|
2018-12-08 11:19:47 +00:00
|
|
|
.with_stdout(
|
|
|
|
"
|
2018-09-16 20:33:32 +00:00
|
|
|
running 1 test
|
|
|
|
test src/lib.rs - foo (line 1) ... ok
|
|
|
|
|
2020-11-22 23:25:46 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]
|
2018-09-16 20:33:32 +00:00
|
|
|
|
2018-12-08 11:19:47 +00:00
|
|
|
",
|
|
|
|
)
|
2019-01-27 18:34:11 +00:00
|
|
|
.env("CARGO_LOG", "cargo=trace")
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2018-09-16 20:33:32 +00:00
|
|
|
|
|
|
|
p.cargo("test --lib --doc")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] Can't mix --doc with other target selecting options\n")
|
|
|
|
.run();
|
|
|
|
}
|
2018-09-17 02:41:57 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-02-04 14:11:58 +00:00
|
|
|
fn can_not_no_run_doc_tests() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
/// ```
|
|
|
|
/// let _x = 1 + "foo";
|
|
|
|
/// ```
|
|
|
|
pub fn foo() -> u8 { 1 }
|
|
|
|
"#,
|
2019-02-04 14:11:58 +00:00
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --doc --no-run")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr("[ERROR] Can't skip running doc tests with --no-run")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-17 02:41:57 +00:00
|
|
|
fn test_all_targets_lib() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
p.cargo("test --all-targets")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo [..]
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [..]
|
2018-09-17 02:41:57 +00:00
|
|
|
[RUNNING] [..]foo[..]
|
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-09-17 02:41:57 +00:00
|
|
|
}
|
2018-10-20 01:04:36 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-10-20 01:04:36 +00:00
|
|
|
fn test_dep_with_dev() {
|
|
|
|
Package::new("devdep", "0.1.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2018-10-20 01:04:36 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
"#,
|
2018-10-20 01:04:36 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
2018-10-20 01:04:36 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dev-dependencies]
|
|
|
|
devdep = "0.1"
|
|
|
|
"#,
|
2018-10-20 01:04:36 +00:00
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -p bar")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(
|
|
|
|
"[ERROR] package `bar` cannot be tested because it requires dev-dependencies \
|
|
|
|
and is not a member of the workspace",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2019-09-12 18:08:29 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
|
2019-09-12 18:08:29 +00:00
|
|
|
fn cargo_test_doctest_xcompile_ignores() {
|
2020-02-08 02:02:52 +00:00
|
|
|
// -Zdoctest-xcompile also enables --enable-per-target-ignores which
|
|
|
|
// allows the ignore-TARGET syntax.
|
2019-09-12 18:08:29 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
///```ignore-x86_64
|
|
|
|
///assert!(cfg!(not(target_arch = "x86_64")));
|
|
|
|
///```
|
|
|
|
pub fn foo() -> u8 {
|
|
|
|
4
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build").run();
|
|
|
|
#[cfg(not(target_arch = "x86_64"))]
|
|
|
|
p.cargo("test")
|
|
|
|
.with_stdout_contains(
|
2020-11-22 23:25:46 +00:00
|
|
|
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
p.cargo("test")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stdout_contains(
|
2020-11-22 23:25:46 +00:00
|
|
|
"test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out[..]",
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
#[cfg(not(target_arch = "x86_64"))]
|
|
|
|
p.cargo("test -Zdoctest-xcompile")
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
|
2019-09-12 18:08:29 +00:00
|
|
|
.with_stdout_contains(
|
2020-11-22 23:25:46 +00:00
|
|
|
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
p.cargo("test -Zdoctest-xcompile")
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
|
2019-09-12 18:08:29 +00:00
|
|
|
.with_stdout_contains(
|
2020-11-22 23:25:46 +00:00
|
|
|
"test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out[..]",
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
|
2019-09-12 18:08:29 +00:00
|
|
|
fn cargo_test_doctest_xcompile() {
|
2020-02-08 02:02:52 +00:00
|
|
|
if !cross_compile::can_run_on_host() {
|
2019-09-21 23:30:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-12 18:08:29 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
|
|
|
|
///```
|
|
|
|
///assert!(1 == 1);
|
|
|
|
///```
|
|
|
|
pub fn foo() -> u8 {
|
|
|
|
4
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build").run();
|
|
|
|
p.cargo(&format!("test --target {}", cross_compile::alternate()))
|
2019-09-21 23:30:38 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
2019-09-12 18:08:29 +00:00
|
|
|
.run();
|
|
|
|
p.cargo(&format!(
|
|
|
|
"test --target {} -Zdoctest-xcompile",
|
|
|
|
cross_compile::alternate()
|
|
|
|
))
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
|
2019-09-12 18:08:29 +00:00
|
|
|
.with_stdout_contains(
|
2020-11-22 23:25:46 +00:00
|
|
|
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
|
2019-09-12 18:08:29 +00:00
|
|
|
fn cargo_test_doctest_xcompile_runner() {
|
2020-02-08 02:02:52 +00:00
|
|
|
if !cross_compile::can_run_on_host() {
|
2019-09-21 23:30:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-12 18:08:29 +00:00
|
|
|
|
|
|
|
let runner = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("runner"))
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
pub fn main() {
|
|
|
|
eprintln!("this is a runner");
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
std::process::Command::new(&args[1]).spawn();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
runner.cargo("build").run();
|
|
|
|
assert!(runner.bin("runner").is_file());
|
|
|
|
let runner_path = paths::root().join("runner");
|
|
|
|
fs::copy(&runner.bin("runner"), &runner_path).unwrap();
|
|
|
|
|
|
|
|
let config = paths::root().join(".cargo/config");
|
|
|
|
|
|
|
|
fs::create_dir_all(config.parent().unwrap()).unwrap();
|
2019-10-23 15:14:40 +00:00
|
|
|
// Escape Windows backslashes for TOML config.
|
|
|
|
let runner_str = runner_path.to_str().unwrap().replace('\\', "\\\\");
|
|
|
|
fs::write(
|
|
|
|
config,
|
|
|
|
format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.'cfg(target_arch = "{}")']
|
|
|
|
runner = "{}"
|
|
|
|
"#,
|
2020-02-08 02:02:52 +00:00
|
|
|
cross_compile::alternate_arch(),
|
2019-10-23 15:14:40 +00:00
|
|
|
runner_str
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2019-09-12 18:08:29 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
2020-02-08 02:02:52 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
///```
|
|
|
|
///assert!(cfg!(target_arch = "{}"));
|
|
|
|
///```
|
|
|
|
pub fn foo() -> u8 {{
|
|
|
|
4
|
|
|
|
}}
|
|
|
|
"#,
|
|
|
|
cross_compile::alternate_arch()
|
|
|
|
),
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build").run();
|
|
|
|
p.cargo(&format!("test --target {}", cross_compile::alternate()))
|
2019-09-21 23:30:38 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
2019-09-12 18:08:29 +00:00
|
|
|
.run();
|
|
|
|
p.cargo(&format!(
|
|
|
|
"test --target {} -Zdoctest-xcompile",
|
|
|
|
cross_compile::alternate()
|
|
|
|
))
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
|
2019-09-12 18:08:29 +00:00
|
|
|
.with_stdout_contains(
|
2020-11-22 23:25:46 +00:00
|
|
|
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
2019-09-21 23:30:38 +00:00
|
|
|
.with_stderr_contains("this is a runner")
|
2019-09-12 18:08:29 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zdoctest-xcompile is unstable")]
|
2019-09-12 18:08:29 +00:00
|
|
|
fn cargo_test_doctest_xcompile_no_runner() {
|
2020-02-08 02:02:52 +00:00
|
|
|
if !cross_compile::can_run_on_host() {
|
2019-09-21 23:30:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-12 18:08:29 +00:00
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
2020-02-08 02:02:52 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
///```
|
|
|
|
///assert!(cfg!(target_arch = "{}"));
|
|
|
|
///```
|
|
|
|
pub fn foo() -> u8 {{
|
|
|
|
4
|
|
|
|
}}
|
|
|
|
"#,
|
|
|
|
cross_compile::alternate_arch()
|
|
|
|
),
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("build").run();
|
|
|
|
p.cargo(&format!("test --target {}", cross_compile::alternate()))
|
2019-09-21 23:30:38 +00:00
|
|
|
.with_stdout_contains("running 0 tests")
|
2019-09-12 18:08:29 +00:00
|
|
|
.run();
|
|
|
|
p.cargo(&format!(
|
|
|
|
"test --target {} -Zdoctest-xcompile",
|
|
|
|
cross_compile::alternate()
|
|
|
|
))
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
|
2019-09-12 18:08:29 +00:00
|
|
|
.with_stdout_contains(
|
2020-11-22 23:25:46 +00:00
|
|
|
"test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out[..]",
|
2019-09-12 18:08:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2019-09-30 15:48:43 +00:00
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zpanic-abort-tests in rustc is unstable")]
|
2019-09-30 15:48:43 +00:00
|
|
|
fn panic_abort_tests() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = 'a' }
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
panic = 'abort'
|
|
|
|
[profile.test]
|
|
|
|
panic = 'abort'
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn foo() {
|
|
|
|
a::foo();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_lib_manifest("a"))
|
|
|
|
.file("a/src/lib.rs", "pub fn foo() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -Z panic-abort-tests -v")
|
|
|
|
.with_stderr_contains("[..]--crate-name a [..]-C panic=abort[..]")
|
|
|
|
.with_stderr_contains("[..]--crate-name foo [..]-C panic=abort[..]")
|
|
|
|
.with_stderr_contains("[..]--crate-name foo [..]-C panic=abort[..]--test[..]")
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["panic-abort-tests"])
|
2019-09-30 15:48:43 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zpanic-abort-tests in rustc is unstable")]
|
2019-09-30 15:48:43 +00:00
|
|
|
fn panic_abort_only_test() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = 'a' }
|
|
|
|
|
|
|
|
[profile.test]
|
|
|
|
panic = 'abort'
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn foo() {
|
|
|
|
a::foo();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_lib_manifest("a"))
|
|
|
|
.file("a/src/lib.rs", "pub fn foo() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -Z panic-abort-tests -v")
|
2019-10-18 13:39:57 +00:00
|
|
|
.with_stderr_contains("warning: `panic` setting is ignored for `test` profile")
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["panic-abort-tests"])
|
2019-09-30 15:48:43 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
#[cargo_test(nightly, reason = "-Zpanic-abort-tests in rustc is unstable")]
|
2019-10-18 13:39:57 +00:00
|
|
|
fn panic_abort_test_profile_inherits() {
|
2019-09-30 15:48:43 +00:00
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = 'foo'
|
|
|
|
version = '0.1.0'
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
a = { path = 'a' }
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
panic = 'abort'
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn foo() {
|
|
|
|
a::foo();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_lib_manifest("a"))
|
|
|
|
.file("a/src/lib.rs", "pub fn foo() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -Z panic-abort-tests -v")
|
2022-07-16 02:32:23 +00:00
|
|
|
.masquerade_as_nightly_cargo(&["panic-abort-tests"])
|
2019-10-18 13:39:57 +00:00
|
|
|
.with_status(0)
|
2019-09-30 15:48:43 +00:00
|
|
|
.run();
|
|
|
|
}
|
2019-12-11 16:26:08 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn bin_env_for_test() {
|
2022-09-26 07:28:16 +00:00
|
|
|
// Test for the `CARGO_BIN_EXE_` environment variables for tests.
|
2019-12-11 16:26:08 +00:00
|
|
|
//
|
|
|
|
// Note: The Unicode binary uses a `[[bin]]` definition because different
|
|
|
|
// filesystems normalize utf-8 in different ways. For example, HFS uses
|
|
|
|
// "gru\u{308}ßen" and APFS uses "gr\u{fc}ßen". Defining it in TOML forces
|
|
|
|
// one form to be used.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = 'grüßen'
|
|
|
|
path = 'src/bin/grussen.rs'
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/bin/foo.rs", "fn main() {}")
|
|
|
|
.file("src/bin/with-dash.rs", "fn main() {}")
|
|
|
|
.file("src/bin/grussen.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let bin_path = |name| p.bin(name).to_string_lossy().replace("\\", "\\\\");
|
|
|
|
p.change_file(
|
|
|
|
"tests/check_env.rs",
|
|
|
|
&r#"
|
|
|
|
#[test]
|
|
|
|
fn run_bins() {
|
2020-02-06 16:30:09 +00:00
|
|
|
assert_eq!(env!("CARGO_BIN_EXE_foo"), "<FOO_PATH>");
|
|
|
|
assert_eq!(env!("CARGO_BIN_EXE_with-dash"), "<WITH_DASH_PATH>");
|
|
|
|
assert_eq!(env!("CARGO_BIN_EXE_grüßen"), "<GRÜSSEN_PATH>");
|
2019-12-11 16:26:08 +00:00
|
|
|
}
|
|
|
|
"#
|
|
|
|
.replace("<FOO_PATH>", &bin_path("foo"))
|
|
|
|
.replace("<WITH_DASH_PATH>", &bin_path("with-dash"))
|
|
|
|
.replace("<GRÜSSEN_PATH>", &bin_path("grüßen")),
|
|
|
|
);
|
|
|
|
|
|
|
|
p.cargo("test --test check_env").run();
|
|
|
|
p.cargo("check --test check_env").run();
|
|
|
|
}
|
2021-01-02 13:34:21 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn test_workspaces_cwd() {
|
|
|
|
// This tests that all the different test types are executed from the
|
|
|
|
// crate directory (manifest_dir), and not from the workspace root.
|
|
|
|
|
|
|
|
let make_lib_file = |expected| {
|
|
|
|
format!(
|
|
|
|
r#"
|
|
|
|
//! ```
|
|
|
|
//! assert_eq!("{expected}", std::fs::read_to_string("file.txt").unwrap());
|
2021-02-22 19:06:03 +00:00
|
|
|
//! assert_eq!("{expected}", include_str!("../file.txt"));
|
2021-01-02 13:34:21 +00:00
|
|
|
//! assert_eq!(
|
|
|
|
//! std::path::PathBuf::from(std::env!("CARGO_MANIFEST_DIR")),
|
|
|
|
//! std::env::current_dir().unwrap(),
|
|
|
|
//! );
|
|
|
|
//! ```
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unit_{expected}_cwd() {{
|
|
|
|
assert_eq!("{expected}", std::fs::read_to_string("file.txt").unwrap());
|
2021-02-22 19:06:03 +00:00
|
|
|
assert_eq!("{expected}", include_str!("../file.txt"));
|
2021-01-02 13:34:21 +00:00
|
|
|
assert_eq!(
|
|
|
|
std::path::PathBuf::from(std::env!("CARGO_MANIFEST_DIR")),
|
|
|
|
std::env::current_dir().unwrap(),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
"#,
|
|
|
|
expected = expected
|
|
|
|
)
|
|
|
|
};
|
|
|
|
let make_test_file = |expected| {
|
|
|
|
format!(
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn test_integration_{expected}_cwd() {{
|
|
|
|
assert_eq!("{expected}", std::fs::read_to_string("file.txt").unwrap());
|
2021-02-22 19:06:03 +00:00
|
|
|
assert_eq!("{expected}", include_str!("../file.txt"));
|
2021-01-02 13:34:21 +00:00
|
|
|
assert_eq!(
|
|
|
|
std::path::PathBuf::from(std::env!("CARGO_MANIFEST_DIR")),
|
|
|
|
std::env::current_dir().unwrap(),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
"#,
|
|
|
|
expected = expected
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "root-crate"
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
members = [".", "nested-crate", "very/deeply/nested/deep-crate"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("file.txt", "root")
|
|
|
|
.file("src/lib.rs", &make_lib_file("root"))
|
|
|
|
.file("tests/integration.rs", &make_test_file("root"))
|
|
|
|
.file(
|
|
|
|
"nested-crate/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "nested-crate"
|
|
|
|
version = "0.0.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("nested-crate/file.txt", "nested")
|
|
|
|
.file("nested-crate/src/lib.rs", &make_lib_file("nested"))
|
|
|
|
.file(
|
|
|
|
"nested-crate/tests/integration.rs",
|
|
|
|
&make_test_file("nested"),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"very/deeply/nested/deep-crate/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "deep-crate"
|
|
|
|
version = "0.0.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("very/deeply/nested/deep-crate/file.txt", "deep")
|
|
|
|
.file(
|
|
|
|
"very/deeply/nested/deep-crate/src/lib.rs",
|
|
|
|
&make_lib_file("deep"),
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"very/deeply/nested/deep-crate/tests/integration.rs",
|
|
|
|
&make_test_file("deep"),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --workspace --all")
|
|
|
|
.with_stderr_contains("[DOCTEST] root-crate")
|
|
|
|
.with_stderr_contains("[DOCTEST] nested-crate")
|
|
|
|
.with_stderr_contains("[DOCTEST] deep-crate")
|
|
|
|
.with_stdout_contains("test test_unit_root_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_unit_nested_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_unit_deep_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_root_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_nested_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_deep_cwd ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test -p root-crate --all")
|
|
|
|
.with_stderr_contains("[DOCTEST] root-crate")
|
|
|
|
.with_stdout_contains("test test_unit_root_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_root_cwd ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test -p nested-crate --all")
|
|
|
|
.with_stderr_contains("[DOCTEST] nested-crate")
|
|
|
|
.with_stdout_contains("test test_unit_nested_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_nested_cwd ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test -p deep-crate --all")
|
|
|
|
.with_stderr_contains("[DOCTEST] deep-crate")
|
|
|
|
.with_stdout_contains("test test_unit_deep_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_deep_cwd ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --all")
|
|
|
|
.cwd("nested-crate")
|
|
|
|
.with_stderr_contains("[DOCTEST] nested-crate")
|
|
|
|
.with_stdout_contains("test test_unit_nested_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_nested_cwd ... ok")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --all")
|
|
|
|
.cwd("very/deeply/nested/deep-crate")
|
|
|
|
.with_stderr_contains("[DOCTEST] deep-crate")
|
|
|
|
.with_stdout_contains("test test_unit_deep_cwd ... ok")
|
|
|
|
.with_stdout_contains("test test_integration_deep_cwd ... ok")
|
|
|
|
.run();
|
|
|
|
}
|
2022-08-28 00:45:11 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn execution_error() {
|
|
|
|
// Checks the behavior when a test fails to launch.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"tests/t1.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
let key = format!("CARGO_TARGET_{}_RUNNER", rustc_host_env());
|
|
|
|
p.cargo("test")
|
|
|
|
.env(&key, "does_not_exist")
|
|
|
|
// The actual error is usually "no such file", but on Windows it has a
|
|
|
|
// custom message. Since matching against the error string produced by
|
|
|
|
// Rust is not very reliable, this just uses `[..]`.
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 [..]
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] tests/t1.rs (target/debug/deps/t1[..])
|
|
|
|
error: test failed, to rerun pass `--test t1`
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
could not execute process `does_not_exist [ROOT]/foo/target/debug/deps/t1[..]` (never executed)
|
|
|
|
|
|
|
|
Caused by:
|
|
|
|
[..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn nonzero_exit_status() {
|
|
|
|
// Tests for nonzero exit codes from tests.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"tests/t1.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn t() { panic!("this is a normal error") }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/t2.rs",
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn t() { std::process::exit(4) }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test --test t1")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo [..]
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] tests/t1.rs (target/debug/deps/t1[..])
|
|
|
|
error: test failed, to rerun pass `--test t1`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_stdout_contains("[..]this is a normal error[..]")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --test t2")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 [..]
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
|
|
|
|
error: test failed, to rerun pass `--test t2`
|
|
|
|
|
2023-08-07 22:02:48 +00:00
|
|
|
Caused by:
|
|
|
|
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
|
2023-08-09 19:40:19 +00:00
|
|
|
note: test exited abnormally; to see the full output pass --nocapture to the harness.
|
2023-08-07 22:02:48 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(4)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --test t2 -- --nocapture")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
|
|
|
|
error: test failed, to rerun pass `--test t2`
|
|
|
|
|
2022-08-28 00:45:11 +00:00
|
|
|
Caused by:
|
|
|
|
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(4)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// no-fail-fast always uses 101
|
|
|
|
p.cargo("test --no-fail-fast")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[FINISHED] test [..]
|
|
|
|
[RUNNING] tests/t1.rs (target/debug/deps/t1[..])
|
|
|
|
error: test failed, to rerun pass `--test t1`
|
|
|
|
[RUNNING] tests/t2.rs (target/debug/deps/t2[..])
|
|
|
|
error: test failed, to rerun pass `--test t2`
|
|
|
|
|
2023-08-07 22:02:48 +00:00
|
|
|
Caused by:
|
|
|
|
process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)
|
2023-08-09 19:40:19 +00:00
|
|
|
note: test exited abnormally; to see the full output pass --nocapture to the harness.
|
2023-08-07 22:02:48 +00:00
|
|
|
error: 2 targets failed:
|
|
|
|
`--test t1`
|
|
|
|
`--test t2`
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("test --no-fail-fast -- --nocapture")
|
2023-08-09 19:40:19 +00:00
|
|
|
.with_stderr_does_not_contain("test exited abnormally; to see the full output pass --nocapture to the harness.")
|
|
|
|
.with_stderr_contains("[..]thread 't' panicked [..] tests/t1[..]")
|
|
|
|
.with_stderr_contains("note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace")
|
|
|
|
.with_stderr_contains("[..]process didn't exit successfully: `[ROOT]/foo/target/debug/deps/t2[..]` (exit [..]: 4)")
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
2022-08-28 00:45:11 +00:00
|
|
|
}
|
2023-08-11 13:12:59 +00:00
|
|
|
|
2023-08-15 11:44:08 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn cargo_test_print_env_verbose() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "0.0.1"))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -vv")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name foo[..]`
|
|
|
|
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustc --crate-name foo[..]`
|
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] [CWD]/target/debug/deps/foo-[..][EXE]`
|
|
|
|
[DOCTEST] foo
|
|
|
|
[RUNNING] `[..]CARGO_MANIFEST_DIR=[CWD][..] rustdoc --crate-type lib --crate-name foo[..]",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2023-12-25 12:21:26 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn cargo_test_set_out_dir_env_var() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
edition = "2021"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn add(left: usize, right: usize) -> usize {
|
|
|
|
left + right
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/case.rs",
|
|
|
|
r#"
|
|
|
|
#[cfg(test)]
|
|
|
|
pub mod tests {
|
|
|
|
#[test]
|
|
|
|
fn test_add() {
|
|
|
|
assert!(std::env::var("OUT_DIR").is_ok());
|
|
|
|
assert_eq!(foo::add(2, 5), 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test").run();
|
|
|
|
p.cargo("test --package foo --test case -- tests::test_add --exact --nocapture")
|
|
|
|
.run();
|
|
|
|
}
|