2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo check` command.
|
|
|
|
|
2018-09-23 21:11:25 +00:00
|
|
|
use std::fmt::{self, Write};
|
|
|
|
|
2022-10-28 00:07:59 +00:00
|
|
|
use crate::messages::raw_rustc_output;
|
2024-01-18 05:27:56 +00:00
|
|
|
use cargo_test_support::compare;
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::install::exe;
|
|
|
|
use cargo_test_support::paths::CargoPathExt;
|
|
|
|
use cargo_test_support::registry::Package;
|
2023-11-19 01:23:29 +00:00
|
|
|
use cargo_test_support::tools;
|
2022-10-28 00:07:59 +00:00
|
|
|
use cargo_test_support::{basic_bin_manifest, basic_manifest, git, project};
|
2017-10-07 16:28:34 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-11-29 03:10:00 +00:00
|
|
|
fn check_success() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = 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-11-29 03:10: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-08-28 09:20:03 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bar; fn main() { ::bar::baz(); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check").run();
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-11-29 03:10:00 +00:00
|
|
|
fn check_fail() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = 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-11-29 03:10: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-08-28 09:20:03 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bar; fn main() { ::bar::baz(42); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-12-29 01:47:50 +00:00
|
|
|
foo.cargo("check")
|
|
|
|
.with_status(101)
|
2020-02-12 20:10:58 +00:00
|
|
|
.with_stderr_contains("[..]this function takes 0[..]")
|
2018-12-29 01:47:50 +00:00
|
|
|
.run();
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-11-29 03:10:00 +00:00
|
|
|
fn custom_derive() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = 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-11-29 03:10: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/main.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate bar;
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
trait B {
|
|
|
|
fn b(&self);
|
|
|
|
}
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[derive(B)]
|
|
|
|
struct A;
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {
|
|
|
|
let a = A;
|
|
|
|
a.b();
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = []
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
|
|
|
"#,
|
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 proc_macro;
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use proc_macro::TokenStream;
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[proc_macro_derive(B)]
|
|
|
|
pub fn derive(_input: TokenStream) -> TokenStream {
|
|
|
|
format!("impl B for A {{ fn b(&self) {{}} }}").parse().unwrap()
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check").run();
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-11-29 03:10:00 +00:00
|
|
|
fn check_build() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = 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-11-29 03:10: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-08-28 09:20:03 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bar; fn main() { ::bar::baz(); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check").run();
|
|
|
|
foo.cargo("build").run();
|
2016-11-29 03:10:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-11-29 03:10:00 +00:00
|
|
|
fn build_check() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = 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-11-29 03:10: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-08-28 09:20:03 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bar; fn main() { ::bar::baz(); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-02-15 14:16:41 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2016-11-29 03:10:00 +00:00
|
|
|
|
2019-05-08 18:28:05 +00:00
|
|
|
foo.cargo("build -v").run();
|
|
|
|
foo.cargo("check -v").run();
|
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.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-12-17 20:23:33 +00:00
|
|
|
fn issue_3418() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
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-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check -v")
|
2019-04-26 20:53:51 +00:00
|
|
|
.with_stderr_contains("[..] --emit=[..]metadata [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
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.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-12-18 21:52:50 +00:00
|
|
|
fn issue_3419() {
|
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-12-18 21:52:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
rustc-serialize = "*"
|
|
|
|
"#,
|
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 rustc_serialize;
|
2016-12-18 21:52:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
use rustc_serialize::Decodable;
|
2016-12-18 21:52:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
pub fn take<T: Decodable>() {}
|
|
|
|
"#,
|
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
|
|
|
extern crate rustc_serialize;
|
2016-12-18 21:52:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
extern crate foo;
|
2016-12-18 21:52:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
#[derive(RustcDecodable)]
|
|
|
|
pub struct Foo;
|
2016-12-18 21:52:50 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {
|
|
|
|
foo::take::<Foo>();
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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",
|
2020-09-27 00:59:58 +00:00
|
|
|
r#"
|
|
|
|
pub trait Decodable: Sized {
|
2016-12-18 21:52:50 +00:00
|
|
|
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>;
|
2020-09-27 00:59:58 +00:00
|
|
|
}
|
|
|
|
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-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.publish();
|
2016-12-18 21:52:50 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check").run();
|
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.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-11-29 15:40:02 +00:00
|
|
|
fn dylib_check_preserves_build_cache() {
|
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 = []
|
2017-11-29 03:31:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[lib]
|
|
|
|
crate-type = ["dylib"]
|
2017-11-29 03:31:34 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2017-11-29 03:31:34 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
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
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-11-29 15:40:02 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check").run();
|
2017-11-29 15:40:02 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
|
|
|
|
.run();
|
2017-11-29 03:31:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 02:21:12 +00:00
|
|
|
// test `cargo rustc --profile check`
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-01-05 02:21:12 +00:00
|
|
|
fn rustc_check() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = 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-01-05 02:21:12 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-08-28 09:20:03 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bar; fn main() { ::bar::baz(); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-05 02:21:12 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("rustc --profile check -- --emit=metadata").run();
|
2019-10-08 06:48:31 +00:00
|
|
|
|
|
|
|
// Verify compatible usage of --profile with --release, issue #7488
|
2019-10-08 08:07:19 +00:00
|
|
|
foo.cargo("rustc --profile check --release -- --emit=metadata")
|
|
|
|
.run();
|
|
|
|
foo.cargo("rustc --profile test --release -- --emit=metadata")
|
|
|
|
.run();
|
2017-01-05 02:21:12 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-01-05 02:21:12 +00:00
|
|
|
fn rustc_check_err() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = 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-01-05 02:21:12 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies.bar]
|
|
|
|
path = "../bar"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-08-28 09:20:03 +00:00
|
|
|
"src/main.rs",
|
|
|
|
"extern crate bar; fn main() { ::bar::qux(); }",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
let _bar = project()
|
|
|
|
.at("bar")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/lib.rs", "pub fn baz() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.build();
|
2017-01-05 02:21:12 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("rustc --profile check -- --emit=metadata")
|
|
|
|
.with_status(101)
|
2018-12-29 01:47:50 +00:00
|
|
|
.with_stderr_contains("[CHECKING] bar [..]")
|
|
|
|
.with_stderr_contains("[CHECKING] foo [..]")
|
2019-08-09 22:20:43 +00:00
|
|
|
.with_stderr_contains("[..]cannot find function `qux` in [..] `bar`")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-01-05 02:21:12 +00:00
|
|
|
}
|
2017-02-17 17:09:23 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-02-17 17:09:23 +00:00
|
|
|
fn check_all() {
|
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 = []
|
2017-02-17 17:09:23 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
[dependencies]
|
|
|
|
b = { path = "b" }
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
2017-02-17 17:09:23 +00:00
|
|
|
.file("examples/a.rs", "fn main() {}")
|
|
|
|
.file("tests/a.rs", "")
|
|
|
|
.file("src/lib.rs", "")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
|
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
|
|
|
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("check --workspace -v")
|
2018-08-28 09:20:03 +00:00
|
|
|
.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 [..]")
|
|
|
|
.run();
|
2017-02-17 17:09:23 +00:00
|
|
|
}
|
2017-05-26 21:00:45 +00:00
|
|
|
|
2020-10-04 15:31:09 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn check_all_exclude() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-10-09 23:44:57 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2020-10-04 15:31:09 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() { break_the_build(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check --workspace --exclude baz")
|
|
|
|
.with_stderr_does_not_contain("[CHECKING] baz v0.1.0 [..]")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_all_exclude_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:09 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() { break_the_build(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check --workspace --exclude '*z'")
|
|
|
|
.with_stderr_does_not_contain("[CHECKING] baz v0.1.0 [..]")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-05-26 21:00:45 +00:00
|
|
|
fn check_virtual_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 = ["bar", "baz"]
|
|
|
|
"#,
|
2018-12-08 11:19:47 +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", "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", "pub fn baz() {}")
|
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("check -v")
|
|
|
|
.with_stderr_contains("[..] --crate-name bar bar/src/lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name baz baz/src/lib.rs [..]")
|
|
|
|
.run();
|
2017-05-26 21:00:45 +00:00
|
|
|
}
|
2017-08-11 01:46:07 +00:00
|
|
|
|
2020-10-04 15:31:09 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn check_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:09 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() { break_the_build(); }")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -p bar")
|
|
|
|
.with_stderr_does_not_contain("[CHECKING] baz v0.1.0 [..]")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[CHECKING] bar v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_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:09 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() { break_the_build(); }")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -p '*z'")
|
|
|
|
.with_stderr_does_not_contain("[CHECKING] bar v0.1.0 [..]")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[CHECKING] baz v0.1.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-02-18 18:26:39 +00:00
|
|
|
fn exclude_warns_on_non_existing_package() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2019-08-12 12:31:20 +00:00
|
|
|
p.cargo("check --workspace --exclude bar")
|
2019-02-18 18:26:39 +00:00
|
|
|
.with_stdout("")
|
|
|
|
.with_stderr(
|
2020-09-27 00:59:58 +00:00
|
|
|
"\
|
2020-10-09 22:58:06 +00:00
|
|
|
[WARNING] excluded package(s) `bar` not found in workspace `[CWD]`
|
2019-02-18 18:26:39 +00:00
|
|
|
[CHECKING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2020-09-27 00:59:58 +00:00
|
|
|
",
|
2019-02-18 18:26:39 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-03-19 17:20:54 +00:00
|
|
|
fn targets_selected_default() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
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-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check -v")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src/lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src/main.rs [..]")
|
|
|
|
.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 [..]")
|
|
|
|
.run();
|
2018-03-19 17:20:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-03-19 17:20:54 +00:00
|
|
|
fn targets_selected_all() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-03-19 17:20:54 +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", "")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check --all-targets -v")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src/lib.rs [..]")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src/main.rs [..]")
|
|
|
|
.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 [..]")
|
|
|
|
.run();
|
2017-08-11 01:46:07 +00:00
|
|
|
}
|
2017-10-07 16:28:34 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-07 16:28:34 +00:00
|
|
|
fn check_unit_test_profile() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
badtext
|
|
|
|
}
|
2017-10-07 16:28:34 +00:00
|
|
|
}
|
2020-09-27 00:59:58 +00:00
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-10-07 16:28:34 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check").run();
|
|
|
|
foo.cargo("check --profile test")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[..]badtext[..]")
|
|
|
|
.run();
|
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.
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-10-20 21:34:21 +00:00
|
|
|
fn check_filters() {
|
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
|
|
|
fn unused_normal_lib() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_lib() {}
|
|
|
|
}
|
|
|
|
"#,
|
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
|
|
|
fn main() {}
|
|
|
|
fn unused_normal_bin() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_bin() {}
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"tests/t1.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn unused_normal_t1() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_t1() {}
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"examples/ex1.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn main() {}
|
|
|
|
fn unused_normal_ex1() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_ex1() {}
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-03-14 15:17:44 +00:00
|
|
|
"benches/b1.rs",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
fn unused_normal_b1() {}
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
fn unused_unit_b1() {}
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr_contains("[..]unused_normal_lib[..]")
|
|
|
|
.with_stderr_contains("[..]unused_normal_bin[..]")
|
|
|
|
.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_[..]")
|
|
|
|
.run();
|
2017-10-07 16:28:34 +00:00
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --tests -v")
|
|
|
|
.with_stderr_contains("[..] --crate-name foo src/lib.rs [..] --test [..]")
|
2018-09-09 17:39:55 +00:00
|
|
|
.with_stderr_contains("[..] --crate-name foo src/lib.rs [..] --crate-type lib [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.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[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_ex1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_ex1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_b1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_b1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]--crate-type bin[..]")
|
|
|
|
.run();
|
2017-10-20 21:34:21 +00:00
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --test t1 -v")
|
|
|
|
.with_stderr_contains("[..]unused_normal_lib[..]")
|
|
|
|
.with_stderr_contains("[..]unused_unit_t1[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_lib[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_normal_bin[..]")
|
|
|
|
.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[..]")
|
|
|
|
.run();
|
2017-10-07 16:28:34 +00:00
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --all-targets -v")
|
|
|
|
.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[..]")
|
|
|
|
.with_stderr_does_not_contain("[..]unused_unit_ex1[..]")
|
|
|
|
.run();
|
2017-10-07 16:28:34 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_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).
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2017-10-07 16:28:34 +00:00
|
|
|
.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();
|
2018-11-09 05:05:17 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check").run();
|
2018-11-09 05:05:17 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
|
|
|
|
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
|
2019-03-26 20:21:05 +00:00
|
|
|
assert_eq!(p.glob("target/debug/deps/libfoo-*.rmeta").count(), 2);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --lib").run();
|
2018-11-09 05:05:17 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
|
|
|
|
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
|
2019-03-26 20:21:05 +00:00
|
|
|
assert_eq!(p.glob("target/debug/deps/libfoo-*.rmeta").count(), 1);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --bin foo").run();
|
2018-11-09 05:05:17 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
|
|
|
|
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
|
2019-03-26 20:21:05 +00:00
|
|
|
assert_eq!(p.glob("target/debug/deps/libfoo-*.rmeta").count(), 2);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --test t1").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
|
|
|
|
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
|
|
|
|
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
|
2019-03-26 20:21:05 +00:00
|
|
|
assert_eq!(p.glob("target/debug/t1-*").count(), 0);
|
|
|
|
assert_eq!(p.glob("target/debug/deps/libfoo-*.rmeta").count(), 1);
|
|
|
|
assert_eq!(p.glob("target/debug/deps/libt1-*.rmeta").count(), 1);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --example ex1").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
|
|
|
|
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
|
2018-12-08 11:19:47 +00:00
|
|
|
assert!(!p
|
|
|
|
.root()
|
|
|
|
.join("target/debug/examples")
|
|
|
|
.join(exe("ex1"))
|
|
|
|
.is_file());
|
2019-03-26 20:21:05 +00:00
|
|
|
assert_eq!(p.glob("target/debug/deps/libfoo-*.rmeta").count(), 1);
|
|
|
|
assert_eq!(p.glob("target/debug/examples/libex1-*.rmeta").count(), 1);
|
2017-10-07 16:28:34 +00:00
|
|
|
|
|
|
|
p.root().join("target").rm_rf();
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("check --bench b1").run();
|
2018-08-29 06:11:10 +00:00
|
|
|
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
|
|
|
|
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
|
|
|
|
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
|
2019-03-26 20:21:05 +00:00
|
|
|
assert_eq!(p.glob("target/debug/b1-*").count(), 0);
|
|
|
|
assert_eq!(p.glob("target/debug/deps/libfoo-*.rmeta").count(), 1);
|
|
|
|
assert_eq!(p.glob("target/debug/deps/libb1-*.rmeta").count(), 1);
|
2017-10-07 16:28:34 +00:00
|
|
|
}
|
2018-05-11 15:04:10 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-08-09 20:13:42 +00:00
|
|
|
fn short_message_format() {
|
|
|
|
let foo = project()
|
|
|
|
.file("src/lib.rs", "fn foo() { let _x: bool = 'a'; }")
|
|
|
|
.build();
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("check --message-format=short")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains(
|
2018-08-09 20:13:42 +00:00
|
|
|
"\
|
|
|
|
src/lib.rs:1:27: error[E0308]: mismatched types
|
2023-08-09 15:19:59 +00:00
|
|
|
error: could not compile `foo` (lib) due to 1 previous error
|
2018-08-09 20:13:42 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-08-09 20:13:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-11 15:04:10 +00:00
|
|
|
fn proc_macro() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-05-11 15:04:10 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "demo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-05-11 15:04:10 +00:00
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
extern crate proc_macro;
|
|
|
|
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
|
|
|
#[proc_macro_derive(Foo)]
|
|
|
|
pub fn demo(_input: TokenStream) -> TokenStream {
|
|
|
|
"".parse().unwrap()
|
|
|
|
}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file(
|
2018-05-11 15:04:10 +00:00
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
#[macro_use]
|
|
|
|
extern crate demo;
|
|
|
|
|
|
|
|
#[derive(Foo)]
|
|
|
|
struct A;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2019-01-27 18:34:11 +00:00
|
|
|
p.cargo("check -v").env("CARGO_LOG", "cargo=trace").run();
|
2018-05-11 15:04:10 +00:00
|
|
|
}
|
2018-09-05 23:26:29 +00:00
|
|
|
|
2022-02-12 06:22:38 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn check_keep_going() {
|
|
|
|
let foo = project()
|
|
|
|
.file("src/bin/one.rs", "compile_error!(\"ONE\"); fn main() {}")
|
|
|
|
.file("src/bin/two.rs", "compile_error!(\"TWO\"); fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// Due to -j1, without --keep-going only one of the two bins would be built.
|
2023-08-26 16:49:49 +00:00
|
|
|
foo.cargo("check -j1 --keep-going")
|
2022-02-12 06:22:38 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("error: ONE")
|
|
|
|
.with_stderr_contains("error: TWO")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-05 23:26:29 +00:00
|
|
|
fn does_not_use_empty_rustc_wrapper() {
|
2022-07-24 20:10:35 +00:00
|
|
|
// An empty RUSTC_WRAPPER environment variable won't be used.
|
|
|
|
// The env var will also override the config, essentially unsetting it.
|
|
|
|
let p = project()
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
|
|
|
".cargo/config.toml",
|
|
|
|
r#"
|
|
|
|
[build]
|
|
|
|
rustc-wrapper = "do-not-execute-me"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
2018-09-05 23:26:29 +00:00
|
|
|
p.cargo("check").env("RUSTC_WRAPPER", "").run();
|
|
|
|
}
|
2018-09-23 21:11:25 +00:00
|
|
|
|
2019-10-22 14:53:51 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn does_not_use_empty_rustc_workspace_wrapper() {
|
|
|
|
let p = project().file("src/lib.rs", "").build();
|
2020-12-13 22:50:15 +00:00
|
|
|
p.cargo("check").env("RUSTC_WORKSPACE_WRAPPER", "").run();
|
2019-10-22 14:53:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-23 21:11:25 +00:00
|
|
|
fn error_from_deep_recursion() -> Result<(), fmt::Error> {
|
|
|
|
let mut big_macro = String::new();
|
|
|
|
writeln!(big_macro, "macro_rules! m {{")?;
|
|
|
|
for i in 0..130 {
|
|
|
|
writeln!(big_macro, "({}) => {{ m!({}); }};", i, i + 1)?;
|
|
|
|
}
|
|
|
|
writeln!(big_macro, "}}")?;
|
|
|
|
writeln!(big_macro, "m!(0);")?;
|
|
|
|
|
|
|
|
let p = project().file("src/lib.rs", &big_macro).build();
|
|
|
|
p.cargo("check --message-format=json")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stdout_contains(
|
2020-01-24 16:40:34 +00:00
|
|
|
"[..]\"message\":\"recursion limit reached while expanding [..]`m[..]`\"[..]",
|
2018-09-23 21:11:25 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-10-22 14:53:51 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn rustc_workspace_wrapper_affects_all_workspace_members() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2019-10-22 14:53:51 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
|
|
|
.build();
|
|
|
|
|
2020-12-13 22:50:15 +00:00
|
|
|
p.cargo("check")
|
2021-06-10 00:13:33 +00:00
|
|
|
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
|
2020-03-13 21:59:41 +00:00
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
|
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name baz [..]")
|
2019-10-22 14:53:51 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn rustc_workspace_wrapper_includes_path_deps() {
|
|
|
|
let p = project()
|
|
|
|
.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"
|
|
|
|
authors = []
|
2019-10-22 14:53:51 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar"]
|
2019-10-22 14:53:51 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
baz = { path = "baz" }
|
|
|
|
"#,
|
2019-10-22 14:53:51 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
|
|
|
.build();
|
|
|
|
|
2020-12-13 22:50:15 +00:00
|
|
|
p.cargo("check --workspace")
|
2021-06-10 00:13:33 +00:00
|
|
|
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
|
2020-03-13 21:59:41 +00:00
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name foo [..]")
|
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
|
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name baz [..]")
|
2019-10-22 14:53:51 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn rustc_workspace_wrapper_respects_primary_units() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar", "baz"]
|
|
|
|
"#,
|
2019-10-22 14:53:51 +00:00
|
|
|
)
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.file("baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
|
|
|
|
.file("baz/src/lib.rs", "pub fn baz() {}")
|
|
|
|
.build();
|
|
|
|
|
2020-12-13 22:50:15 +00:00
|
|
|
p.cargo("check -p bar")
|
2021-06-10 00:13:33 +00:00
|
|
|
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
|
2020-03-13 21:59:41 +00:00
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
|
2019-10-22 14:53:51 +00:00
|
|
|
.with_stdout_does_not_contain("WRAPPER CALLED: rustc --crate-name baz [..]")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn rustc_workspace_wrapper_excludes_published_deps() {
|
|
|
|
let p = project()
|
|
|
|
.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"
|
|
|
|
authors = []
|
2019-10-22 14:53:51 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[workspace]
|
|
|
|
members = ["bar"]
|
2019-10-22 14:53:51 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
baz = "1.0.0"
|
|
|
|
"#,
|
2019-10-22 14:53:51 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "pub fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Package::new("baz", "1.0.0").publish();
|
|
|
|
|
2020-12-13 22:50:15 +00:00
|
|
|
p.cargo("check --workspace -v")
|
2021-06-10 00:13:33 +00:00
|
|
|
.env("RUSTC_WORKSPACE_WRAPPER", tools::echo_wrapper())
|
2020-03-13 21:59:41 +00:00
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name foo [..]")
|
|
|
|
.with_stderr_contains("WRAPPER CALLED: rustc --crate-name bar [..]")
|
2019-10-22 14:53:51 +00:00
|
|
|
.with_stderr_contains("[CHECKING] baz [..]")
|
|
|
|
.with_stdout_does_not_contain("WRAPPER CALLED: rustc --crate-name baz [..]")
|
|
|
|
.run();
|
|
|
|
}
|
2022-09-26 16:32:07 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn warn_manifest_package_and_project() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[WARNING] manifest at `[CWD]` contains both `project` and `package`, this could become a hard error in the future
|
|
|
|
[CHECKING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn git_manifest_package_and_project() {
|
|
|
|
let p = project();
|
|
|
|
let git_project = git::new("bar", |p| {
|
|
|
|
p.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
});
|
|
|
|
|
|
|
|
let p = p
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
version = "0.0.1"
|
|
|
|
git = '{}'
|
|
|
|
|
|
|
|
"#,
|
|
|
|
git_project.url()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] git repository `[..]`
|
|
|
|
[CHECKING] bar v0.0.1 ([..])
|
|
|
|
[CHECKING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2022-09-26 16:32:48 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn warn_manifest_with_project() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[WARNING] manifest at `[CWD]` contains `[project]` instead of `[package]`, this could become a hard error in the future
|
|
|
|
[CHECKING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn git_manifest_with_project() {
|
|
|
|
let p = project();
|
|
|
|
let git_project = git::new("bar", |p| {
|
|
|
|
p.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[project]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
});
|
|
|
|
|
|
|
|
let p = p
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies.bar]
|
|
|
|
version = "0.0.1"
|
|
|
|
git = '{}'
|
|
|
|
|
|
|
|
"#,
|
|
|
|
git_project.url()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[UPDATING] git repository `[..]`
|
|
|
|
[CHECKING] bar v0.0.1 ([..])
|
|
|
|
[CHECKING] foo v0.0.1 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2022-10-28 00:07:59 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_fixable_warning() {
|
|
|
|
let foo = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "use std::io;")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
foo.cargo("check")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --lib -p foo` to apply 1 suggestion)")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_fixable_test_warning() {
|
|
|
|
let foo = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"\
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn t1() {
|
|
|
|
use std::io;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
foo.cargo("check --all-targets")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --lib -p foo --tests` to apply 1 suggestion)")
|
|
|
|
.run();
|
|
|
|
foo.cargo("fix --lib -p foo --tests --allow-no-vcs").run();
|
|
|
|
assert!(!foo.read_file("src/lib.rs").contains("use std::io;"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_fixable_error_no_fix() {
|
|
|
|
let foo = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
"use std::io;\n#[derive(Debug(x))]\nstruct Foo;",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let rustc_message = raw_rustc_output(&foo, "src/lib.rs", &[]);
|
|
|
|
let expected_output = format!(
|
|
|
|
"\
|
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
|
|
|
{}\
|
|
|
|
[WARNING] `foo` (lib) generated 1 warning
|
2023-08-09 15:19:59 +00:00
|
|
|
[ERROR] could not compile `foo` (lib) due to 1 previous error; 1 warning emitted
|
2022-10-28 00:07:59 +00:00
|
|
|
",
|
|
|
|
rustc_message
|
|
|
|
);
|
|
|
|
foo.cargo("check")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(expected_output)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_fixable_warning_workspace() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["foo", "bar"]
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("foo/src/lib.rs", "use std::io;")
|
|
|
|
.file(
|
|
|
|
"bar/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
foo = { path = "../foo" }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("bar/src/lib.rs", "use std::io;")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --lib -p foo` to apply 1 suggestion)")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --lib -p bar` to apply 1 suggestion)")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_fixable_example() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("examples/ex1.rs", "use std::fmt; fn main() {}")
|
|
|
|
.build();
|
|
|
|
p.cargo("check --all-targets")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --example \"ex1\"` to apply 1 suggestion)")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
|
|
|
fn check_fixable_bench() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_hello(_b: &mut test::Bencher) {
|
|
|
|
use std::io;
|
|
|
|
assert_eq!(hello(), "hello")
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"benches/bench.rs",
|
|
|
|
"
|
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_b: &mut test::Bencher) { use std::fmt; }
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
p.cargo("check --all-targets")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --bench \"bench\"` to apply 1 suggestion)")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(nightly, reason = "bench")]
|
|
|
|
fn check_fixable_mixed() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
fn hello() -> &'static str {
|
|
|
|
"hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
println!("{}", hello())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_hello(_b: &mut test::Bencher) {
|
|
|
|
use std::io;
|
|
|
|
assert_eq!(hello(), "hello")
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn t1() {
|
|
|
|
use std::fmt;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("examples/ex1.rs", "use std::fmt; fn main() {}")
|
|
|
|
.file(
|
|
|
|
"benches/bench.rs",
|
|
|
|
"
|
|
|
|
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench(_b: &mut test::Bencher) { use std::fmt; }
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
p.cargo("check --all-targets")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --bin \"foo\" --tests` to apply 2 suggestions)")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --example \"ex1\"` to apply 1 suggestion)")
|
|
|
|
.with_stderr_contains("[..] (run `cargo fix --bench \"bench\"` to apply 1 suggestion)")
|
|
|
|
.run();
|
|
|
|
}
|
2022-12-15 16:54:35 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_fixable_warning_for_clippy() {
|
|
|
|
let foo = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
// We don't want to show a warning that is `clippy`
|
|
|
|
// specific since we are using a `rustc` wrapper
|
|
|
|
// inplace of `clippy`
|
|
|
|
.file("src/lib.rs", "use std::io;")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
foo.cargo("check")
|
|
|
|
// We can't use `clippy` so we use a `rustc` workspace wrapper instead
|
2023-11-19 01:23:29 +00:00
|
|
|
.env("RUSTC_WORKSPACE_WRAPPER", tools::wrapped_clippy_driver())
|
2022-12-15 16:54:35 +00:00
|
|
|
.with_stderr_contains("[..] (run `cargo clippy --fix --lib -p foo` to apply 1 suggestion)")
|
|
|
|
.run();
|
|
|
|
}
|
2023-03-01 19:38:20 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn check_unused_manifest_keys() {
|
|
|
|
Package::new("dep", "0.1.0").publish();
|
|
|
|
Package::new("foo", "0.1.0").publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "bar"
|
|
|
|
version = "0.2.0"
|
|
|
|
authors = []
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep = { version = "0.1.0", wxz = "wxz" }
|
|
|
|
foo = { version = "0.1.0", abc = "abc" }
|
|
|
|
|
|
|
|
[dev-dependencies]
|
|
|
|
foo = { version = "0.1.0", wxz = "wxz" }
|
|
|
|
|
|
|
|
[build-dependencies]
|
|
|
|
foo = { version = "0.1.0", wxz = "wxz" }
|
|
|
|
|
|
|
|
[target.'cfg(windows)'.dependencies]
|
|
|
|
foo = { version = "0.1.0", wxz = "wxz" }
|
|
|
|
|
|
|
|
[target.x86_64-pc-windows-gnu.dev-dependencies]
|
|
|
|
foo = { version = "0.1.0", wxz = "wxz" }
|
|
|
|
|
|
|
|
[target.bar.build-dependencies]
|
|
|
|
foo = { version = "0.1.0", wxz = "wxz" }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[WARNING] unused manifest key: dependencies.dep.wxz
|
|
|
|
[WARNING] unused manifest key: dependencies.foo.abc
|
|
|
|
[WARNING] unused manifest key: dev-dependencies.foo.wxz
|
|
|
|
[WARNING] unused manifest key: build-dependencies.foo.wxz
|
|
|
|
[WARNING] unused manifest key: target.bar.build-dependencies.foo.wxz
|
|
|
|
[WARNING] unused manifest key: target.cfg(windows).dependencies.foo.wxz
|
|
|
|
[WARNING] unused manifest key: target.x86_64-pc-windows-gnu.dev-dependencies.foo.wxz
|
|
|
|
[UPDATING] `[..]` index
|
|
|
|
[DOWNLOADING] crates ...
|
|
|
|
[DOWNLOADED] foo v0.1.0 ([..])
|
|
|
|
[DOWNLOADED] dep v0.1.0 ([..])
|
|
|
|
[CHECKING] [..]
|
|
|
|
[CHECKING] [..]
|
|
|
|
[CHECKING] bar v0.2.0 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2023-10-04 18:00:37 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn versionless_package() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
description = "foo"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr(
|
2023-10-04 17:33:35 +00:00
|
|
|
"\
|
|
|
|
[CHECKING] foo v0.0.0 ([CWD])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
2023-10-04 18:00:37 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2024-01-18 05:27:56 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn pkgid_querystring_works() {
|
|
|
|
let git_project = git::new("gitdep", |p| {
|
|
|
|
p.file("Cargo.toml", &basic_manifest("gitdep", "1.0.0"))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
});
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
gitdep = {{ git = "{}", branch = "master" }}
|
|
|
|
"#,
|
|
|
|
git_project.url()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("generate-lockfile").run();
|
|
|
|
|
|
|
|
let output = p.cargo("pkgid").arg("gitdep").exec_with_output().unwrap();
|
|
|
|
let gitdep_pkgid = String::from_utf8(output.stdout).unwrap();
|
|
|
|
let gitdep_pkgid = gitdep_pkgid.trim();
|
|
|
|
compare::assert_match_exact("git+file://[..]/gitdep?branch=master#1.0.0", &gitdep_pkgid);
|
|
|
|
|
|
|
|
p.cargo("build -p")
|
|
|
|
.arg(gitdep_pkgid)
|
2024-01-18 05:29:23 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] gitdep v1.0.0 (file:///[..]/gitdep?branch=master#[..])
|
|
|
|
[FINISHED] dev [..]",
|
|
|
|
)
|
2024-01-18 05:27:56 +00:00
|
|
|
.run();
|
|
|
|
}
|