Skip to content

Commit

Permalink
Also match against the test name for exact matches
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshowers committed Dec 11, 2023
1 parent 93a6271 commit a4cbf4e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

#![forbid(unsafe_code)]

use std::{process, sync::mpsc, fmt, time::Instant};
use std::{process, sync::mpsc, fmt, time::Instant, borrow::Cow};

mod args;
mod printer;
Expand Down Expand Up @@ -374,6 +374,7 @@ impl Arguments {
}

fn is_filtered_out(&self, test: &Trial) -> bool {
let test_name = test.name();
// Match against the full test name, including the kind. This upholds the invariant that if
// --list prints out:
//
Expand All @@ -385,16 +386,22 @@ impl Arguments {
// If a filter was specified, apply this
if let Some(filter) = &self.filter {
match self.exact {
true if test_name != filter => return true,
false if !test_name.contains(filter) => return true,
// For exact matches, we want to match against either the test name (to maintain
// backwards compatibility with older versions of libtest-mimic), or the test kind
// (technically more correct with respect to matching against the output of --list.)
true if test_name != filter && &test_name_with_kind != filter => return true,
false if !test_name_with_kind.contains(filter) => return true,
_ => {}
};
}

// If any skip pattern were specified, test for all patterns.
for skip_filter in &self.skip {
match self.exact {
true if &test_name_with_kind == skip_filter => return true,
// For exact matches, we want to match against either the test name (to maintain
// backwards compatibility with older versions of libtest-mimic), or the test kind
// (technically more correct with respect to matching against the output of --list.)
true if test_name == skip_filter || &test_name_with_kind == skip_filter => return true,

Check failure on line 404 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Check basic style

Line too long

Line exceeds maximum length of 100 (it's 103 Unicode codepoints long)
false if test_name_with_kind.contains(skip_filter) => return true,
_ => {}
}
Expand Down
43 changes: 41 additions & 2 deletions tests/mixed_bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ fn list_with_filter() {

#[test]
fn list_with_filter_exact() {
// --exact matches the test name either with or without the kind.
let (c, out) = common::do_run(args(["--list", "--exact", "[apple] fox"]), tests());
// Matches all tests that contain "a" in either the name or the kind.
assert_log!(out, "
[apple] fox: test
");
Expand All @@ -260,7 +260,46 @@ fn list_with_filter_exact() {
num_failed: 0,
num_ignored: 0,
num_measured: 0,
});
});
let (c, out) = common::do_run(args(["--list", "--exact", "fly"]), tests());
assert_log!(out, "
[banana] fly: test
");
assert_eq!(c, Conclusion {
num_filtered_out: 0,
num_passed: 0,
num_failed: 0,
num_ignored: 0,
num_measured: 0,
});

// --skip --exact can be used to exclude tests.
let (c, out) = common::do_run(args(["--list", "--exact", "--skip", "[apple] fox", "--skip", "fly"]), tests());

Check failure on line 277 in tests/mixed_bag.rs

View workflow job for this annotation

GitHub Actions / Check basic style

Line too long

Line exceeds maximum length of 100 (it's 114 Unicode codepoints long)
assert_log!(out, "
cat: test
dog: test
[apple] bunny: test
frog: test
owl: test
[banana] bear: test
red: bench
blue: bench
[kiwi] yellow: bench
[kiwi] green: bench
purple: bench
cyan: bench
[banana] orange: bench
[banana] pink: bench
");
assert_eq!(c, Conclusion {
num_filtered_out: 0,
num_passed: 0,
num_failed: 0,
num_ignored: 0,
num_measured: 0,
});

// --skip --exact matches test names without the kind as well.
}

#[test]
Expand Down

0 comments on commit a4cbf4e

Please sign in to comment.