Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: regex pattern additional syntax support #43

Merged
merged 9 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
/// 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
)

Check warning on line 67 in src/runner.rs

View check run for this annotation

Codecov / codecov/patch

src/runner.rs#L62-L67

Added lines #L62 - L67 were not covered by tests
}) {
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