Skip to content

Commit 52bd6ad

Browse files
committed
Add test that overrides cfg_if with the one from crates.io
1 parent 3e9d356 commit 52bd6ad

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/libcore/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ path = "../libcore/benches/lib.rs"
2121

2222
[dev-dependencies]
2323
rand = "0.6"
24+
cfg_if = "1.0"
2425

2526
[features]
2627
# Make panics and failed asserts immediately abort without formatting any message

src/libcore/tests/cfg_if_override.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Test that overriding cfg_if with our own cfg_if macro does not break
2+
//! anything.
13
#![feature(cfg_if)]
24

35
macro_rules! cfg_if {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! Test that using cfg_if from the cfg_if crate does not break anything.
2+
3+
#[macro_use(cfg_if)]
4+
extern crate cfg_if;
5+
6+
cfg_if! {
7+
if #[cfg(test)] {
8+
use core::option::Option as Option2;
9+
fn works1() -> Option2<u32> { Some(1) }
10+
} else {
11+
fn works1() -> Option<u32> { None }
12+
}
13+
}
14+
15+
cfg_if! {
16+
if #[cfg(foo)] {
17+
fn works2() -> bool { false }
18+
} else if #[cfg(test)] {
19+
fn works2() -> bool { true }
20+
} else {
21+
fn works2() -> bool { false }
22+
}
23+
}
24+
25+
cfg_if! {
26+
if #[cfg(foo)] {
27+
fn works3() -> bool { false }
28+
} else {
29+
fn works3() -> bool { true }
30+
}
31+
}
32+
33+
cfg_if! {
34+
if #[cfg(test)] {
35+
use core::option::Option as Option3;
36+
fn works4() -> Option3<u32> { Some(1) }
37+
}
38+
}
39+
40+
cfg_if! {
41+
if #[cfg(foo)] {
42+
fn works5() -> bool { false }
43+
} else if #[cfg(test)] {
44+
fn works5() -> bool { true }
45+
}
46+
}
47+
48+
#[test]
49+
fn it_works() {
50+
assert!(works1().is_some());
51+
assert!(works2());
52+
assert!(works3());
53+
assert!(works4().is_some());
54+
assert!(works5());
55+
}

0 commit comments

Comments
 (0)