I have released Test2::Plugin::SubtestFilter for Perl tests, which allows filtering test targets by subtest name, similar to --testNamePattern
in jest and vitest. I think it is useful when you want to run only specific tests.
# t/test.t
use Test2::V0;
use Test2::Plugin::SubtestFilter;
subtest 'foo' => sub {
subtest 'nested foo1' => sub { ok 1 };
subtest 'nested foo2' => sub { ok 1 };
};
subtest 'baz' => sub {
ok 1;
};
done_testing;
# Run tests matching `foo1`
❯ SUBTEST_FILTER=foo1 prove -lvr t/test.t
t/test.t ..
# Seeded srand with seed '20251020' from local date.
ok 1 - foo {
ok 1 - nested foo1 {
ok 1
1..1
}
ok 2 - nested foo2 # skip
1..2
}
ok 2 - baz # skip
1..2
ok
All tests successful.
Files=1, Tests=2, 0 wallclock secs ( 0.00 usr 0.00 sys + 0.04 cusr 0.00 csys = 0.04 CPU)
Result: PASS
Top comments (1)
I was wishing for something like this a couple of years ago for a systems check script.