Skip to content

Commit 2c6057a

Browse files
authored
feat: regex pattern additional syntax support (#43)
1 parent db2b4f3 commit 2c6057a

File tree

8 files changed

+42
-21
lines changed

8 files changed

+42
-21
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ jobs:
5757
matrix:
5858
os:
5959
- ubuntu-latest
60-
# 1.65 is the MSRV
61-
rust-version: ["1.65", stable]
60+
rust-version: ["1.66", stable]
6261
fail-fast: false
6362
steps:
6463
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

Cargo.lock

Lines changed: 27 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ readme = "README.md"
99
edition = "2021"
1010
categories = ["development-tools::testing"]
1111
keywords = ["datatest", "data-driven-tests", "test-harness"]
12-
rust-version = "1.65"
12+
rust-version = "1.66"
1313

1414
[dependencies]
1515
camino = "1.1.6"
16+
fancy-regex = "0.13.0"
1617
libtest-mimic = "0.7.2"
17-
regex = "1.10.4"
1818
walkdir = "2.5.0"
1919

2020
[[test]]

src/runner.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@ impl Requirements {
5252
/// Scans all files in a given directory, finds matching ones and generates a test descriptor
5353
/// for each of them.
5454
fn expand(&self) -> Vec<Trial> {
55-
let re = regex::Regex::new(&self.pattern)
55+
let re = fancy_regex::Regex::new(&self.pattern)
5656
.unwrap_or_else(|_| panic!("invalid regular expression: '{}'", self.pattern));
5757

5858
let tests: Vec<_> = utils::iterate_directory(&self.root)
5959
.filter_map(|path_res| {
6060
let path = path_res.expect("error while iterating directory");
61-
if re.is_match(path.as_str()) {
61+
if re.is_match(path.as_str()).unwrap_or_else(|error| {
62+
panic!(
63+
"error matching pattern '{}' against path '{}' : {}",
64+
self.pattern,
65+
path.as_str(),
66+
error
67+
)
68+
}) {
6269
let testfn = self.test;
6370
let name = utils::derive_test_name(&self.root, &path, &self.test_name);
6471
Some(Trial::test(name, move || {

tests/example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn test_artifact_utf8(path: &Utf8Path) -> Result<()> {
2020
datatest_stable::harness!(
2121
test_artifact,
2222
"tests/files",
23-
r"^.*/*",
23+
r"^.*(?<!\.skip)\.txt$", // this regex pattern skips .skip.txt files
2424
test_artifact_utf8,
2525
"tests/files",
26-
r"^.*/*",
26+
r"^.*\.txt$", // this regexpattern matches all files
2727
);
File renamed without changes.
File renamed without changes.

tests/files/c.skip.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
baz foo

0 commit comments

Comments
 (0)