mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
test: migrate check_cfg to snapbox
This commit is contained in:
parent
471287ffed
commit
5a09fcb9f4
@ -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)?) => {{
|
||||
@ -31,6 +30,7 @@ macro_rules! x {
|
||||
}};
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn features() {
|
||||
let p = project()
|
||||
@ -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()
|
||||
@ -87,6 +87,7 @@ fn features_with_deps() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn features_with_opt_deps() {
|
||||
let p = project()
|
||||
@ -118,6 +119,7 @@ fn features_with_opt_deps() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn features_with_namespaced_features() {
|
||||
let p = project()
|
||||
@ -148,6 +150,7 @@ fn features_with_namespaced_features() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn features_fingerprint() {
|
||||
let p = project()
|
||||
@ -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()
|
||||
@ -231,6 +242,7 @@ fn well_known_names_values() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn features_test() {
|
||||
let p = project()
|
||||
@ -256,6 +268,7 @@ fn features_test() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn features_doctest() {
|
||||
let p = project()
|
||||
@ -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()
|
||||
@ -298,6 +311,7 @@ fn well_known_names_values_test() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn well_known_names_values_doctest() {
|
||||
let p = project()
|
||||
@ -313,6 +327,7 @@ fn well_known_names_values_doctest() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn features_doc() {
|
||||
let p = project()
|
||||
@ -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()
|
||||
@ -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()
|
||||
@ -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();
|
||||
@ -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()
|
||||
@ -524,6 +557,7 @@ fn config_simple() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn config_workspace() {
|
||||
let p = project()
|
||||
@ -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()
|
||||
@ -589,6 +631,7 @@ fn config_workspace_not_inherited() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn config_invalid_position() {
|
||||
let p = project()
|
||||
@ -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();
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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()
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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()
|
||||
@ -793,6 +860,7 @@ fn config_and_build_script() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn config_features_and_build_script() {
|
||||
let p = project()
|
||||
@ -828,6 +896,7 @@ fn config_features_and_build_script() {
|
||||
.run();
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cargo_test]
|
||||
fn config_fingerprint() {
|
||||
let p = project()
|
||||
|
Loading…
x
Reference in New Issue
Block a user