When using the test-case crate, is it possible to put the test cases in a different file and then include it? This would be to have a cleaner file.
I am currently implementing some statistical models and it is important that for a dataset it replicates the same results for each data element and so many test cases (100+) are needed and putting them all in the file would effectively clutter it.
For a simple example, is there a way to go from:
fn add_two(x: i32, y: i32) -> i32 {
x + y
}
mod test {
use super::*;
use test_case::test_case;
#[test_case(2, 2 => 4)]
#[test_case(2, 3 => 5)]
#[test_case(2, 1 => 3)]
#[test_case(-2, 2 => 0)]
fn test_add_two(x: i32, y: i32) -> i32 {
add_two(x, y)
}
}
To something like:
mod test {
use super::*;
use test_case::test_case;
include!("test_cases/my_test_cases.in");
fn test_add_two(x: i32, y: i32) -> i32 {
add_two(x, y)
}
}
I get the following error when attempting that:
error: expected item after attributes
--> src/test_cases/my_test_cases.in:4:1
|
1 | / #[test_case(2, 2 => 4)]
2 | | #[test_case(2, 3 => 5)]
3 | | #[test_case(2, 1 => 3)]
| |_______________________- other attributes here
4 | #[test_case(-2, 2 => 0)]
Thanks!
EDIT: fixed formatting.