Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tags: foresterre/sif

Tags

v0.1.1

Toggle v0.1.1's commit message
Re-implement the parameterized macro with separate cases

The other variant (in the parameterized/parameterized_macro crate) uses the following syntax (example):

#[parameterized(
  arg = { "value", "more values", ...},
  more_arg = { 0, 1, ...}
)]
fn my_test(arg: &str, more_arg: u8) { ... }

 With many inputs this becomes quite verbose. In addition, it has the property that parameters for a single test case are separated from each other syntactically (e.g. the first value from 'arg' and the first value from 'more_arg' are the inputs for the first test case and are provided in separate input 'lists'). This can be seen as both an advantage and a disadvantage (but I perceived it as a disadvantage as my test cases grew, or if you wanted to add a case later on, as the inputs then are "far" apart). In addition, especially Intellij-Rust didn't like the custom syntax within the attribute, and with auto-formatting it flattened the whole input to the left. Lastly, the syntax made it difficult to add additional features like renaming test cases.

This new attribute macro so-far re-implemented everything which is available from the parameterized crate and currently doesn't add more, but at least test case renaming is planned.
The 'sif' crate uses separate attributes for each case. If we translate the example above, we'll be left with the following:

#[parameterized]
#[case("value", 0)]
#[case("more values", 1)]
// .. more cases
fn my_test(arg: &str, more_arg: u8) { ... }

You can see that now each "case" attribute contains the input arguments for one test case, which improves the locality of related arguments. For IDE's like intellij-Rust, this syntax is easier to grok since it currently uses a simple meta-list like syntax, where arguments usually span a single line. Lastly, we can provide renaming by refining the syntax to accept something like #[case(x, y, z) as IDENT] or perhaps #[case(x, y,z) with_name: IDENT] in the near future.

v0.1.0

Toggle v0.1.0's commit message
Re-implement the parameterized macro with separate cases

The other variant (in the parameterized/parameterized_macro crate) uses the following syntax (example):

#[parameterized(
  arg = { "value", "more values", ...},
  more_arg = { 0, 1, ...}
)]
fn my_test(arg: &str, more_arg: u8) { ... }

 With many inputs this becomes quite verbose. In addition, it has the property that parameters for a single test case are separated from each other syntactically (e.g. the first value from 'arg' and the first value from 'more_arg' are the inputs for the first test case and are provided in separate input 'lists'). This can be seen as both an advantage and a disadvantage (but I perceived it as a disadvantage as my test cases grew, or if you wanted to add a case later on, as the inputs then are "far" apart). In addition, especially Intellij-Rust didn't like the custom syntax within the attribute, and with auto-formatting it flattened the whole input to the left. Lastly, the syntax made it difficult to add additional features like renaming test cases.

This new attribute macro so-far re-implemented everything which is available from the parameterized crate and currently doesn't add more, but at least test case renaming is planned.
The 'sif' crate uses separate attributes for each case. If we translate the example above, we'll be left with the following:

#[parameterized]
#[case("value", 0)]
#[case("more values", 1)]
// .. more cases
fn my_test(arg: &str, more_arg: u8) { ... }

You can see that now each "case" attribute contains the input arguments for one test case, which improves the locality of related arguments. For IDE's like intellij-Rust, this syntax is easier to grok since it currently uses a simple meta-list like syntax, where arguments usually span a single line. Lastly, we can provide renaming by refining the syntax to accept something like #[case(x, y, z) as IDENT] or perhaps #[case(x, y,z) with_name: IDENT] in the near future.