Attribute Macro test_vec_case

Source
#[test_vec_case]
Expand description

An attribute macro for simplifying the creation of test functions that utilize test vectors.

This macro allows you to write data-driven tests using external test vectors stored in YAML or JSON files. It provides flexibility by supporting different modes of operation: initializing, checking, and recording test cases.

§Usage

The test_vec_case macro is applied as an attribute to test functions. Here’s a basic example:

use assert_tv_macros::test_vec_case;
#[test_vec_case]
fn my_test() {
    // Test code here
}

§Arguments

The test_vec macro accepts the following arguments:

  1. file: Specifies the path to the test vector file.

    • Format: "path/to/file.{yaml|json}"
    • Example: #[test_vec(file = "tests/vecs/my_test.yaml")]
    • Default: None (uses a default based on function name and format)
  2. format: Determines the format of the test vector file.

    • Possible values:
      • "yaml" or "yml"
      • "json"
      • "toml"
    • Default: "yaml"
    • Example: #[test_vec(format = "json")]
  3. mode: Specifies the test mode.

    • Possible values:
      • "init"
      • "check"
    • Default: If no value is specified, the TEST_MODE env-variable is queried for a fall-back. Else "check" is used as the default.
    • Example: #[test_vec(mode = "init")]

§Notes

  • The generated default file path for test vectors is .test_vectors/<function_name>.<format>.
  • Test functions wrapped with this macro are marked as #[ignore] by default. To include them in test runs, use the --ignored flag.
  • The macro automatically initializes and cleans up test vector resources, ensuring proper setup and teardown.