Skip to content

Commit

Permalink
Add preparatory tests for lib.test = false check-cfg changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Jan 4, 2025
1 parent fbca21b commit 208f817
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,127 @@ fn well_known_names_values_doctest() {
.run();
}

#[cargo_test]
fn test_false_lib() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2018"
[lib]
test = false
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check -v")
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
.run();

p.cargo("clean").run();
p.cargo("test -v")
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
.run();

p.cargo("clean").run();
p.cargo("test --lib -v")
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
.run();
}

#[cargo_test]
fn test_false_bins() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2018"
[[bin]]
name = "daemon"
test = false
path = "src/deamon.rs"
"#,
)
.file("src/main.rs", "fn main() {}")
.file("src/deamon.rs", "fn main() {}")
.build();

p.cargo("check -v")
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) // for foo & deamon
.run();
}

#[cargo_test]
fn test_false_examples() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2018"
[lib]
test = false
[[example]]
name = "daemon"
test = false
path = "src/deamon.rs"
"#,
)
.file("src/lib.rs", "")
.file("src/deamon.rs", "fn main() {}")
.build();

p.cargo("check --examples -v")
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
.run();
}

#[cargo_test(nightly, reason = "bench is nightly")]
fn test_false_benches() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.0"
edition = "2018"
[[bench]]
name = "ben1"
test = false
path = "benches/ben1.rs"
"#,
)
.file("src/lib.rs", "")
.file(
"benches/ben1.rs",
r#"
#![feature(test)]
extern crate test;
#[bench] fn run1(_ben: &mut test::Bencher) { }
"#,
)
.build();

p.cargo("bench --bench ben1 -v")
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test"))
.run();
}

#[cargo_test]
fn features_doc() {
let p = project()
Expand Down

0 comments on commit 208f817

Please sign in to comment.