Created
December 1, 2014 09:48
-
-
Save pshc/f76489952566506eddd8 to your computer and use it in GitHub Desktop.
#[cfg(test)] internal export hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HACK | |
#[cfg(test)] | |
pub use self::secret::internal; | |
mod secret { | |
pub fn internal() -> bool { | |
println!("you've broken my secret elbow!"); | |
true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod dep; | |
#[cfg(not(test))] | |
fn main() { | |
assert_eq!(dep::internal(), true); | |
} | |
#[cfg(test)] | |
#[test] | |
fn white_box() { | |
assert_eq!(dep::internal(), true); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rustc main.rs | |
main.rs:5:16: 5:29 error: unresolved name `dep::internal`. | |
main.rs:5 assert_eq!(dep::internal(), true); | |
^~~~~~~~~~~~~ | |
<std macros>:1:1: 14:2 note: in expansion of assert_eq! | |
main.rs:5:5: 5:39 note: expansion site | |
error: aborting due to previous error | |
$ rustc --test main.rs && ./main | |
running 1 test | |
test white_box ... ok | |
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment