commure / datatest

Datatest -- data-driven test framework for Rust
Apache License 2.0
53 stars 15 forks source link

Directory included in pattern matching is confusing #29

Open djmarcin opened 4 years ago

djmarcin commented 4 years ago

The documentation states that "These tests define a directory to scan for test data, a pattern (a regular expression) to match". However it doesn't make clear that the directory string must match the pattern and also is not automatically prepended to template filenames. This seems like an unexpected choice since the directory appears to be a prefix to the pattern / template definitions.

For example, given a configuration like this, nothing will ever match because the input pattern does not match "src/foo/tests".

#[datatest::files("src/foo/tests", {
    input in r"^(test_.*).in.yml",
    output = r"${1}.out.yml",
})]

Intuitively, the input pattern seems like it should be relative to the directory that is being searched. I was left scratching my head as to why this pattern wasn't matching anything, so at the very least this behavior should be documented. Although it would potentially be a disruptive change, I think it would greatly improve usability if the regex & file templates were applied rooted at the given directory.

idubrov commented 4 years ago

I feel you. I myself spent like 30 minutes today figuring out why my pattern didn't work 😀

P.S. Thanks for the bug report! I'll take a look. I think, some extra error reporting on top would help as well.

mverleg commented 3 years ago

I was also confused by this, until I found this issue. Once known I just used '/filename$' instead of '^filename$' and it worked.

I'm still a bit confused, because the example in the readme starts with ^ and doesn't include the path in the pattern either. Seems like it wouldn't work, or am I missing something?