2014-07-10 19:39:05 +00:00
|
|
|
use std::str;
|
|
|
|
|
2014-07-21 00:02:09 +00:00
|
|
|
use support::{project, execs, basic_bin_manifest, basic_lib_manifest};
|
2015-02-27 01:04:25 +00:00
|
|
|
use support::{COMPILING, RUNNING, DOCTEST};
|
|
|
|
use support::paths::CargoPathExt;
|
2015-03-21 02:31:12 +00:00
|
|
|
use hamcrest::{assert_that, existing_file, is_not};
|
2014-06-26 22:14:31 +00:00
|
|
|
use cargo::util::process;
|
|
|
|
|
|
|
|
fn setup() {}
|
|
|
|
|
|
|
|
test!(cargo_test_simple {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())
|
|
|
|
.file("src/foo.rs", r#"
|
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
assert_eq!(hello(), "hello")
|
|
|
|
}"#);
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("build"), execs());
|
2014-06-26 22:14:31 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(process(&p.bin("foo")).unwrap(),
|
|
|
|
execs().with_stdout("hello\n"));
|
2014-06-26 22:14:31 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
|
|
|
execs().with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{} foo v0.5.0 ({})
|
2014-10-31 18:17:29 +00:00
|
|
|
{} target[..]foo-[..]
|
2014-08-01 03:21:13 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test_hello ... ok
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-06 16:21:10 +00:00
|
|
|
COMPILING, p.url(),
|
2014-08-01 03:21:13 +00:00
|
|
|
RUNNING)));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2014-08-07 15:27:05 +00:00
|
|
|
test!(cargo_test_verbose {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())
|
|
|
|
.file("src/foo.rs", r#"
|
|
|
|
fn main() {}
|
|
|
|
#[test] fn test_hello() {}
|
|
|
|
"#);
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test").arg("-v").arg("hello"),
|
2014-08-07 15:27:05 +00:00
|
|
|
execs().with_stdout(format!("\
|
|
|
|
{compiling} foo v0.5.0 ({url})
|
2014-09-11 14:35:01 +00:00
|
|
|
{running} `rustc src[..]foo.rs [..]`
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} `[..]target[..]foo-[..] hello`
|
2014-08-07 15:27:05 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test_hello ... ok
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-07 15:27:05 +00:00
|
|
|
compiling = COMPILING, url = p.url(), running = RUNNING)));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-08-07 15:27:05 +00:00
|
|
|
|
2014-07-23 18:44:15 +00:00
|
|
|
test!(many_similar_names {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
pub fn foo() {}
|
|
|
|
#[test] fn lib_test() {}
|
|
|
|
")
|
|
|
|
.file("src/main.rs", "
|
|
|
|
extern crate foo;
|
|
|
|
fn main() {}
|
|
|
|
#[test] fn bin_test() { foo::foo() }
|
|
|
|
")
|
|
|
|
.file("tests/foo.rs", r#"
|
|
|
|
extern crate foo;
|
|
|
|
#[test] fn test_test() { foo::foo() }
|
|
|
|
"#);
|
|
|
|
|
2015-03-21 03:23:53 +00:00
|
|
|
let output = p.cargo_process("test").arg("-v").exec_with_output().unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
let output = str::from_utf8(&output.stdout).unwrap();
|
2014-07-23 18:44:15 +00:00
|
|
|
assert!(output.contains("test bin_test"), "bin_test missing\n{}", output);
|
|
|
|
assert!(output.contains("test lib_test"), "lib_test missing\n{}", output);
|
|
|
|
assert!(output.contains("test test_test"), "test_test missing\n{}", output);
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-23 18:44:15 +00:00
|
|
|
|
2014-07-21 19:23:01 +00:00
|
|
|
test!(cargo_test_failing_test {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())
|
|
|
|
.file("src/foo.rs", r#"
|
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_hello() {
|
|
|
|
assert_eq!(hello(), "nope")
|
|
|
|
}"#);
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("build"), execs());
|
2014-07-21 19:23:01 +00:00
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(process(&p.bin("foo")).unwrap(),
|
|
|
|
execs().with_stdout("hello\n"));
|
2014-07-21 19:23:01 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
|
|
|
execs().with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{} foo v0.5.0 ({})
|
2014-10-31 18:17:29 +00:00
|
|
|
{} target[..]foo-[..]
|
2014-08-01 03:21:13 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test_hello ... FAILED
|
|
|
|
|
|
|
|
failures:
|
|
|
|
|
|
|
|
---- test_hello stdout ----
|
2014-12-21 18:45:39 +00:00
|
|
|
<tab>thread 'test_hello' panicked at 'assertion failed: \
|
2014-08-01 03:21:13 +00:00
|
|
|
`(left == right) && (right == left)` (left: \
|
2015-02-27 01:04:25 +00:00
|
|
|
`\"hello\"`, right: `\"nope\"`)', src[..]foo.rs:12
|
2014-12-02 03:11:20 +00:00
|
|
|
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
|
|
|
|
failures:
|
|
|
|
test_hello
|
|
|
|
|
|
|
|
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2015-02-27 01:04:25 +00:00
|
|
|
COMPILING, p.url(), RUNNING))
|
2014-07-23 19:49:32 +00:00
|
|
|
.with_stderr(format!("\
|
2014-12-21 18:45:39 +00:00
|
|
|
thread '<main>' panicked at 'Some tests failed', [..]
|
2015-01-25 06:03:42 +00:00
|
|
|
|
2014-08-11 04:48:43 +00:00
|
|
|
"))
|
2014-07-23 19:49:32 +00:00
|
|
|
.with_status(101));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-09 20:08:44 +00:00
|
|
|
|
|
|
|
test!(test_with_lib_dep {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-07-17 01:44:30 +00:00
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "baz"
|
|
|
|
path = "src/main.rs"
|
2014-07-09 20:08:44 +00:00
|
|
|
"#)
|
2014-08-01 03:21:13 +00:00
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// extern crate foo;
|
|
|
|
/// fn main() {
|
2015-01-13 16:41:04 +00:00
|
|
|
/// println!("{:?}", foo::foo());
|
2014-08-01 03:21:13 +00:00
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
2014-07-10 19:08:13 +00:00
|
|
|
pub fn foo(){}
|
|
|
|
#[test] fn lib_test() {}
|
2014-08-01 03:21:13 +00:00
|
|
|
"#)
|
2014-07-09 20:08:44 +00:00
|
|
|
.file("src/main.rs", "
|
|
|
|
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() {}
|
2014-07-09 20:08:44 +00:00
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-08-01 03:21:13 +00:00
|
|
|
execs().with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{} foo v0.0.1 ({})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]baz-[..]
|
2014-07-10 19:08:13 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test bin_test ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-10-31 18:17:29 +00:00
|
|
|
{running} target[..]foo[..]
|
2014-08-01 03:21:13 +00:00
|
|
|
|
2014-07-10 19:08:13 +00:00
|
|
|
running 1 test
|
|
|
|
test lib_test ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
2014-07-10 19:39:05 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
{doctest} foo
|
2014-07-10 19:08:13 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
running 1 test
|
|
|
|
test foo_0 ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-06 16:21:10 +00:00
|
|
|
COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-09 20:55:00 +00:00
|
|
|
|
|
|
|
test!(test_with_deep_lib_dep {
|
2014-07-10 18:50:03 +00:00
|
|
|
let p = project("bar")
|
2014-07-09 20:55:00 +00:00
|
|
|
.file("Cargo.toml", r#"
|
2014-07-10 18:50:03 +00:00
|
|
|
[package]
|
2014-07-09 20:55:00 +00:00
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.foo]
|
2014-07-10 18:50:03 +00:00
|
|
|
path = "../foo"
|
2014-07-09 20:55:00 +00:00
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
extern crate foo;
|
2014-08-19 20:10:55 +00:00
|
|
|
/// ```
|
|
|
|
/// bar::bar();
|
|
|
|
/// ```
|
|
|
|
pub fn bar() {}
|
|
|
|
|
2014-07-10 18:50:03 +00:00
|
|
|
#[test]
|
|
|
|
fn bar_test() {
|
|
|
|
foo::foo();
|
|
|
|
}
|
|
|
|
");
|
|
|
|
let p2 = project("foo")
|
2014-07-09 20:55:00 +00:00
|
|
|
.file("Cargo.toml", r#"
|
2014-07-10 18:50:03 +00:00
|
|
|
[package]
|
2014-07-09 20:55:00 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
2014-07-10 18:50:03 +00:00
|
|
|
.file("src/lib.rs", "
|
|
|
|
pub fn foo() {}
|
2014-07-09 20:55:00 +00:00
|
|
|
|
2014-07-10 18:50:03 +00:00
|
|
|
#[test]
|
|
|
|
fn foo_test() {}
|
|
|
|
");
|
|
|
|
|
|
|
|
p2.build();
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-07-10 18:50:03 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{compiling} foo v0.0.1 ({dir})
|
|
|
|
{compiling} bar v0.0.1 ({dir})
|
2014-08-01 03:21:13 +00:00
|
|
|
{running} target[..]
|
2014-07-10 18:50:03 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test bar_test ... ok
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-19 20:10:55 +00:00
|
|
|
{doctest} bar
|
|
|
|
|
2014-12-31 20:02:18 +00:00
|
|
|
running 1 test
|
|
|
|
test bar_0 ... ok
|
2014-08-19 20:10:55 +00:00
|
|
|
|
2014-12-31 20:02:18 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
2014-08-19 20:10:55 +00:00
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
",
|
2014-08-01 03:21:13 +00:00
|
|
|
compiling = COMPILING, running = RUNNING,
|
2014-08-19 20:10:55 +00:00
|
|
|
doctest = DOCTEST,
|
2014-08-06 16:21:10 +00:00
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-11 00:08:19 +00:00
|
|
|
|
|
|
|
test!(external_test_explicit {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "test"
|
|
|
|
path = "src/test.rs"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn internal_test() {}
|
|
|
|
"#)
|
|
|
|
.file("src/test.rs", r#"
|
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(foo::get_hello(), "Hello") }
|
|
|
|
"#);
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-08-01 03:21:13 +00:00
|
|
|
execs().with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{} foo v0.0.1 ({})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-11 00:08:19 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test internal_test ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]test-[..]
|
2014-08-01 03:21:13 +00:00
|
|
|
|
2014-07-11 00:08:19 +00:00
|
|
|
running 1 test
|
|
|
|
test external_test ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
{doctest} foo
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
running 0 tests
|
|
|
|
|
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-06 16:21:10 +00:00
|
|
|
COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-11 00:08:19 +00:00
|
|
|
|
|
|
|
test!(external_test_implicit {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
pub fn get_hello() -> &'static str { "Hello" }
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn internal_test() {}
|
|
|
|
"#)
|
2014-07-13 12:45:26 +00:00
|
|
|
.file("tests/external.rs", r#"
|
2014-07-11 00:08:19 +00:00
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_test() { assert_eq!(foo::get_hello(), "Hello") }
|
|
|
|
"#);
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-08-01 03:21:13 +00:00
|
|
|
execs().with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{} foo v0.0.1 ({})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]external-[..]
|
2014-07-11 00:08:19 +00:00
|
|
|
|
|
|
|
running 1 test
|
2014-08-01 03:21:13 +00:00
|
|
|
test external_test ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-11 00:08:19 +00:00
|
|
|
|
|
|
|
running 1 test
|
2014-08-01 03:21:13 +00:00
|
|
|
test internal_test ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} foo
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
running 0 tests
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
2014-07-11 00:08:19 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
",
|
2014-08-06 16:21:10 +00:00
|
|
|
COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-11 20:34:50 +00:00
|
|
|
|
|
|
|
test!(dont_run_examples {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
"#)
|
|
|
|
.file("examples/dont-run-me-i-will-fail.rs", r#"
|
2014-10-30 01:59:06 +00:00
|
|
|
fn main() { panic!("Examples should not be run by 'cargo test'"); }
|
2014-07-11 20:34:50 +00:00
|
|
|
"#);
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-07-11 20:34:50 +00:00
|
|
|
execs().with_status(0));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-10 20:53:36 +00:00
|
|
|
|
|
|
|
test!(pass_through_command_line {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
#[test] fn foo() {}
|
|
|
|
#[test] fn bar() {}
|
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test").arg("bar"),
|
2014-07-10 20:53:36 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{compiling} foo v0.0.1 ({dir})
|
2014-10-31 18:17:29 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-10 20:53:36 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test bar ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-01 03:21:13 +00:00
|
|
|
compiling = COMPILING, running = RUNNING,
|
|
|
|
doctest = DOCTEST,
|
2014-08-06 16:21:10 +00:00
|
|
|
dir = p.url()).as_slice()));
|
2014-07-10 20:53:36 +00:00
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test").arg("foo"),
|
2014-07-10 20:53:36 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{compiling} foo v0.0.1 ({dir})
|
2014-10-31 18:17:29 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-10 20:53:36 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-01 03:21:13 +00:00
|
|
|
compiling = COMPILING, running = RUNNING,
|
|
|
|
doctest = DOCTEST,
|
2014-08-06 16:21:10 +00:00
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-21 00:02:09 +00:00
|
|
|
|
|
|
|
// Regression test for running cargo-test twice with
|
|
|
|
// tests in an rlib
|
|
|
|
test!(cargo_test_twice {
|
|
|
|
let p = project("test_twice")
|
|
|
|
.file("Cargo.toml", basic_lib_manifest("test_twice").as_slice())
|
|
|
|
.file("src/test_twice.rs", r#"
|
|
|
|
#![crate_type = "rlib"]
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dummy_test() { }
|
|
|
|
"#);
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
p.cargo_process("build");
|
2014-07-21 00:02:09 +00:00
|
|
|
|
2015-03-22 23:58:11 +00:00
|
|
|
for _ in 0..2 {
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
2014-07-21 00:02:09 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
}
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-22 14:45:46 +00:00
|
|
|
|
|
|
|
test!(lib_bin_same_name {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-22 14:45:46 +00:00
|
|
|
name = "foo"
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
#[test] fn lib_test() {}
|
|
|
|
")
|
|
|
|
.file("src/main.rs", "
|
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bin_test() {}
|
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-08-01 03:21:13 +00:00
|
|
|
execs().with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{} foo v0.0.1 ({})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-22 14:45:46 +00:00
|
|
|
|
|
|
|
running 1 test
|
2014-08-01 03:21:13 +00:00
|
|
|
test [..] ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-22 14:45:46 +00:00
|
|
|
|
|
|
|
running 1 test
|
2014-08-01 03:21:13 +00:00
|
|
|
test [..] ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
{doctest} foo
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
running 0 tests
|
2014-07-22 14:45:46 +00:00
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-06 16:21:10 +00:00
|
|
|
COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-23 00:53:38 +00:00
|
|
|
|
|
|
|
test!(lib_with_standard_name {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.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() {}
|
2014-07-23 00:53:38 +00:00
|
|
|
")
|
|
|
|
.file("tests/test.rs", "
|
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-07-23 00:53:38 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{compiling} syntax v0.0.1 ({dir})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]syntax-[..]
|
2014-08-07 15:26:38 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo_test ... ok
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
2014-08-07 15:26:38 +00:00
|
|
|
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]test-[..]
|
2014-07-23 00:53:38 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test ... ok
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
2014-08-07 15:26:38 +00:00
|
|
|
|
|
|
|
{doctest} syntax
|
|
|
|
|
2014-12-31 20:02:18 +00:00
|
|
|
running 1 test
|
|
|
|
test foo_0 ... ok
|
2014-08-07 15:26:38 +00:00
|
|
|
|
2014-12-31 20:02:18 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
2014-08-14 15:15:04 +00:00
|
|
|
|
|
|
|
",
|
2014-08-01 03:21:13 +00:00
|
|
|
compiling = COMPILING, running = RUNNING,
|
2014-08-07 15:26:38 +00:00
|
|
|
doctest = DOCTEST, dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-23 00:53:38 +00:00
|
|
|
|
|
|
|
test!(lib_with_standard_name2 {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "syntax"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-23 00:53:38 +00:00
|
|
|
name = "syntax"
|
|
|
|
test = false
|
2014-08-11 04:27:17 +00:00
|
|
|
doctest = false
|
2014-07-23 00:53:38 +00:00
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
pub fn foo() {}
|
|
|
|
")
|
|
|
|
.file("src/main.rs", "
|
|
|
|
extern crate syntax;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test() { syntax::foo() }
|
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-07-23 00:53:38 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{compiling} syntax v0.0.1 ({dir})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]syntax-[..]
|
2014-07-23 00:53:38 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test ... ok
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-01 03:21:13 +00:00
|
|
|
compiling = COMPILING, running = RUNNING,
|
2014-08-06 16:21:10 +00:00
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-23 18:58:09 +00:00
|
|
|
|
|
|
|
test!(bin_there_for_integration {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "
|
|
|
|
fn main() { std::os::set_exit_status(1); }
|
|
|
|
#[test] fn main_test() {}
|
|
|
|
")
|
|
|
|
.file("tests/foo.rs", r#"
|
2015-01-30 13:48:43 +00:00
|
|
|
use std::old_io::Command;
|
2014-07-23 18:58:09 +00:00
|
|
|
#[test]
|
|
|
|
fn test_test() {
|
2015-03-03 21:46:02 +00:00
|
|
|
let status = Command::new("target/debug/foo").status().unwrap();
|
2014-07-23 18:58:09 +00:00
|
|
|
assert!(status.matches_exit_status(1));
|
|
|
|
}
|
|
|
|
"#);
|
|
|
|
|
2014-12-21 23:19:44 +00:00
|
|
|
let output = p.cargo_process("test").exec_with_output().unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
let output = str::from_utf8(&output.stdout).unwrap();
|
2014-07-23 18:58:09 +00:00
|
|
|
assert!(output.contains("main_test ... ok"), "no main_test\n{}", output);
|
|
|
|
assert!(output.contains("test_test ... ok"), "no test_test\n{}", output);
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-23 16:09:33 +00:00
|
|
|
|
|
|
|
test!(test_dylib {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-07-23 16:09:33 +00:00
|
|
|
name = "foo"
|
|
|
|
crate_type = ["dylib"]
|
2014-08-07 00:50:55 +00:00
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "bar"
|
2014-07-23 16:09:33 +00:00
|
|
|
"#)
|
2014-08-18 01:34:50 +00:00
|
|
|
.file("src/lib.rs", r#"
|
2014-09-11 05:36:23 +00:00
|
|
|
extern crate "bar" as the_bar;
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2014-08-18 01:34:50 +00:00
|
|
|
pub fn bar() { the_bar::baz(); }
|
2014-08-07 00:50:55 +00:00
|
|
|
|
2014-07-23 16:09:33 +00:00
|
|
|
#[test]
|
2014-08-07 00:50:55 +00:00
|
|
|
fn foo() { bar(); }
|
2014-08-18 01:34:50 +00:00
|
|
|
"#)
|
2014-08-07 00:50:55 +00:00
|
|
|
.file("tests/test.rs", r#"
|
2014-09-11 05:36:23 +00:00
|
|
|
extern crate "foo" as the_foo;
|
2014-08-07 00:50:55 +00:00
|
|
|
|
|
|
|
#[test]
|
2014-08-18 01:34:50 +00:00
|
|
|
fn foo() { the_foo::bar(); }
|
2014-08-07 00:50:55 +00:00
|
|
|
"#)
|
|
|
|
.file("bar/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
2014-08-14 06:08:02 +00:00
|
|
|
[lib]
|
2014-08-07 00:50:55 +00:00
|
|
|
name = "bar"
|
|
|
|
crate_type = ["dylib"]
|
|
|
|
"#)
|
|
|
|
.file("bar/src/lib.rs", "
|
|
|
|
pub fn baz() {}
|
2014-07-23 16:09:33 +00:00
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-07-23 16:09:33 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-07 00:50:55 +00:00
|
|
|
{compiling} bar v0.0.1 ({dir})
|
2014-08-06 16:21:10 +00:00
|
|
|
{compiling} foo v0.0.1 ({dir})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-23 16:09:33 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]test-[..]
|
2014-08-07 00:50:55 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-01 03:21:13 +00:00
|
|
|
compiling = COMPILING, running = RUNNING,
|
|
|
|
doctest = DOCTEST,
|
2014-08-06 16:21:10 +00:00
|
|
|
dir = p.url()).as_slice()));
|
2014-12-21 23:19:44 +00:00
|
|
|
p.root().move_into_the_past().unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
2014-07-23 16:09:33 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-23 16:09:33 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]test-[..]
|
2014-08-07 00:50:55 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-09-05 17:15:10 +00:00
|
|
|
running = RUNNING,
|
|
|
|
doctest = DOCTEST)));
|
|
|
|
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-07-23 16:36:49 +00:00
|
|
|
|
|
|
|
test!(test_twice_with_build_cmd {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2015-01-19 22:27:51 +00:00
|
|
|
build = "build.rs"
|
2014-07-23 16:36:49 +00:00
|
|
|
"#)
|
2015-01-19 22:27:51 +00:00
|
|
|
.file("build.rs", "fn main() {}")
|
2014-07-23 16:36:49 +00:00
|
|
|
.file("src/lib.rs", "
|
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-07-23 16:36:49 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-06 16:21:10 +00:00
|
|
|
{compiling} foo v0.0.1 ({dir})
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-23 16:36:49 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-08-01 03:21:13 +00:00
|
|
|
compiling = COMPILING, running = RUNNING,
|
|
|
|
doctest = DOCTEST,
|
2014-08-06 16:21:10 +00:00
|
|
|
dir = p.url()).as_slice()));
|
2014-08-02 07:08:31 +00:00
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
2014-07-23 16:36:49 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
2014-08-19 04:38:04 +00:00
|
|
|
{running} target[..]foo-[..]
|
2014-07-23 16:36:49 +00:00
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
2014-08-01 03:21:13 +00:00
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2014-08-14 15:15:04 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
2014-09-05 17:15:10 +00:00
|
|
|
running = RUNNING,
|
|
|
|
doctest = DOCTEST)));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-08-19 04:38:04 +00:00
|
|
|
|
|
|
|
test!(test_then_build {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
#[test]
|
|
|
|
fn foo() {}
|
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test"),
|
2014-08-19 04:38:04 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} foo v0.0.1 ({dir})
|
|
|
|
{running} target[..]foo-[..]
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
|
|
|
compiling = COMPILING, running = RUNNING,
|
|
|
|
doctest = DOCTEST,
|
|
|
|
dir = p.url()).as_slice()));
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("build"),
|
2014-08-19 04:38:04 +00:00
|
|
|
execs().with_status(0)
|
2014-09-05 17:15:10 +00:00
|
|
|
.with_stdout(""));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-08-21 21:09:27 +00:00
|
|
|
|
|
|
|
test!(test_no_run {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "
|
|
|
|
#[test]
|
2014-10-30 01:59:06 +00:00
|
|
|
fn foo() { panic!() }
|
2014-08-21 21:09:27 +00:00
|
|
|
");
|
|
|
|
|
2014-08-21 16:24:34 +00:00
|
|
|
assert_that(p.cargo_process("test").arg("--no-run"),
|
2014-08-21 21:09:27 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} foo v0.0.1 ({dir})
|
|
|
|
",
|
|
|
|
compiling = COMPILING,
|
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-08-25 12:54:47 +00:00
|
|
|
|
2014-10-28 08:31:34 +00:00
|
|
|
test!(test_run_specific_bin_target {
|
|
|
|
let prj = project("foo")
|
|
|
|
.file("Cargo.toml" , r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="bin1"
|
|
|
|
path="src/bin1.rs"
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name="bin2"
|
|
|
|
path="src/bin2.rs"
|
|
|
|
"#)
|
|
|
|
.file("src/bin1.rs", "#[test] fn test1() { }")
|
|
|
|
.file("src/bin2.rs", "#[test] fn test2() { }");
|
|
|
|
|
|
|
|
let expected_stdout = format!("\
|
|
|
|
{compiling} foo v0.0.1 ({dir})
|
|
|
|
{running} target[..]bin2-[..]
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test2 ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
|
|
|
compiling = COMPILING,
|
|
|
|
running = RUNNING,
|
|
|
|
dir = prj.url());
|
|
|
|
|
2015-03-21 00:47:34 +00:00
|
|
|
assert_that(prj.cargo_process("test").arg("--bin").arg("bin2"),
|
2014-10-28 08:31:34 +00:00
|
|
|
execs().with_status(0).with_stdout(expected_stdout.as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-10-28 08:31:34 +00:00
|
|
|
|
|
|
|
test!(test_run_specific_test_target {
|
|
|
|
let prj = project("foo")
|
|
|
|
.file("Cargo.toml" , r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/bin/a.rs", "fn main() { }")
|
|
|
|
.file("src/bin/b.rs", "#[test] fn test_b() { } fn main() { }")
|
|
|
|
.file("tests/a.rs", "#[test] fn test_a() { }")
|
|
|
|
.file("tests/b.rs", "#[test] fn test_b() { }");
|
|
|
|
|
|
|
|
let expected_stdout = format!("\
|
|
|
|
{compiling} foo v0.0.1 ({dir})
|
|
|
|
{running} target[..]b-[..]
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test test_b ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
",
|
|
|
|
compiling = COMPILING,
|
|
|
|
running = RUNNING,
|
|
|
|
dir = prj.url());
|
|
|
|
|
2014-11-13 17:37:09 +00:00
|
|
|
assert_that(prj.cargo_process("test").arg("--test").arg("b"),
|
2014-10-28 08:31:34 +00:00
|
|
|
execs().with_status(0).with_stdout(expected_stdout.as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-10-28 08:31:34 +00:00
|
|
|
|
2014-08-25 12:54:47 +00:00
|
|
|
test!(test_no_harness {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[[bin]]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
|
|
|
|
|
|
|
[[test]]
|
|
|
|
name = "bar"
|
|
|
|
path = "foo.rs"
|
|
|
|
harness = false
|
|
|
|
"#)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("foo.rs", "fn main() {}");
|
|
|
|
|
2014-08-31 20:22:09 +00:00
|
|
|
assert_that(p.cargo_process("test").arg("--").arg("--nocapture"),
|
2014-08-25 12:54:47 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} foo v0.0.1 ({dir})
|
|
|
|
{running} target[..]bar-[..]
|
|
|
|
",
|
|
|
|
compiling = COMPILING, running = RUNNING,
|
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-09-24 01:10:27 +00:00
|
|
|
|
|
|
|
test!(selective_testing {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
[dependencies.d2]
|
|
|
|
path = "d2"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
doctest = false
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("d1/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
doctest = false
|
|
|
|
"#)
|
|
|
|
.file("d1/src/lib.rs", "")
|
2015-03-21 01:53:00 +00:00
|
|
|
.file("d1/src/main.rs", "extern crate d1; fn main() {}")
|
2014-09-24 01:10:27 +00:00
|
|
|
.file("d2/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "d2"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d2"
|
|
|
|
doctest = false
|
|
|
|
"#)
|
2015-03-21 01:53:00 +00:00
|
|
|
.file("d2/src/lib.rs", "")
|
|
|
|
.file("d2/src/main.rs", "extern crate d2; fn main() {}");
|
2014-09-24 01:10:27 +00:00
|
|
|
p.build();
|
|
|
|
|
|
|
|
println!("d1");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test").arg("-p").arg("d1"),
|
2014-09-24 01:10:27 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} d1 v0.0.1 ({dir})
|
|
|
|
{running} target[..]d1-[..]
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2015-03-21 01:53:00 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{running} target[..]d1-[..]
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-09-24 01:10:27 +00:00
|
|
|
", compiling = COMPILING, running = RUNNING,
|
|
|
|
dir = p.url()).as_slice()));
|
|
|
|
|
|
|
|
println!("d2");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test").arg("-p").arg("d2"),
|
2014-09-24 01:10:27 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} d2 v0.0.1 ({dir})
|
|
|
|
{running} target[..]d2-[..]
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2015-03-21 01:53:00 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{running} target[..]d2-[..]
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-09-24 01:10:27 +00:00
|
|
|
", compiling = COMPILING, running = RUNNING,
|
|
|
|
dir = p.url()).as_slice()));
|
|
|
|
|
|
|
|
println!("whole");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
2014-09-24 01:10:27 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} foo v0.0.1 ({dir})
|
|
|
|
{running} target[..]foo-[..]
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
2015-03-21 01:53:00 +00:00
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
2014-09-24 01:10:27 +00:00
|
|
|
", compiling = COMPILING, running = RUNNING,
|
|
|
|
dir = p.url()).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-09-24 05:14:02 +00:00
|
|
|
|
|
|
|
test!(almost_cyclic_but_not_quite {
|
|
|
|
let p = project("a")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies.b]
|
|
|
|
path = "b"
|
|
|
|
[dev-dependencies.c]
|
|
|
|
path = "c"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
#[cfg(test)] extern crate b;
|
|
|
|
#[cfg(test)] extern crate c;
|
|
|
|
"#)
|
|
|
|
.file("b/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "b"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.a]
|
|
|
|
path = ".."
|
|
|
|
"#)
|
|
|
|
.file("b/src/lib.rs", r#"
|
|
|
|
extern crate a;
|
|
|
|
"#)
|
|
|
|
.file("c/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "c"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("c/src/lib.rs", "");
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("build"), execs().with_status(0));
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test"),
|
2014-09-24 05:14:02 +00:00
|
|
|
execs().with_status(0));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-10-06 18:27:16 +00:00
|
|
|
|
|
|
|
test!(build_then_selective_test {
|
|
|
|
let p = project("a")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.b]
|
|
|
|
path = "b"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "extern crate b;")
|
|
|
|
.file("src/main.rs", "extern crate b; extern crate a; fn main() {}")
|
|
|
|
.file("b/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "b"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("b/src/lib.rs", "");
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("build"), execs().with_status(0));
|
|
|
|
p.root().move_into_the_past().unwrap();
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test").arg("-p").arg("b"),
|
2014-10-06 18:27:16 +00:00
|
|
|
execs().with_status(0));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-10-03 01:57:33 +00:00
|
|
|
|
2014-10-06 03:00:42 +00:00
|
|
|
test!(example_dev_dep {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dev-dependencies.bar]
|
|
|
|
path = "bar"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
"#)
|
|
|
|
.file("examples/e1.rs", r#"
|
|
|
|
extern crate bar;
|
|
|
|
fn main() { }
|
|
|
|
"#)
|
|
|
|
.file("bar/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("bar/src/lib.rs", r#"
|
|
|
|
#![feature(macro_rules)]
|
|
|
|
// make sure this file takes awhile to compile
|
Overhaul how cargo treats profiles
This commit is a complete overhaul of how Cargo handles compilation profiles
internally. The external interface of Cargo is not affected by this change.
Previously each Target had a Profile embedded within it. Conceptually a Target
is an entry in the manifest (a binary, benchmark, etc) and a Profile controlled
various flags (e.g. --test, -C opt-level, etc). Each Package then contained many
profiles for each possible compilation mode. For example a Package would have
one target for testing a library, benchmarking a library, documenting a library,
etc. When it came to building these targets, Cargo would filter out the targets
listed to determine what needed to be built.
This filtering was largely done based off an "environment" represented as a
string. Each mode of compilation got a separate environment string like `"test"`
or `"bench"`. Altogether, however, this approach had a number of drawbacks:
* Examples in release mode do not currently work. This is due to how examples
are classified and how release mode is handled (e.g. the "release" environment
where examples are meant to be built in the "test" environment).
* It is not trivial to implement `cargo test --release` today.
* It is not trivial to implement `cargo build --bin foo` where *only* the binary
`foo` is built. The same is true for examples.
* It is not trivial to add selective building of a number of
binaries/examples/etc.
* Filtering the list of targets to build has some pretty hokey logic that
involves pseudo-environments like "doc-all" vs "doc". This logic is duplicated
in a few places and in general is quite brittle.
* The TOML parser greatly affects compilation due to the time at which profiles
are generated, which seems somewhat backwards.
* Profiles must be overridden, but only partially, at compile time becuase only
the top-level package's profile is applied.
In general, this system just needed an overhaul. This commit made a single
change of separating `Profile` from `Target` and then basically hit `make` until
all the tests passed again. The other large architectural changes are:
* Environment strings are now entirely gone.
* Filters are implemented in a much more robust fashion.
* Release mode is now handled much more gracefully.
* The unit of compilation in the backend is no longer (package, target) but
rather (package, target, profile). This change had to be propagated many
location in the `cargo_rustc` module.
* The backend does not filter targets to build *at all*. All filtering now
happens entirely in the frontend.
I'll test issues after this change lands, but the motivation behind this is to
open the door to quickly fixing a number of outstanding issues against Cargo.
This change itself is not intended to close many bugs.
2015-02-19 19:30:35 +00:00
|
|
|
macro_rules! f0( () => (1) );
|
2014-12-19 18:38:32 +00:00
|
|
|
macro_rules! f1( () => ({(f0!()) + (f0!())}) );
|
|
|
|
macro_rules! f2( () => ({(f1!()) + (f1!())}) );
|
|
|
|
macro_rules! f3( () => ({(f2!()) + (f2!())}) );
|
|
|
|
macro_rules! f4( () => ({(f3!()) + (f3!())}) );
|
|
|
|
macro_rules! f5( () => ({(f4!()) + (f4!())}) );
|
|
|
|
macro_rules! f6( () => ({(f5!()) + (f5!())}) );
|
|
|
|
macro_rules! f7( () => ({(f6!()) + (f6!())}) );
|
|
|
|
macro_rules! f8( () => ({(f7!()) + (f7!())}) );
|
|
|
|
macro_rules! f9( () => ({(f8!()) + (f8!())}) );
|
|
|
|
macro_rules! f10( () => ({(f9!()) + (f9!())}) );
|
|
|
|
macro_rules! f11( () => ({(f10!()) + (f10!())}) );
|
2014-10-06 03:00:42 +00:00
|
|
|
pub fn bar() {
|
|
|
|
f11!();
|
|
|
|
}
|
|
|
|
"#);
|
|
|
|
assert_that(p.cargo_process("test"),
|
|
|
|
execs().with_status(0));
|
Overhaul how cargo treats profiles
This commit is a complete overhaul of how Cargo handles compilation profiles
internally. The external interface of Cargo is not affected by this change.
Previously each Target had a Profile embedded within it. Conceptually a Target
is an entry in the manifest (a binary, benchmark, etc) and a Profile controlled
various flags (e.g. --test, -C opt-level, etc). Each Package then contained many
profiles for each possible compilation mode. For example a Package would have
one target for testing a library, benchmarking a library, documenting a library,
etc. When it came to building these targets, Cargo would filter out the targets
listed to determine what needed to be built.
This filtering was largely done based off an "environment" represented as a
string. Each mode of compilation got a separate environment string like `"test"`
or `"bench"`. Altogether, however, this approach had a number of drawbacks:
* Examples in release mode do not currently work. This is due to how examples
are classified and how release mode is handled (e.g. the "release" environment
where examples are meant to be built in the "test" environment).
* It is not trivial to implement `cargo test --release` today.
* It is not trivial to implement `cargo build --bin foo` where *only* the binary
`foo` is built. The same is true for examples.
* It is not trivial to add selective building of a number of
binaries/examples/etc.
* Filtering the list of targets to build has some pretty hokey logic that
involves pseudo-environments like "doc-all" vs "doc". This logic is duplicated
in a few places and in general is quite brittle.
* The TOML parser greatly affects compilation due to the time at which profiles
are generated, which seems somewhat backwards.
* Profiles must be overridden, but only partially, at compile time becuase only
the top-level package's profile is applied.
In general, this system just needed an overhaul. This commit made a single
change of separating `Profile` from `Target` and then basically hit `make` until
all the tests passed again. The other large architectural changes are:
* Environment strings are now entirely gone.
* Filters are implemented in a much more robust fashion.
* Release mode is now handled much more gracefully.
* The unit of compilation in the backend is no longer (package, target) but
rather (package, target, profile). This change had to be propagated many
location in the `cargo_rustc` module.
* The backend does not filter targets to build *at all*. All filtering now
happens entirely in the frontend.
I'll test issues after this change lands, but the motivation behind this is to
open the door to quickly fixing a number of outstanding issues against Cargo.
This change itself is not intended to close many bugs.
2015-02-19 19:30:35 +00:00
|
|
|
assert_that(p.cargo("run")
|
|
|
|
.arg("--example").arg("e1").arg("--release").arg("-v"),
|
|
|
|
execs().with_status(0));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-10-06 03:00:42 +00:00
|
|
|
|
2014-10-03 01:57:33 +00:00
|
|
|
test!(selective_testing_with_docs {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.d1]
|
|
|
|
path = "d1"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
/// ```
|
|
|
|
/// not valid rust
|
|
|
|
/// ```
|
|
|
|
pub fn foo() {}
|
|
|
|
"#)
|
|
|
|
.file("d1/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "d1"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2014-10-07 19:01:10 +00:00
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "d1"
|
|
|
|
path = "d1.rs"
|
2014-10-03 01:57:33 +00:00
|
|
|
"#)
|
2014-10-07 19:01:10 +00:00
|
|
|
.file("d1/d1.rs", "");
|
2014-10-03 01:57:33 +00:00
|
|
|
p.build();
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test").arg("-p").arg("d1"),
|
2014-10-03 01:57:33 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} d1 v0.0.1 ({dir})
|
|
|
|
{running} target[..]deps[..]d1[..]
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} d1
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
", compiling = COMPILING, running = RUNNING, dir = p.url(),
|
|
|
|
doctest = DOCTEST).as_slice()));
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-10-24 16:18:19 +00:00
|
|
|
|
|
|
|
test!(example_bin_same_name {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#)
|
|
|
|
.file("examples/foo.rs", r#"fn main() { println!("example"); }"#);
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("test").arg("--no-run").arg("-v"),
|
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} foo v0.0.1 ({dir})
|
2015-03-21 02:31:12 +00:00
|
|
|
{running} `rustc [..]`
|
|
|
|
{running} `rustc [..]`
|
2014-10-24 16:18:19 +00:00
|
|
|
", compiling = COMPILING, running = RUNNING, dir = p.url()).as_slice()));
|
|
|
|
|
2015-03-21 02:31:12 +00:00
|
|
|
assert_that(&p.bin("foo"), is_not(existing_file()));
|
2014-10-24 16:18:19 +00:00
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
|
|
|
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.process(&p.bin("examples/foo")),
|
2014-10-24 16:18:19 +00:00
|
|
|
execs().with_status(0).with_stdout("example\n"));
|
2015-03-21 02:31:12 +00:00
|
|
|
|
2015-03-24 00:45:41 +00:00
|
|
|
assert_that(p.cargo("run"),
|
2015-03-21 02:31:12 +00:00
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
{compiling} foo v0.0.1 ([..])
|
|
|
|
{running} [..]
|
|
|
|
bin
|
|
|
|
", compiling = COMPILING, running = RUNNING).as_slice()));
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-10-29 23:33:52 +00:00
|
|
|
|
|
|
|
test!(test_with_example_twice {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#)
|
|
|
|
.file("examples/foo.rs", r#"fn main() { println!("example"); }"#);
|
|
|
|
|
|
|
|
println!("first");
|
|
|
|
assert_that(p.cargo_process("test").arg("-v"),
|
|
|
|
execs().with_status(0));
|
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
|
|
|
println!("second");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"),
|
2014-10-29 23:33:52 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
assert_that(&p.bin("examples/foo"), existing_file());
|
2014-12-19 18:38:32 +00:00
|
|
|
});
|
2014-12-28 09:04:10 +00:00
|
|
|
|
|
|
|
test!(example_with_dev_dep {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
name = "foo"
|
|
|
|
test = false
|
|
|
|
doctest = false
|
|
|
|
|
|
|
|
[dev-dependencies.a]
|
|
|
|
path = "a"
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("examples/ex.rs", "extern crate a; fn main() {}")
|
|
|
|
.file("a/Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "a"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("a/src/lib.rs", "");
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("test").arg("-v"),
|
|
|
|
execs().with_status(0)
|
|
|
|
.with_stdout(format!("\
|
|
|
|
[..]
|
|
|
|
[..]
|
|
|
|
[..]
|
|
|
|
[..]
|
|
|
|
{running} `rustc [..] --crate-name ex [..] --extern a=[..]`
|
|
|
|
", running = RUNNING).as_slice()));
|
|
|
|
});
|
2015-01-14 05:23:43 +00:00
|
|
|
|
|
|
|
test!(bin_is_preserved {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/main.rs", "fn main() {}");
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("build").arg("-v"),
|
|
|
|
execs().with_status(0));
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
|
|
|
|
println!("testing");
|
2015-02-27 01:04:25 +00:00
|
|
|
assert_that(p.cargo("test").arg("-v"),
|
2015-01-14 05:23:43 +00:00
|
|
|
execs().with_status(0));
|
|
|
|
assert_that(&p.bin("foo"), existing_file());
|
|
|
|
});
|
2015-02-09 16:28:36 +00:00
|
|
|
|
|
|
|
test!(bad_example {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", "");
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("run").arg("--example").arg("foo"),
|
|
|
|
execs().with_status(101).with_stderr("\
|
2015-03-21 02:33:12 +00:00
|
|
|
no example target named `foo`
|
2015-02-09 16:28:36 +00:00
|
|
|
"));
|
|
|
|
assert_that(p.cargo_process("run").arg("--bin").arg("foo"),
|
|
|
|
execs().with_status(101).with_stderr("\
|
2015-03-21 02:33:12 +00:00
|
|
|
no bin target named `foo`
|
2015-02-09 16:28:36 +00:00
|
|
|
"));
|
|
|
|
});
|
2015-02-09 19:14:27 +00:00
|
|
|
|
|
|
|
test!(doctest_feature {
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
[features]
|
|
|
|
bar = []
|
|
|
|
"#)
|
|
|
|
.file("src/lib.rs", r#"
|
|
|
|
/// ```rust
|
|
|
|
/// assert_eq!(foo::foo(), 1);
|
|
|
|
/// ```
|
|
|
|
#[cfg(feature = "bar")]
|
|
|
|
pub fn foo() -> i32 { 1 }
|
|
|
|
"#);
|
|
|
|
|
|
|
|
assert_that(p.cargo_process("test").arg("--features").arg("bar"),
|
|
|
|
execs().with_status(0).with_stdout(format!("\
|
|
|
|
{compiling} foo [..]
|
|
|
|
{running} target[..]foo[..]
|
|
|
|
|
|
|
|
running 0 tests
|
|
|
|
|
|
|
|
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
{doctest} foo
|
|
|
|
|
|
|
|
running 1 test
|
|
|
|
test foo_0 ... ok
|
|
|
|
|
|
|
|
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
|
|
|
|
|
|
|
|
", compiling = COMPILING, running = RUNNING, doctest = DOCTEST)))
|
|
|
|
});
|