File: method-filter.t

package info (click to toggle)
libtest-routine-perl 0.031-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 705; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,144 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use Test::Routine;
use Test::Routine::Util;
use Test::More;
use Test::Fatal;

my %ran;
my %expected = ( map { $_ => 1 } just => 1..3 );

foreach my $num (1..3) {
  test "this must run $num" => sub { pass "must $num"; $ran{$num}++ };
}

test "just this" => sub { pass "just this"; $ran{just}++ };

subtest 'empty TEST_METHOD' => sub {
  local $ENV{TEST_METHOD} = '';
  run_me 'empty TEST_METHOD';
  is_deeply \%ran, \%expected, 'ran all tests';
};

subtest 'TEST_METHOD set' => sub {
  test "not to run" => sub { fail };

  %ran = ();
  {
    local $ENV{TEST_METHOD} = 'just this';
    run_me 'literal';
  }

  {
    local $ENV{TEST_METHOD} = '.*must.*';
    run_me 'regex';
  }

  is_deeply \%ran, \%expected, "ran each test once";
};

{
  # the whole subtest must be TODO, or it fails with "no tests run" for
  # the subtest created by run_me()
  local $TODO = "Exception gets swallowed somewhere";
  subtest 'invalid regex' => sub {
    local $ENV{TEST_METHOD} = 'invalid++';
    like exception { run_me 'invalid' },
      qr/\A\QTEST_METHOD (invalid++) is not a valid regular expression/,
      "invalid regex throws";
  };
}

done_testing;