From 23f59d4eeb85de6766b3dd7b3d0ee4d19a448c13 Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 29 Jun 2022 14:51:40 +0200 Subject: [PATCH] Add regression tests for check-cfg unstable config --- tests/testsuite/check_cfg.rs | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index ab7d4f9a2..330a0ae97 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -629,3 +629,74 @@ fn build_script_test() { .masquerade_as_nightly_cargo() .run(); } + +#[cargo_test] +fn config_valid() { + 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() {}") + .file( + ".cargo/config.toml", + r#" + [unstable] + check-cfg = ["features", "names", "values"] + "#, + ) + .build(); + + 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(); +} + +#[cargo_test] +fn config_invalid() { + 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" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file( + ".cargo/config.toml", + r#" + [unstable] + check-cfg = ["va"] + "#, + ) + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_stderr_contains("error: unstable check-cfg only takes `features`, `names`, `values` or `output` as valid inputs") + .with_status(101) + .run(); +}