2018-03-01 18:14:17 +00:00
|
|
|
use cargotest::install::exe;
|
2017-10-07 16:28:34 +00:00
|
|
|
use cargotest::support::paths::CargoPathExt;
|
2018-03-01 18:14:17 +00:00
|
|
|
use cargotest::support::registry::Package;
|
|
|
|
use cargotest::support::{execs, project};
|
2017-10-07 16:28:34 +00:00
|
|
|
use glob::glob;
|
2018-03-01 18:14:17 +00:00
|
|
|
use hamcrest::{assert_that, existing_file, is_not};
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
const SIMPLE_MANIFEST: &str = r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
"#;
|
2016-11-29 03:10:00 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_success() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
::bar::baz();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
|
|
|
let _bar = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
pub fn baz() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("check"), execs().with_status(0));
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_fail() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
::bar::baz(42);
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
|
|
|
let _bar = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
pub fn baz() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("check"), execs().with_status(101));
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn custom_derive() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate bar;
|
|
|
|
|
|
|
|
trait B {
|
|
|
|
fn b(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(B)]
|
|
|
|
struct A;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a = A;
|
|
|
|
a.b();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
|
|
|
let _bar = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
extern crate proc_macro;
|
|
|
|
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
|
|
|
#[proc_macro_derive(B)]
|
|
|
|
pub fn derive(_input: TokenStream) -> TokenStream {
|
|
|
|
format!("impl B for A {{ fn b(&self) {{}} }}").parse().unwrap()
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("check"), execs().with_status(0));
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_build() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
::bar::baz();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _bar = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
pub fn baz() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("check"), execs().with_status(0));
|
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0));
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn build_check() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
::bar::baz();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2017-07-22 03:12:21 +00:00
|
|
|
let _bar = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-11-29 03:10:00 +00:00
|
|
|
pub fn baz() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("build"), execs().with_status(0));
|
|
|
|
assert_that(foo.cargo("check"), execs().with_status(0));
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
2016-12-17 20:23:33 +00:00
|
|
|
|
|
|
|
// Checks that where a project has both a lib and a bin, the lib is only checked
|
|
|
|
// not built.
|
|
|
|
#[test]
|
|
|
|
fn issue_3418() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-12-17 20:23:33 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2016-12-17 20:23:33 +00:00
|
|
|
.file("src/lib.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
2016-12-17 20:23:33 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
foo.cargo("check").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] --emit=dep-info,metadata [..]"),
|
|
|
|
);
|
2016-12-17 20:23:33 +00:00
|
|
|
}
|
2016-12-18 21:52:50 +00:00
|
|
|
|
|
|
|
// Some weirdness that seems to be caused by a crate being built as well as
|
|
|
|
// checked, but in this case with a proc macro too.
|
|
|
|
#[test]
|
|
|
|
fn issue_3419() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2016-12-18 21:52:50 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
rustc-serialize = "*"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2016-12-18 21:52:50 +00:00
|
|
|
extern crate rustc_serialize;
|
|
|
|
|
|
|
|
use rustc_serialize::Decodable;
|
|
|
|
|
|
|
|
pub fn take<T: Decodable>() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2016-12-18 21:52:50 +00:00
|
|
|
extern crate rustc_serialize;
|
|
|
|
|
|
|
|
extern crate foo;
|
|
|
|
|
|
|
|
#[derive(RustcDecodable)]
|
|
|
|
pub struct Foo;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
foo::take::<Foo>();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-12-18 21:52:50 +00:00
|
|
|
|
|
|
|
Package::new("rustc-serialize", "1.0.0")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"pub trait Decodable: Sized {
|
2016-12-18 21:52:50 +00:00
|
|
|
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>;
|
|
|
|
}
|
|
|
|
pub trait Decoder {
|
|
|
|
type Error;
|
|
|
|
fn read_struct<T, F>(&mut self, s_name: &str, len: usize, f: F)
|
|
|
|
-> Result<T, Self::Error>
|
|
|
|
where F: FnOnce(&mut Self) -> Result<T, Self::Error>;
|
2018-03-14 15:17:44 +00:00
|
|
|
} "#,
|
|
|
|
)
|
|
|
|
.publish();
|
2016-12-18 21:52:50 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("check"), execs().with_status(0));
|
2016-12-18 21:52:50 +00:00
|
|
|
}
|
2017-01-05 02:21:12 +00:00
|
|
|
|
2017-11-29 03:31:34 +00:00
|
|
|
// Check on a dylib should have a different metadata hash than build.
|
|
|
|
#[test]
|
2017-11-29 15:40:02 +00:00
|
|
|
fn dylib_check_preserves_build_cache() {
|
2017-11-29 03:31:34 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-11-29 03:31:34 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
crate-type = ["dylib"]
|
|
|
|
|
|
|
|
[dependencies]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-11-29 03:31:34 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
|
|
|
execs().with_status(0).with_stderr(
|
|
|
|
"\
|
2017-11-29 15:40:02 +00:00
|
|
|
[..]Compiling foo v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
|
|
|
),
|
|
|
|
);
|
2017-11-29 15:40:02 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(p.cargo("check"), execs().with_status(0));
|
2017-11-29 15:40:02 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("build"),
|
2018-03-14 15:43:41 +00:00
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2017-11-29 03:31:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 02:21:12 +00:00
|
|
|
// test `cargo rustc --profile check`
|
|
|
|
#[test]
|
|
|
|
fn rustc_check() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
::bar::baz();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
|
|
|
let _bar = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
pub fn baz() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-05 02:21:12 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
foo.cargo("rustc")
|
|
|
|
.arg("--profile")
|
|
|
|
.arg("check")
|
|
|
|
.arg("--")
|
|
|
|
.arg("--emit=metadata"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
2017-01-05 02:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn rustc_check_err() {
|
|
|
|
let foo = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
extern crate bar;
|
|
|
|
fn main() {
|
|
|
|
::bar::qux();
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
|
|
|
let _bar = project("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-01-05 02:21:12 +00:00
|
|
|
pub fn baz() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-05 02:21:12 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
foo.cargo("rustc")
|
|
|
|
.arg("--profile")
|
|
|
|
.arg("check")
|
|
|
|
.arg("--")
|
|
|
|
.arg("--emit=metadata"),
|
|
|
|
execs().with_status(101),
|
|
|
|
);
|
2017-01-05 02:21:12 +00:00
|
|
|
}
|
2017-02-17 17:09:23 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_all() {
|
2017-07-22 03:12:21 +00:00
|
|
|
let p = project("foo")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-02-17 17:09:23 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[workspace]
|
|
|
|
[dependencies]
|
|
|
|
b = { path = "b" }
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-17 17:09:23 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("examples/a.rs", "fn main() {}")
|
|
|
|
.file("tests/a.rs", "")
|
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"b/Cargo.toml",
|
|
|
|
r#"
|
2017-02-17 17:09:23 +00:00
|
|
|
[package]
|
|
|
|
name = "b"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-02-17 17:09:23 +00:00
|
|
|
.file("b/src/main.rs", "fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
2017-02-17 17:09:23 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--all").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name b b[/]src[/]lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name b b[/]src[/]main.rs [..]"),
|
|
|
|
);
|
2017-02-17 17:09:23 +00:00
|
|
|
}
|
2017-05-26 21:00:45 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_virtual_all_implied() {
|
|
|
|
let p = project("workspace")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/src/lib.rs",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
pub fn foo() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"bar/src/lib.rs",
|
|
|
|
r#"
|
2017-05-26 21:00:45 +00:00
|
|
|
pub fn bar() {}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] --crate-name foo foo[/]src[/]lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name bar bar[/]src[/]lib.rs [..]"),
|
|
|
|
);
|
2017-05-26 21:00:45 +00:00
|
|
|
}
|
2017-08-11 01:46:07 +00:00
|
|
|
|
|
|
|
#[test]
|
2018-03-19 17:20:54 +00:00
|
|
|
fn targets_selected_default() {
|
2017-08-11 01:46:07 +00:00
|
|
|
let foo = project("foo")
|
2017-10-07 16:28:34 +00:00
|
|
|
.file("Cargo.toml", SIMPLE_MANIFEST)
|
2017-08-11 01:46:07 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("src/lib.rs", "pub fn smth() {}")
|
|
|
|
.file("examples/example1.rs", "fn main() {}")
|
|
|
|
.file("tests/test2.rs", "#[test] fn t() {}")
|
|
|
|
.file("benches/bench3.rs", "")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-08-11 01:46:07 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
2018-03-19 17:20:54 +00:00
|
|
|
foo.cargo("check").arg("-v"),
|
2018-03-14 15:17:44 +00:00
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]")
|
2018-03-19 17:20:54 +00:00
|
|
|
.with_stderr_does_not_contain("[..] --crate-name example1 examples[/]example1.rs [..]")
|
|
|
|
.with_stderr_does_not_contain("[..] --crate-name test2 tests[/]test2.rs [..]")
|
|
|
|
.with_stderr_does_not_contain("[..] --crate-name bench3 benches[/]bench3.rs [..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2018-03-19 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn targets_selected_all() {
|
|
|
|
let foo = project("foo")
|
|
|
|
.file("Cargo.toml", SIMPLE_MANIFEST)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("src/lib.rs", "pub fn smth() {}")
|
|
|
|
.file("examples/example1.rs", "fn main() {}")
|
|
|
|
.file("tests/test2.rs", "#[test] fn t() {}")
|
|
|
|
.file("benches/bench3.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-03-15 15:20:15 +00:00
|
|
|
assert_that(
|
2018-03-19 17:20:54 +00:00
|
|
|
foo.cargo("check").arg("--all-targets").arg("-v"),
|
2018-03-15 15:20:15 +00:00
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]")
|
2018-03-19 17:20:54 +00:00
|
|
|
.with_stderr_contains("[..] --crate-name example1 examples[/]example1.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name test2 tests[/]test2.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name bench3 benches[/]bench3.rs [..]"),
|
2018-03-15 15:20:15 +00:00
|
|
|
);
|
2017-08-11 01:46:07 +00:00
|
|
|
}
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_unit_test_profile() {
|
|
|
|
let foo = project("foo")
|
|
|
|
.file("Cargo.toml", SIMPLE_MANIFEST)
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-10-07 16:28:34 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
badtext
|
|
|
|
}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-10-08 22:23:21 +00:00
|
|
|
.build();
|
2017-10-07 16:28:34 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(foo.cargo("check"), execs().with_status(0));
|
|
|
|
assert_that(
|
|
|
|
foo.cargo("check").arg("--profile").arg("test"),
|
|
|
|
execs()
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..]badtext[..]"),
|
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 21:34:21 +00:00
|
|
|
// Verify what is checked with various command-line filters.
|
2017-10-07 16:28:34 +00:00
|
|
|
#[test]
|
2017-10-20 21:34:21 +00:00
|
|
|
fn check_filters() {
|
2017-10-07 16:28:34 +00:00
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", SIMPLE_MANIFEST)
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2017-10-07 16:28:34 +00:00
|
|
|
fn unused_normal_lib() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_lib() {}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
2017-10-07 16:28:34 +00:00
|
|
|
fn main() {}
|
|
|
|
fn unused_normal_bin() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_bin() {}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"tests/t1.rs",
|
|
|
|
r#"
|
2017-10-07 16:28:34 +00:00
|
|
|
fn unused_normal_t1() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_t1() {}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"examples/ex1.rs",
|
|
|
|
r#"
|
2017-10-07 16:28:34 +00:00
|
|
|
fn main() {}
|
|
|
|
fn unused_normal_ex1() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_ex1() {}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"benches/b1.rs",
|
|
|
|
r#"
|
2017-10-07 16:28:34 +00:00
|
|
|
fn unused_normal_b1() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_b1() {}
|
|
|
|
}
|
2018-03-14 15:17:44 +00:00
|
|
|
"#,
|
|
|
|
)
|
2017-10-08 22:23:21 +00:00
|
|
|
.build();
|
2017-10-07 16:28:34 +00:00
|
|
|
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..]unused_normal_lib[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_bin[..]")
|
2018-04-19 05:13:30 +00:00
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_t1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_ex1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_b1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_[..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--tests").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..] --test [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]lib.rs --crate-type lib [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src[/]main.rs [..] --test [..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_lib[..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_bin[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_lib[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_bin[..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_t1[..]")
|
2018-04-21 02:43:57 +00:00
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_ex1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_ex1[..]")
|
2018-04-19 05:13:30 +00:00
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_b1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_b1[..]"),
|
2018-04-18 01:46:44 +00:00
|
|
|
// with_stderr_does_not_contain --crate-type lib
|
|
|
|
// with_stderr_does_not_contain --crate-type bin
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2017-10-20 21:34:21 +00:00
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--test").arg("t1").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..]unused_normal_lib[..]")
|
2018-04-18 01:46:44 +00:00
|
|
|
// .with_stderr_contains("[..]unused_normal_bin[..]")
|
2018-03-14 15:17:44 +00:00
|
|
|
.with_stderr_contains("[..]unused_unit_t1[..]")
|
2018-04-19 05:13:30 +00:00
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_lib[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_bin[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_ex1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_b1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_ex1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_b1[..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--all-targets").arg("-v"),
|
|
|
|
execs()
|
|
|
|
.with_status(0)
|
|
|
|
.with_stderr_contains("[..]unused_normal_lib[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_bin[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_t1[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_ex1[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_b1[..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_b1[..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_t1[..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_lib[..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_bin[..]")
|
2018-04-21 02:43:57 +00:00
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_ex1[..]"),
|
2018-03-14 15:17:44 +00:00
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-03-14 15:17:44 +00:00
|
|
|
fn check_artifacts() {
|
2017-10-07 16:28:34 +00:00
|
|
|
// Verify which artifacts are created when running check (#4059).
|
|
|
|
let p = project("foo")
|
|
|
|
.file("Cargo.toml", SIMPLE_MANIFEST)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("tests/t1.rs", "")
|
|
|
|
.file("examples/ex1.rs", "fn main() {}")
|
2017-10-08 22:23:21 +00:00
|
|
|
.file("benches/b1.rs", "")
|
|
|
|
.build();
|
2017-10-07 16:28:34 +00:00
|
|
|
assert_that(p.cargo("check"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/libfoo.rlib"),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(exe("foo")),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
|
|
|
assert_that(p.cargo("check").arg("--lib"), execs().with_status(0));
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/libfoo.rlib"),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(exe("foo")),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--bin").arg("foo"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/libfoo.rlib"),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(exe("foo")),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--test").arg("t1"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/libfoo.rlib"),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(exe("foo")),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
glob(&p.root().join("target/debug/t1-*").to_str().unwrap())
|
|
|
|
.unwrap()
|
|
|
|
.count(),
|
|
|
|
0
|
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--example").arg("ex1"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/libfoo.rlib"),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/examples").join(exe("ex1")),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-03-14 15:17:44 +00:00
|
|
|
assert_that(
|
|
|
|
p.cargo("check").arg("--bench").arg("b1"),
|
|
|
|
execs().with_status(0),
|
|
|
|
);
|
|
|
|
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug/libfoo.rlib"),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_that(
|
|
|
|
&p.root().join("target/debug").join(exe("foo")),
|
|
|
|
is_not(existing_file()),
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
glob(&p.root().join("target/debug/b1-*").to_str().unwrap())
|
|
|
|
.unwrap()
|
|
|
|
.count(),
|
|
|
|
0
|
|
|
|
);
|
2017-10-07 16:28:34 +00:00
|
|
|
}
|