You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr would be great if some primitive test_case generators were possible, e.g. #[test_case(1; 3; "test cases 1 2 and 3")] (made-up syntax).
Problem
For my project, I have a large static vector DATA with complex entries. DATA length corresponds to a global constant DATA_LEN. Each DATA entry carries it's own built-in test case (only in test builds). Previously, I had created one test case and looped on all entries.
However, I have to manually update the listing of #[test_case] when DATA changes.
Solution
It would be great if I could have test_case help me generate the test cases, 0 up to DATA_LEN.
constDATA_LEN:usize = 70;#[test_case(0; DATA_LEN; "a test case for each entry in DATA")]fntest_DATA_entry(index:usize){let entry = &DATA[&index];assert(...)}
the code snippet would run 70 unique test cases.
Suggestions
I'm imagining some new formatting like
#[test_case(1; 3; "test cases 1 2 and 3")]
Or perhaps a new test_case library export like
#[test_case_generator(1; 3; "test cases 1 2 and 3")]
Or perhaps it has a start, stop, step that takes closures. The stop closure returns Option<T>. When None the test cases stop else pass T to the test case
#[test_case_generator(1, |x| if x > 3{None} else {Some(x)}, |x| x + 1; "test cases 1 2 and 3")]
The text was updated successfully, but these errors were encountered:
tl;dr would be great if some primitive test_case generators were possible, e.g.
#[test_case(1; 3; "test cases 1 2 and 3")]
(made-up syntax).Problem
For my project, I have a large static vector
DATA
with complex entries.DATA
length corresponds to a global constantDATA_LEN
. EachDATA
entry carries it's own built-in test case (only in test builds). Previously, I had created one test case and looped on all entries.But I wanted more granular test cases, one test case for each entry in the
DATA
. So I added#[test_case]
declaration for eachHowever, I have to manually update the listing of
#[test_case]
whenDATA
changes.Solution
It would be great if I could have
test_case
help me generate the test cases,0
up toDATA_LEN
.the code snippet would run 70 unique test cases.
Suggestions
I'm imagining some new formatting like
#[test_case(1; 3; "test cases 1 2 and 3")]
Or perhaps a new
test_case
library export like#[test_case_generator(1; 3; "test cases 1 2 and 3")]
Or perhaps it has a start, stop, step that takes closures. The stop closure returns
Option<T>
. WhenNone
the test cases stop else passT
to the test case#[test_case_generator(1, |x| if x > 3 { None } else { Some(x) }, |x| x + 1; "test cases 1 2 and 3")]
The text was updated successfully, but these errors were encountered: