As suggested by The Book, I have moved the integration tests in my crate to a tests
directory. Some of those tests use functions that I don't want to export outside of the crate, though, and I am no longer able to use them in the integration test folder. I use them for non-test purposes too, so they need to compile outside of tests too. I tried using variants of pub(restricted)
, but I wasn't able to make it work. Ideally I'd like to have something like pub(tests)
.
directory tree (the relevant bits):
my_crate
|- src
|- parser.rs
|- tests
|- parsing.rs
|- benches
|- parsing.rs
tests/parsing.rs:
extern crate my_crate;
use my_crate::parser::foo;
#[test]
fn temp() {
foo();
}
benches/parsing.rs:
#![feature(test)]
extern crate test;
extern crate my_crate;
use test::Bencher;
use my_crate::parser::foo;
#[bench]
fn temp(b: &mut Bencher) {
b.iter(|| { foo(); });
}
My current workaround is to make the relevant objects pub
lic and invisible in the docs (#[doc(hidden)]
), but it doesn't convey the proper intention. Can I make an object public only for integration test / benchmarking purposes?