glob_test

Attribute Macro glob_test 

Source
#[glob_test]
Expand description

A macro that expands a single test case parameterized by a single &str parameter into a family of tests with the same name used as prefix for each file found in a glob pattern at compile time.

ยงExample

Assume that your cargo project has a testdata folder with the following structure:

  • foo
    • bar.md
    • baz.md

Then the expansion

use spectest_macros::glob_test;

#[glob_test("testdata/foo/**/*.md")]
fn test_foo(path: &str) {
    println!("Running test at path = {path}");
}

will be

fn test_foo(path: &str) {
    println!("Running test at path = {path}");
}

#[test]
fn test_foo_bar() {
    test_foo("/path/to/crate/testdata/foo/bar.md")
}

#[test]
fn test_foo_baz() {
    test_foo("/path/to/crate/testdata/foo/baz.md")
}