Skip to content

Commit

Permalink
feat: regex pattern additional syntax support (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
webbdays authored Apr 21, 2024
1 parent db2b4f3 commit 2c6057a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ jobs:
matrix:
os:
- ubuntu-latest
# 1.65 is the MSRV
rust-version: ["1.65", stable]
rust-version: ["1.66", stable]
fail-fast: false
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
Expand Down
40 changes: 27 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ readme = "README.md"
edition = "2021"
categories = ["development-tools::testing"]
keywords = ["datatest", "data-driven-tests", "test-harness"]
rust-version = "1.65"
rust-version = "1.66"

[dependencies]
camino = "1.1.6"
fancy-regex = "0.13.0"
libtest-mimic = "0.7.2"
regex = "1.10.4"
walkdir = "2.5.0"

[[test]]
Expand Down
11 changes: 9 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ impl Requirements {
/// Scans all files in a given directory, finds matching ones and generates a test descriptor
/// for each of them.
fn expand(&self) -> Vec<Trial> {
let re = regex::Regex::new(&self.pattern)
let re = fancy_regex::Regex::new(&self.pattern)
.unwrap_or_else(|_| panic!("invalid regular expression: '{}'", self.pattern));

let tests: Vec<_> = utils::iterate_directory(&self.root)
.filter_map(|path_res| {
let path = path_res.expect("error while iterating directory");
if re.is_match(path.as_str()) {
if re.is_match(path.as_str()).unwrap_or_else(|error| {
panic!(
"error matching pattern '{}' against path '{}' : {}",
self.pattern,
path.as_str(),
error
)
}) {
let testfn = self.test;
let name = utils::derive_test_name(&self.root, &path, &self.test_name);
Some(Trial::test(name, move || {
Expand Down
4 changes: 2 additions & 2 deletions tests/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fn test_artifact_utf8(path: &Utf8Path) -> Result<()> {
datatest_stable::harness!(
test_artifact,
"tests/files",
r"^.*/*",
r"^.*(?<!\.skip)\.txt$", // this regex pattern skips .skip.txt files
test_artifact_utf8,
"tests/files",
r"^.*/*",
r"^.*\.txt$", // this regexpattern matches all files
);
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/files/c.skip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baz foo

0 comments on commit 2c6057a

Please sign in to comment.