Skip to content

Commit

Permalink
Update regular tests for always-on check-cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Apr 17, 2024
1 parent 2e73d67 commit a0a42ad
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 42 deletions.
9 changes: 7 additions & 2 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,10 @@ fn cfg_test() {
)
.file(
"build.rs",
r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#,
r#"fn main() {
println!("cargo::rustc-cfg=foo");
println!("cargo::rustc-check-cfg=cfg(foo)");
}"#,
)
.file(
"src/lib.rs",
Expand Down Expand Up @@ -2723,6 +2726,7 @@ fn cfg_override_test() {
r#"
[target.{}.a]
rustc-cfg = ["foo"]
rustc-check-cfg = ["cfg(foo)"]
"#,
rustc_host()
),
Expand Down Expand Up @@ -5557,9 +5561,10 @@ fn build_script_rerun_when_target_rustflags_change() {
use std::env;
fn main() {
println!("cargo::rustc-check-cfg=cfg(enable)");
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {
println!("cargo::rustc-cfg=enable")
println!("cargo::rustc-cfg=enable");
}
}
}
Expand Down
60 changes: 29 additions & 31 deletions tests/testsuite/cargo/z_help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ fn no_implicit_feature() {
r#"
fn main() {
if cfg!(feature = "regex") { println!("regex"); }
if cfg!(feature = "lazy_static") { println!("lazy_static"); }
// #[expect(unexpected_cfgs)]
// if cfg!(feature = "lazy_static") { println!("lazy_static"); }
}
"#,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/package_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ fn virtual_with_specific() {
.file(
"a/src/lib.rs",
r#"
#[cfg(not_feature = "f1")]
#[cfg(not(feature = "f1"))]
compile_error!{"f1 is missing"}
#[cfg(not_feature = "f2")]
#[cfg(not(feature = "f2"))]
compile_error!{"f2 is missing"}
"#,
)
Expand All @@ -211,9 +211,9 @@ fn virtual_with_specific() {
.file(
"b/src/lib.rs",
r#"
#[cfg(not_feature = "f2")]
#[cfg(not(feature = "f2"))]
compile_error!{"f2 is missing"}
#[cfg(not_feature = "f3")]
#[cfg(not(feature = "f3"))]
compile_error!{"f3 is missing"}
"#,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn profile_overrides() {
[RUNNING] `rustc --crate-name test --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]\
-C opt-level=1[..]\
-C debug-assertions=on \
-C debug-assertions=on[..] \
-C metadata=[..] \
-C rpath \
--out-dir [..] \
Expand Down Expand Up @@ -141,7 +141,7 @@ fn check_opt_level_override(profile_level: &str, rustc_level: &str) {
--emit=[..]link \
-C opt-level={level}[..]\
-C debuginfo=2 [..]\
-C debug-assertions=on \
-C debug-assertions=on[..] \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn lib() {
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C debug-assertions=off \
-C debug-assertions=off [..] \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
Expand Down Expand Up @@ -69,7 +69,7 @@ fn build_main_and_allow_unstable_options() {
-L dependency=[CWD]/target/debug/deps`
[RUNNING] `rustc --crate-name {name} --edition=2015 src/main.rs [..]--crate-type bin \
--emit=[..]link[..]-C debuginfo=2 [..]\
-C debug-assertions \
-C debug-assertions [..] \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps \
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/rustflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,7 @@ fn two_matching_in_config() {
.file(
"src/main.rs",
r#"
#![allow(unexpected_cfgs)]
fn main() {
if cfg!(foo = "a") {
println!("a");
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/weak_dep_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::fmt::Write;
// Helper to create lib.rs files that check features.
fn require(enabled_features: &[&str], disabled_features: &[&str]) -> String {
let mut s = String::new();
writeln!(s, "#![allow(unexpected_cfgs)]").unwrap();
for feature in enabled_features {
writeln!(s, "#[cfg(not(feature=\"{feature}\"))] compile_error!(\"expected feature {feature} to be enabled\");",
feature=feature).unwrap();
Expand Down

0 comments on commit a0a42ad

Please sign in to comment.