Skip to content

test: migrate check_cfg to snapbox #14235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 104 additions & 35 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Tests for Cargo usage of rustc `--check-cfg`.

#![allow(deprecated)]

use cargo_test_support::{basic_manifest, project};
use cargo_test_support::prelude::*;
use cargo_test_support::{basic_manifest, project, str};

macro_rules! x {
($tool:tt => $what:tt $(of $who:tt)?) => {{
Expand Down Expand Up @@ -31,6 +30,7 @@ macro_rules! x {
}};
}

#[allow(deprecated)]
#[cargo_test]
fn features() {
let p = project()
Expand All @@ -53,10 +53,10 @@ fn features() {
p.cargo("check -v")
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn features_with_deps() {
let p = project()
Expand Down Expand Up @@ -87,6 +87,7 @@ fn features_with_deps() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn features_with_opt_deps() {
let p = project()
Expand Down Expand Up @@ -118,6 +119,7 @@ fn features_with_opt_deps() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn features_with_namespaced_features() {
let p = project()
Expand Down Expand Up @@ -148,6 +150,7 @@ fn features_with_namespaced_features() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn features_fingerprint() {
let p = project()
Expand Down Expand Up @@ -210,14 +213,22 @@ fn features_fingerprint() {

p.cargo("check -v")
// we check that the fingerprint is indeed dirty
.with_stderr_contains("[..]Dirty[..]the list of declared features changed")
// that is cause rustc to be called again with the new check-cfg args
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a"))
// and that we indeed found a new warning from the unexpected_cfgs lint
.with_stderr_contains("[..]unexpected_cfgs[..]")
.with_stderr_data(format!(
"\
[DIRTY] foo v0.1.0 ([ROOT]/foo): the list of declared features changed
[CHECKING] foo v0.1.0 ([ROOT]/foo)
{running_rustc}
[WARNING] unexpected `cfg` condition value: `f_b`
...
",
running_rustc = x!("rustc" => "cfg" of "feature" with "f_a")
))
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn well_known_names_values() {
let p = project()
Expand All @@ -231,6 +242,7 @@ fn well_known_names_values() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn features_test() {
let p = project()
Expand All @@ -256,6 +268,7 @@ fn features_test() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn features_doctest() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the does_not_contains could be removed. If we were passing -Z, it would fail as this test runs on stable

let p = project()
Expand All @@ -281,10 +294,10 @@ fn features_doctest() {
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn well_known_names_values_test() {
let p = project()
Expand All @@ -298,6 +311,7 @@ fn well_known_names_values_test() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn well_known_names_values_doctest() {
let p = project()
Expand All @@ -313,6 +327,7 @@ fn well_known_names_values_doctest() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn features_doc() {
let p = project()
Expand All @@ -336,10 +351,10 @@ fn features_doc() {
p.cargo("doc -v")
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn build_script_feedback() {
let p = project()
Expand All @@ -364,10 +379,10 @@ fn build_script_feedback() {
p.cargo("check -v")
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn build_script_doc() {
let p = project()
Expand All @@ -391,21 +406,22 @@ fn build_script_doc() {

p.cargo("doc -v")
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
.with_stderr(
.with_stderr_data(format!(
"\
[COMPILING] foo v0.0.1 ([CWD])
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc [..] build.rs [..]`
[RUNNING] `[..]/build-script-build`
[DOCUMENTING] foo [..]
[RUNNING] `rustdoc [..] src/main.rs [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
[GENERATED] [CWD]/target/doc/foo/index.html
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
{running_rustdoc}
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
",
)
running_rustdoc = x!("rustdoc" => "cfg" of "foo")
))
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn build_script_override() {
let target = cargo_test_support::rustc_host();
Expand Down Expand Up @@ -491,14 +507,31 @@ fn build_script_test() {
.build();

p.cargo("test -v")
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
.with_stdout_contains("test test_foo ... ok")
.with_stdout_contains("test test_bar ... ok")
.with_stdout_contains_n("test [..] ... ok", 3)
.with_stderr_data(
format!(
"\
{running_rustc}
{running_rustdoc}
...
",
running_rustc = x!("rustc" => "cfg" of "foo"),
running_rustdoc = x!("rustdoc" => "cfg" of "foo")
)
.unordered(),
)
.with_stdout_data(
str![[r#"
test test_foo ... ok
test test_bar ... ok
test [..] ... ok
...
"#]]
.unordered(),
)
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_simple() {
let p = project()
Expand All @@ -524,6 +557,7 @@ fn config_simple() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_workspace() {
let p = project()
Expand Down Expand Up @@ -553,11 +587,19 @@ fn config_workspace() {
.build();

p.cargo("check -v")
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
.with_stderr_data(format!(
"\
...
{running_rustc}
...
",
running_rustc = x!("rustc" => "cfg" of "has_foo")
))
.with_stderr_does_not_contain("unexpected_cfgs")
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_workspace_not_inherited() {
let p = project()
Expand Down Expand Up @@ -589,6 +631,7 @@ fn config_workspace_not_inherited() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_invalid_position() {
let p = project()
Expand All @@ -608,7 +651,10 @@ fn config_invalid_position() {
.build();

p.cargo("check -v")
.with_stderr_contains("[..]unused manifest key: `lints.rust.use_bracket.check-cfg`[..]")
.with_stderr_data(str![[r#"
[WARNING] unused manifest key: `lints.rust.use_bracket.check-cfg`
...
"#]])
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "has_foo"))
.run();
}
Expand All @@ -633,7 +679,10 @@ fn config_invalid_empty() {

p.cargo("check")
.with_status(101)
.with_stderr_contains("[..]missing field `level`[..]")
.with_stderr_data(str![[r#"
[ERROR] missing field `level`
...
"#]])
.run();
}

Expand All @@ -657,9 +706,10 @@ fn config_invalid_not_list() {

p.cargo("check")
.with_status(101)
.with_stderr_contains(
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
)
.with_stderr_data(str![[r#"
[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string
...
"#]])
.run();
}

Expand All @@ -683,12 +733,14 @@ fn config_invalid_not_list_string() {

p.cargo("check")
.with_status(101)
.with_stderr_contains(
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
)
.with_stderr_data(str![[r#"
[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string
...
"#]])
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_and_features() {
let p = project()
Expand Down Expand Up @@ -737,7 +789,14 @@ fn config_with_cargo_doc() {
.build();

p.cargo("doc -v")
.with_stderr_contains(x!("rustdoc" => "cfg" of "has_foo"))
.with_stderr_data(format!(
"\
...
{running_rustdoc}
...
",
running_rustdoc = x!("rustdoc" => "cfg" of "has_foo")
))
.run();
}

Expand All @@ -760,10 +819,18 @@ fn config_with_cargo_test() {
.build();

p.cargo("test -v")
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
.with_stderr_data(format!(
"\
...
{running_rustc}
...
",
running_rustc = x!("rustc" => "cfg" of "has_foo")
))
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_and_build_script() {
let p = project()
Expand Down Expand Up @@ -793,6 +860,7 @@ fn config_and_build_script() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_features_and_build_script() {
let p = project()
Expand Down Expand Up @@ -828,6 +896,7 @@ fn config_features_and_build_script() {
.run();
}

#[allow(deprecated)]
#[cargo_test]
fn config_fingerprint() {
let p = project()
Expand Down