Create a bunch of test files

Hi, to create a test file I am doing,


#[cfg(test)]
pub mod test_kernel;
#[cfg(test)]
pub mod test_cubic_kernel;
#[cfg(test)]
pub mod test_lucy_kernel;
#[cfg(test)]
pub mod test_gaussian_kernel;

I have more 4 such files, Is there a way to reduce the syntax so that I don't have to repeat #[cfg(test)],
some thing like

#[cfg(test)]{
    pub mod test_kernel;
    pub mod test_cubic_kernel;
    pub mod test_lucy_kernel;
    pub mod test_gaussian_kernel;
}

Something like this should work:

#[cfg(test)]
mod tests {
  pub mod test_kernel;
  pub mod test_cubic_kernel;
  pub mod tests_lucy_kernel;
  pub mod test_gaussian_kernel;
}

#[cfg(test)]
pub use self::tests::*;

Also if this entire file is just a test wrapper, just add #![cfg(test)] - whole file would be compiled only when test is defined (which happens for test builds).

1 Like