Skip to content

Instantly share code, notes, and snippets.

@pshc
Created December 1, 2014 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pshc/f76489952566506eddd8 to your computer and use it in GitHub Desktop.
Save pshc/f76489952566506eddd8 to your computer and use it in GitHub Desktop.
#[cfg(test)] internal export hack
// HACK
#[cfg(test)]
pub use self::secret::internal;
mod secret {
pub fn internal() -> bool {
println!("you've broken my secret elbow!");
true
}
}
mod dep;
#[cfg(not(test))]
fn main() {
assert_eq!(dep::internal(), true);
}
#[cfg(test)]
#[test]
fn white_box() {
assert_eq!(dep::internal(), true);
}
$ 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