Skip to content

Commit

Permalink
Adding cfg_all
Browse files Browse the repository at this point in the history
  • Loading branch information
simsekgokhan committed Apr 25, 2024
1 parent 1ad36df commit c192b66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ clap = "4.0.32"
# Using features (aka conditional compilation with cfg)
[features]
foo = [] # feature has no explicit dependencies
aa = [] # feature has no explicit dependencies

# Todo: how to use them?
# Compile time env. vars
Expand Down
8 changes: 8 additions & 0 deletions src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ const XX : i32 = 44;
#[test] fn ex_1_should_fail_with_foo() {
assert_eq!(XX, 44);
}

// Using: if cfg!(feature = "foo")
#[test] fn ex_2_using_if_cfg_and_should_fail_with_foo() {
if cfg!(feature = "foo") {
assert_eq!(42, 4);
} else {
assert_eq!(42, 42);
}
}

// Will fail with
// cargo t cfg_all --features "foo aa"
#[test] fn ex_3_cfg_all() {
#[cfg(all(feature= "foo", feature= "aa"))]
assert_eq!(42, 43);
}

0 comments on commit c192b66

Please sign in to comment.