foresterre / parameterized

🐑 JUnit style parameterized testing for Rust
https://docs.rs/parameterized
Apache License 2.0
24 stars 1 forks source link

Create declarative macro which helps intellij recognize individual test cases #21

Open foresterre opened 4 years ago

foresterre commented 4 years ago
/// FIXME:
/// Create individual test cases which are recognized by intellij as tests, similar to the ide!()
/// macro, but for individual test cases.
///
/// ```rust
///
/// #[parameterized(
///     a = { 1, 2, 3 },
///     b = { 5, 6, 7},
/// )]
/// mktest! le_test(a: i32, b: i32) {
///     assert!(a < 4 && b > 4);
/// }
/// ```
/// 
/// generates:
/// 
/// ```rust
/// 
/// mod le_test {
///     use super::*;
///
///     ide!();
/// 
///     #[parameterized(
///         a = { 1, 2, 3 },
///         b = { 5, 6, 7},
///     )]
///     fn le_test(a: i32, b: i32) {
///         assert!(a < 4 && b > 4);
///     } 
/// }
/// ```
idubrov commented 4 years ago

Another way is to allow specifying #[test] after #[parameterized(..)] (by making parameterized macro to remove #[test]):

#[parameterized(
  a = { 1, 2, 3 },
  b = { 5, 6, 7},
)]
#[test]
fn le_test(a: i32, b: i32) {
  assert!(a < 4 && b > 4);
} 

Which is non-ideal (you can only put it after #[parameterized(..)), but works okay (this is how we do it in datatest).

foresterre commented 4 years ago

Another way is to allow specifying #[test] after #[parameterized(..)] (by making parameterized macro to remove #[test]):

#[parameterized(
  a = { 1, 2, 3 },
  b = { 5, 6, 7},
)]
#[test]
fn le_test(a: i32, b: i32) {
  assert!(a < 4 && b > 4);
} 

Which is non-ideal (you can only put it after #[parameterized(..)), but works okay (this is how we do it in datatest).

Oh wow :), that's a great idea. Thank you! I will look into this.

foresterre commented 4 years ago

declarative macro for which wraps ide! construct, test inputs and test cases