From 43c193a833608d04e564ed9fd48ac59c1b8c021e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Tue, 12 Apr 2022 19:44:13 +0200 Subject: [PATCH 1/5] Merge of unstable check-cfg cargo flags into -Zcheck-cfg --- src/cargo/core/compiler/mod.rs | 59 +++++++++++++++---------------- src/cargo/core/features.rs | 29 +++++++++++---- src/doc/src/reference/unstable.md | 43 +++++++--------------- 3 files changed, 65 insertions(+), 66 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 1ae87daa241..74900bb4fb4 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -1055,43 +1055,42 @@ fn features_args(_cx: &Context<'_, '_>, unit: &Unit) -> Vec { /// Generate the --check-cfg arguments for the unit fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec { - if !cx.bcx.config.cli_unstable().check_cfg_features - && !cx.bcx.config.cli_unstable().check_cfg_well_known_names - && !cx.bcx.config.cli_unstable().check_cfg_well_known_values + if let Some((features, well_known_names, well_known_values)) = + cx.bcx.config.cli_unstable().check_cfg { - return Vec::new(); - } - - let mut args = Vec::with_capacity(unit.pkg.summary().features().len() * 2 + 4); - args.push(OsString::from("-Zunstable-options")); + let mut args = Vec::with_capacity(unit.pkg.summary().features().len() * 2 + 4); + args.push(OsString::from("-Zunstable-options")); + + if features { + // This generate something like this: + // - values(feature) + // - values(feature, "foo", "bar") + let mut arg = OsString::from("values(feature"); + for (&feat, _) in unit.pkg.summary().features() { + arg.push(", \""); + arg.push(&feat); + arg.push("\""); + } + arg.push(")"); - if cx.bcx.config.cli_unstable().check_cfg_features { - // This generate something like this: - // - values(feature) - // - values(feature, "foo", "bar") - let mut arg = OsString::from("values(feature"); - for (&feat, _) in unit.pkg.summary().features() { - arg.push(", \""); - arg.push(&feat); - arg.push("\""); + args.push(OsString::from("--check-cfg")); + args.push(arg); } - arg.push(")"); - args.push(OsString::from("--check-cfg")); - args.push(arg); - } + if well_known_names { + args.push(OsString::from("--check-cfg")); + args.push(OsString::from("names()")); + } - if cx.bcx.config.cli_unstable().check_cfg_well_known_names { - args.push(OsString::from("--check-cfg")); - args.push(OsString::from("names()")); - } + if well_known_values { + args.push(OsString::from("--check-cfg")); + args.push(OsString::from("values()")); + } - if cx.bcx.config.cli_unstable().check_cfg_well_known_values { - args.push(OsString::from("--check-cfg")); - args.push(OsString::from("values()")); + args + } else { + Vec::new() } - - args } fn lto_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec { diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index f4104e8c9b0..99d72d099e6 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -641,9 +641,7 @@ unstable_cli_options!( build_std_features: Option> = ("Configure features enabled for the standard library itself when building the standard library"), config_include: bool = ("Enable the `include` key in config files"), credential_process: bool = ("Add a config setting to fetch registry authentication tokens by calling an external process"), - check_cfg_features: bool = ("Enable compile-time checking of features in `cfg`"), - check_cfg_well_known_names: bool = ("Enable compile-time checking of well known names in `cfg`"), - check_cfg_well_known_values: bool = ("Enable compile-time checking of well known values in `cfg`"), + check_cfg: Option<(/*features:*/ bool, /*well_known_names:*/ bool, /*well_known_values:*/ bool)> = ("Specify scope of compile-time checking of `cfg` names/values"), doctest_in_workspace: bool = ("Compile doctests with paths relative to the workspace root"), doctest_xcompile: bool = ("Compile and run doctests for non-host target using runner config"), dual_proc_macros: bool = ("Build proc-macros for both the host and the target"), @@ -785,6 +783,27 @@ impl CliUnstable { } } + fn parse_check_cfg(value: Option<&str>) -> CargoResult> { + if let Some(value) = value { + let mut features = false; + let mut well_known_names = false; + let mut well_known_values = false; + + for e in value.split(',') { + match e { + "features" => features = true, + "names" => well_known_names = true, + "values" => well_known_values = true, + _ => bail!("flag -Zcheck-cfg only takes `features`, `names` or `values` as valid inputs"), + } + } + + Ok(Some((features, well_known_names, well_known_values))) + } else { + Ok(None) + } + } + // Asserts that there is no argument to the flag. fn parse_empty(key: &str, value: Option<&str>) -> CargoResult { if let Some(v) = value { @@ -842,9 +861,7 @@ impl CliUnstable { "minimal-versions" => self.minimal_versions = parse_empty(k, v)?, "advanced-env" => self.advanced_env = parse_empty(k, v)?, "config-include" => self.config_include = parse_empty(k, v)?, - "check-cfg-features" => self.check_cfg_features = parse_empty(k, v)?, - "check-cfg-well-known-names" => self.check_cfg_well_known_names = parse_empty(k, v)?, - "check-cfg-well-known-values" => self.check_cfg_well_known_values = parse_empty(k, v)?, + "check-cfg" => self.check_cfg = parse_check_cfg(v)?, "dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?, // can also be set in .cargo/config or with and ENV "mtime-on-use" => self.mtime_on_use = parse_empty(k, v)?, diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 16cb9dc6a7a..b3badd43c19 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -1188,44 +1188,27 @@ For instance: cargo doc -Z unstable-options -Z rustdoc-scrape-examples=examples ``` -### check-cfg-features +### check-cfg * RFC: [#3013](https://github.com/rust-lang/rfcs/pull/3013) +* Tracking Issue: [#10554](https://github.com/rust-lang/cargo/issues/10554) -The `-Z check-cfg-features` argument tells Cargo to pass all possible features of a package to -`rustc` and `rustdoc` unstable `--check-cfg` command line as `--check-cfg=values(feature, ...)`. -This enables compile time checking of feature values in `#[cfg]`, `cfg!` and `#[cfg_attr]`. -Note than this command line options will probably become the default when stabilizing. -For instance: - -``` -cargo check -Z unstable-options -Z check-cfg-features -``` - -### check-cfg-well-known-names - -* RFC: [#3013](https://github.com/rust-lang/rfcs/pull/3013) +`-Z check-cfg` command line enables compile time checking of name and values in `#[cfg]`, `cfg!`, +`#[link]` and `#[cfg_attr]` with the `rustc` and `rustdoc` unstable `--check-cfg` command line. -The `-Z check-cfg-well-known-names` argument tells Cargo to activate `rustc` and `rustdoc` unstable -`--check-cfg` command line as `--check-cfg=names()`. -This enables compile time checking of well known names in `#[cfg]`, `cfg!` and `#[cfg_attr]`. -For instance: - -``` -cargo check -Z unstable-options -Z check-cfg-well-known-names -``` - -### check-cfg-well-known-values - -* RFC: [#3013](https://github.com/rust-lang/rfcs/pull/3013) +It's values are: + - `features`: enables features checking via `--check-cfg=values(feature, ...)`. + Note than this command line options will probably become the default when stabilizing. + - `names`: enables well known names checking via `--check-cfg=names()`. + - `values`: enables well known values checking via `--check-cfg=values()`. -The `-Z check-cfg-well-known-values` argument tells Cargo to activate `rustc` and `rustdoc` unstable -`--check-cfg` command line as `--check-cfg=values()`. -This enables compile time checking of well known values in `#[cfg]`, `cfg!` and `#[cfg_attr]`. For instance: ``` -cargo check -Z unstable-options -Z check-cfg-well-known-values +cargo check -Z unstable-options -Z check-cfg=features +cargo check -Z unstable-options -Z check-cfg=names +cargo check -Z unstable-options -Z check-cfg=values +cargo check -Z unstable-options -Z check-cfg=features,names,values ``` ### workspace-inheritance From 6a9f094c8ce4e387bd3856ddc67b4616c067e4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Tue, 12 Apr 2022 19:46:47 +0200 Subject: [PATCH 2/5] Convert the testsuite to use the new -Zcheck-cfg flag and syntax --- tests/testsuite/build.rs | 14 +++++++------- tests/testsuite/check.rs | 6 +++--- tests/testsuite/doc.rs | 2 +- tests/testsuite/test.rs | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 67ef5db4f36..e6268ac7a62 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -6249,7 +6249,7 @@ fn check_cfg_features() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("build -v -Z check-cfg-features") + p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -6290,7 +6290,7 @@ fn check_cfg_features_with_deps() { .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") .build(); - p.cargo("build -v -Z check-cfg-features") + p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -6334,7 +6334,7 @@ fn check_cfg_features_with_opt_deps() { .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") .build(); - p.cargo("build -v -Z check-cfg-features") + p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -6377,7 +6377,7 @@ fn check_cfg_features_with_namespaced_features() { .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") .build(); - p.cargo("build -v -Z check-cfg-features") + p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -6402,7 +6402,7 @@ fn check_cfg_well_known_names() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("build -v -Z check-cfg-well-known-names") + p.cargo("build -v -Zcheck-cfg=names") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -6427,7 +6427,7 @@ fn check_cfg_well_known_values() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("build -v -Z check-cfg-well-known-values") + p.cargo("build -v -Zcheck-cfg=values") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -6463,7 +6463,7 @@ fn check_cfg_all() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("build -v -Z check-cfg-features -Z check-cfg-well-known-names -Z check-cfg-well-known-values") + p.cargo("build -v -Zcheck-cfg=features,names,values") .masquerade_as_nightly_cargo() .with_stderr( "\ diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index c8c302eb026..eda525670b4 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -1039,7 +1039,7 @@ fn check_cfg_features() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("check -v -Z check-cfg-features") + p.cargo("check -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -1064,7 +1064,7 @@ fn check_cfg_well_known_names() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("check -v -Z check-cfg-well-known-names") + p.cargo("check -v -Zcheck-cfg=names") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -1089,7 +1089,7 @@ fn check_cfg_well_known_values() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("check -v -Z check-cfg-well-known-values") + p.cargo("check -v -Zcheck-cfg=values") .masquerade_as_nightly_cargo() .with_stderr( "\ diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index a5d637d3db1..82125e6e4eb 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -2808,7 +2808,7 @@ fn doc_check_cfg_features() { .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") .build(); - p.cargo("doc -v -Z check-cfg-features") + p.cargo("doc -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 4c1dc880ba5..b304b706add 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -4524,7 +4524,7 @@ fn check_cfg_features() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("test -v -Z check-cfg-features") + p.cargo("test -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -4562,7 +4562,7 @@ fn check_cfg_features_doc() { .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") .build(); - p.cargo("test -v --doc -Z check-cfg-features") + p.cargo("test -v --doc -Zcheck-cfg=features") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -4589,7 +4589,7 @@ fn check_cfg_well_known_names() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("test -v -Z check-cfg-well-known-names") + p.cargo("test -v -Zcheck-cfg=names") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -4615,7 +4615,7 @@ fn check_cfg_well_known_values() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("test -v -Z check-cfg-well-known-values") + p.cargo("test -v -Zcheck-cfg=values") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -4641,7 +4641,7 @@ fn check_cfg_well_known_names_doc() { .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") .build(); - p.cargo("test -v --doc -Z check-cfg-well-known-names") + p.cargo("test -v --doc -Zcheck-cfg=names") .masquerade_as_nightly_cargo() .with_stderr( "\ @@ -4668,7 +4668,7 @@ fn check_cfg_well_known_values_doc() { .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") .build(); - p.cargo("test -v --doc -Z check-cfg-well-known-values") + p.cargo("test -v --doc -Zcheck-cfg=values") .masquerade_as_nightly_cargo() .with_stderr( "\ From 2d0ca84b0e698da4dabd9399d6057db30758f3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Thu, 14 Apr 2022 12:20:36 +0200 Subject: [PATCH 3/5] Move check cfg tests to their own module --- tests/testsuite/build.rs | 250 ---------------- tests/testsuite/check.rs | 87 ------ tests/testsuite/check_cfg.rs | 551 +++++++++++++++++++++++++++++++++++ tests/testsuite/doc.rs | 37 --- tests/testsuite/main.rs | 1 + tests/testsuite/test.rs | 182 ------------ 6 files changed, 552 insertions(+), 556 deletions(-) create mode 100644 tests/testsuite/check_cfg.rs diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index e6268ac7a62..828648ef3b7 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -6224,253 +6224,3 @@ fn primary_package_env_var() { foo.cargo("test").run(); } - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_features() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [features] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("build -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_features_with_deps() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [dependencies] - bar = { path = "bar/" } - - [features] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) - .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") - .build(); - - p.cargo("build -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] bar v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature)' [..] -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_features_with_opt_deps() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [dependencies] - bar = { path = "bar/", optional = true } - - [features] - default = ["bar"] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) - .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") - .build(); - - p.cargo("build -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] bar v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature)' [..] -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"bar\", \"default\", \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_features_with_namespaced_features() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [dependencies] - bar = { path = "bar/", optional = true } - - [features] - f_a = ["dep:bar"] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) - .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") - .build(); - - p.cargo("build -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_names() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("build -v -Zcheck-cfg=names") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_values() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("build -v -Zcheck-cfg=values") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_all() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [features] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("build -v -Zcheck-cfg=features,names,values") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' --check-cfg 'names()' --check-cfg 'values()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index eda525670b4..e10f4cdc693 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -3,7 +3,6 @@ use std::fmt::{self, Write}; use cargo_test_support::install::exe; -use cargo_test_support::is_nightly; use cargo_test_support::paths::CargoPathExt; use cargo_test_support::registry::Package; use cargo_test_support::tools; @@ -1014,89 +1013,3 @@ fn rustc_workspace_wrapper_excludes_published_deps() { .with_stdout_does_not_contain("WRAPPER CALLED: rustc --crate-name baz [..]") .run(); } - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_features() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [features] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[CHECKING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_names() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=names") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[CHECKING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_values() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("check -v -Zcheck-cfg=values") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[CHECKING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); -} diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs new file mode 100644 index 00000000000..ee890eebe51 --- /dev/null +++ b/tests/testsuite/check_cfg.rs @@ -0,0 +1,551 @@ +//! Tests for -Zcheck-cfg. + +use cargo_test_support::{basic_manifest, is_nightly, project}; + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [features] + f_a = [] + f_b = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("build -v -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features_with_deps() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [dependencies] + bar = { path = "bar/" } + + [features] + f_a = [] + f_b = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") + .build(); + + p.cargo("build -v -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] bar v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values(feature)' [..] +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features_with_opt_deps() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [dependencies] + bar = { path = "bar/", optional = true } + + [features] + default = ["bar"] + f_a = [] + f_b = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") + .build(); + + p.cargo("build -v -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] bar v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values(feature)' [..] +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"bar\", \"default\", \"f_a\", \"f_b\")' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features_with_namespaced_features() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [dependencies] + bar = { path = "bar/", optional = true } + + [features] + f_a = ["dep:bar"] + f_b = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}") + .build(); + + p.cargo("build -v -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_names() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("build -v -Zcheck-cfg=names") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'names()' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_values() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("build -v -Zcheck-cfg=values") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values()' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn cli_all_options() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [features] + f_a = [] + f_b = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("build -v -Zcheck-cfg=features,names,values") + .masquerade_as_nightly_cargo() + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features_with_cargo_check() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [features] + f_a = [] + f_b = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check -v -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[CHECKING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_names_with_check() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check -v -Zcheck-cfg=names") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[CHECKING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'names()' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_values_with_check() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check -v -Zcheck-cfg=values") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[CHECKING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values()' [..] +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features_test() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [features] + f_a = [] + f_b = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("test -v -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[RUNNING] [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features_doctest() { + if !is_nightly() { + // --check-cfg is a nightly only rustc and rustdoc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [features] + default = ["f_a"] + f_a = [] + f_b = [] + "#, + ) + .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") + .build(); + + p.cargo("test -v --doc -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[DOCTEST] foo +[RUNNING] `rustdoc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_names_test() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("test -v -Zcheck-cfg=names") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'names()' [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[RUNNING] [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_values_test() { + if !is_nightly() { + // --check-cfg is a nightly only rustc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("test -v -Zcheck-cfg=values") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values()' [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[RUNNING] [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_names_doctest() { + if !is_nightly() { + // --check-cfg is a nightly only rustc and rustdoc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") + .build(); + + p.cargo("test -v --doc -Zcheck-cfg=names") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'names()' [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[DOCTEST] foo +[RUNNING] `rustdoc [..] --check-cfg 'names()' [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn well_known_values_doctest() { + if !is_nightly() { + // --check-cfg is a nightly only rustc and rustdoc command line + return; + } + + let p = project() + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") + .build(); + + p.cargo("test -v --doc -Zcheck-cfg=values") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[COMPILING] foo v0.1.0 [..] +[RUNNING] `rustc [..] --check-cfg 'values()' [..] +[FINISHED] test [unoptimized + debuginfo] target(s) in [..] +[DOCTEST] foo +[RUNNING] `rustdoc [..] --check-cfg 'values()' [..] +", + ) + .run(); +} + +#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +#[cargo_test] +fn features_doc() { + if !is_nightly() { + // --check-cfg is a nightly only rustdoc command line + return; + } + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.1.0" + + [features] + default = ["f_a"] + f_a = [] + f_b = [] + "#, + ) + .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") + .build(); + + p.cargo("doc -v -Zcheck-cfg=features") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[DOCUMENTING] foo v0.1.0 [..] +[RUNNING] `rustdoc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] +[FINISHED] [..] +", + ) + .run(); +} diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 82125e6e4eb..bd799d1d1b8 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -2783,43 +2783,6 @@ fn doc_lib_false_dep() { assert!(!p.build_dir().join("doc/bar").exists()); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn doc_check_cfg_features() { - if !is_nightly() { - // --check-cfg is a nightly only rustdoc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [features] - default = ["f_a"] - f_a = [] - f_b = [] - "#, - ) - .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") - .build(); - - p.cargo("doc -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[DOCUMENTING] foo v0.1.0 [..] -[RUNNING] `rustdoc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] -[FINISHED] [..] -", - ) - .run(); -} - #[cargo_test] fn link_to_private_item() { let main = r#" diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 134bbf5d9fb..cd817d744d3 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -28,6 +28,7 @@ mod cargo_features; mod cargo_targets; mod cfg; mod check; +mod check_cfg; mod clean; mod collisions; mod concurrent; diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index b304b706add..1f79df90293 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -4499,185 +4499,3 @@ fn test_workspaces_cwd() { .with_stdout_contains("test test_integration_deep_cwd ... ok") .run(); } - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_features() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [features] - f_a = [] - f_b = [] - "#, - ) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("test -v -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_features_doc() { - if !is_nightly() { - // --check-cfg is a nightly only rustc and rustdoc command line - return; - } - - let p = project() - .file( - "Cargo.toml", - r#" - [project] - name = "foo" - version = "0.1.0" - - [features] - default = ["f_a"] - f_a = [] - f_b = [] - "#, - ) - .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") - .build(); - - p.cargo("test -v --doc -Zcheck-cfg=features") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[DOCTEST] foo -[RUNNING] `rustdoc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_names() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("test -v -Zcheck-cfg=names") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_values() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/main.rs", "fn main() {}") - .build(); - - p.cargo("test -v -Zcheck-cfg=values") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_names_doc() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") - .build(); - - p.cargo("test -v --doc -Zcheck-cfg=names") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[DOCTEST] foo -[RUNNING] `rustdoc [..] --check-cfg 'names()' [..] -", - ) - .run(); -} - -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support -#[cargo_test] -fn check_cfg_well_known_values_doc() { - if !is_nightly() { - // --check-cfg is a nightly only rustc command line - return; - } - - let p = project() - .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) - .file("src/lib.rs", "#[allow(dead_code)] fn foo() {}") - .build(); - - p.cargo("test -v --doc -Zcheck-cfg=values") - .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[DOCTEST] foo -[RUNNING] `rustdoc [..] --check-cfg 'values()' [..] -", - ) - .run(); -} From cf496db45e7336cb3ad3d7ece6fcfb2a861ed915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Thu, 14 Apr 2022 14:16:35 +0200 Subject: [PATCH 4/5] Re-enable check-cfg tests under windows with a custom macro for escaping --- tests/testsuite/check_cfg.rs | 193 +++++++++-------------------------- 1 file changed, 51 insertions(+), 142 deletions(-) diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index ee890eebe51..2ce3ca4f154 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -2,7 +2,33 @@ use cargo_test_support::{basic_manifest, is_nightly, project}; -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support +macro_rules! x { + ($tool:tt => $what:tt $(of $who:tt)?) => {{ + #[cfg(windows)] + { + concat!("[RUNNING] [..]", $tool, "[..] --check-cfg ", + $what, '(', $($who,)* ')', "[..]") + } + #[cfg(not(windows))] + { + concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '", + $what, '(', $($who,)* ')', "'", "[..]") + } + }}; + ($tool:tt => $what:tt of $who:tt with $($values:tt)*) => {{ + #[cfg(windows)] + { + concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"", + $what, '(', $who, $(", ", "/\"", $values, "/\"",)* ")", '"', "[..]") + } + #[cfg(not(windows))] + { + concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '", + $what, '(', $who, $(", ", "\"", $values, "\"",)* ")", "'", "[..]") + } + }}; +} + #[cargo_test] fn features() { if !is_nightly() { @@ -28,17 +54,10 @@ fn features() { p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn features_with_deps() { if !is_nightly() { @@ -69,19 +88,11 @@ fn features_with_deps() { p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] bar v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature)' [..] -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "values" of "feature")) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn features_with_opt_deps() { if !is_nightly() { @@ -113,19 +124,11 @@ fn features_with_opt_deps() { p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] bar v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature)' [..] -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"bar\", \"default\", \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "values" of "feature")) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "bar" "default" "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn features_with_namespaced_features() { if !is_nightly() { @@ -156,17 +159,10 @@ fn features_with_namespaced_features() { p.cargo("build -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc --crate-name foo [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_names() { if !is_nightly() { @@ -181,17 +177,10 @@ fn well_known_names() { p.cargo("build -v -Zcheck-cfg=names") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "names")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_values() { if !is_nightly() { @@ -206,17 +195,10 @@ fn well_known_values() { p.cargo("build -v -Zcheck-cfg=values") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "values")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn cli_all_options() { if !is_nightly() { @@ -242,10 +224,12 @@ fn cli_all_options() { p.cargo("build -v -Zcheck-cfg=features,names,values") .masquerade_as_nightly_cargo() + .with_stderr_contains(x!("rustc" => "names")) + .with_stderr_contains(x!("rustc" => "values")) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn features_with_cargo_check() { if !is_nightly() { @@ -271,17 +255,10 @@ fn features_with_cargo_check() { p.cargo("check -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[CHECKING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_names_with_check() { if !is_nightly() { @@ -296,17 +273,10 @@ fn well_known_names_with_check() { p.cargo("check -v -Zcheck-cfg=names") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[CHECKING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "names")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_values_with_check() { if !is_nightly() { @@ -321,17 +291,10 @@ fn well_known_values_with_check() { p.cargo("check -v -Zcheck-cfg=values") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[CHECKING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_contains(x!("rustc" => "values")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn features_test() { if !is_nightly() { @@ -357,18 +320,10 @@ fn features_test() { p.cargo("test -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"f_a\", \"f_b\")' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] -", - ) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn features_doctest() { if !is_nightly() { @@ -395,19 +350,11 @@ fn features_doctest() { p.cargo("test -v --doc -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[DOCTEST] foo -[RUNNING] `rustdoc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] -", - ) + .with_stderr_contains(x!("rustc" => "values" of "feature" with "default" "f_a" "f_b")) + .with_stderr_contains(x!("rustdoc" => "values" of "feature" with "default" "f_a" "f_b")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_names_test() { if !is_nightly() { @@ -422,18 +369,10 @@ fn well_known_names_test() { p.cargo("test -v -Zcheck-cfg=names") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] -", - ) + .with_stderr_contains(x!("rustc" => "names")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_values_test() { if !is_nightly() { @@ -448,18 +387,10 @@ fn well_known_values_test() { p.cargo("test -v -Zcheck-cfg=values") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] -", - ) + .with_stderr_contains(x!("rustc" => "values")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_names_doctest() { if !is_nightly() { @@ -474,19 +405,11 @@ fn well_known_names_doctest() { p.cargo("test -v --doc -Zcheck-cfg=names") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'names()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[DOCTEST] foo -[RUNNING] `rustdoc [..] --check-cfg 'names()' [..] -", - ) + .with_stderr_contains(x!("rustc" => "names")) + .with_stderr_contains(x!("rustdoc" => "names")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn well_known_values_doctest() { if !is_nightly() { @@ -501,19 +424,11 @@ fn well_known_values_doctest() { p.cargo("test -v --doc -Zcheck-cfg=values") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[COMPILING] foo v0.1.0 [..] -[RUNNING] `rustc [..] --check-cfg 'values()' [..] -[FINISHED] test [unoptimized + debuginfo] target(s) in [..] -[DOCTEST] foo -[RUNNING] `rustdoc [..] --check-cfg 'values()' [..] -", - ) + .with_stderr_contains(x!("rustc" => "values")) + .with_stderr_contains(x!("rustdoc" => "values")) .run(); } -#[cfg_attr(windows, ignore)] // weird normalization issue with windows and cargo-test-support #[cargo_test] fn features_doc() { if !is_nightly() { @@ -540,12 +455,6 @@ fn features_doc() { p.cargo("doc -v -Zcheck-cfg=features") .masquerade_as_nightly_cargo() - .with_stderr( - "\ -[DOCUMENTING] foo v0.1.0 [..] -[RUNNING] `rustdoc [..] --check-cfg 'values(feature, \"default\", \"f_a\", \"f_b\")' [..] -[FINISHED] [..] -", - ) + .with_stderr_contains(x!("rustdoc" => "values" of "feature" with "default" "f_a" "f_b")) .run(); } From 6f2fae10ea5d0796b82259535fc837b2f713c438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Thu, 14 Apr 2022 14:18:13 +0200 Subject: [PATCH 5/5] Remove now unused context arg --- src/cargo/core/compiler/context/mod.rs | 2 +- src/cargo/core/compiler/mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/context/mod.rs b/src/cargo/core/compiler/context/mod.rs index edd8dc1a8bd..8447895317c 100644 --- a/src/cargo/core/compiler/context/mod.rs +++ b/src/cargo/core/compiler/context/mod.rs @@ -224,7 +224,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { let mut unstable_opts = false; let mut args = compiler::extern_args(&self, unit, &mut unstable_opts)?; args.extend(compiler::lto_args(&self, unit)); - args.extend(compiler::features_args(&self, unit)); + args.extend(compiler::features_args(unit)); args.extend(compiler::check_cfg_args(&self, unit)); let script_meta = self.find_build_script_metadata(unit); diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 74900bb4fb4..553778206db 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -645,7 +645,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { paths::create_dir_all(&doc_dir)?; rustdoc.arg("-o").arg(&doc_dir); - rustdoc.args(&features_args(cx, unit)); + rustdoc.args(&features_args(unit)); rustdoc.args(&check_cfg_args(cx, unit)); add_error_format_and_color(cx, &mut rustdoc); @@ -966,7 +966,7 @@ fn build_base_args( cmd.arg("--cfg").arg("test"); } - cmd.args(&features_args(cx, unit)); + cmd.args(&features_args(unit)); cmd.args(&check_cfg_args(cx, unit)); let meta = cx.files().metadata(unit); @@ -1042,7 +1042,7 @@ fn build_base_args( } /// All active features for the unit passed as --cfg -fn features_args(_cx: &Context<'_, '_>, unit: &Unit) -> Vec { +fn features_args(unit: &Unit) -> Vec { let mut args = Vec::with_capacity(unit.features.len() * 2); for feat in &unit.features {