-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pl
52 lines (42 loc) · 1.39 KB
/
test.pl
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
51
52
use strict;
use warnings;
use Test::More;
require './main.pl';
our ($expanded, $collapsed);
my $tests_planned = 0;
# tests organized into groups of positive and negative matches
my %cases = (
'positives' => [],
'negatives' => [],
);
# loads all test cases from their respective files
foreach my $group ( keys %cases ) {
open my $fh, "tests/$group.txt" or die "Couldn't open $group: $!";
while ( my $line = <$fh> ) {
chomp($line);
(my $test, my $name) = split /\t/, $line;
push @{ $cases{$group} }, { test => $test, name => $name };
# counting planned tests as we go
$tests_planned += 2;
}
close $fh;
}
# set up how many we expect to run
plan tests => $tests_planned;
# iterate each group...
foreach my $group ( keys %cases ) {
# determine what sort of case group this is
my $state = $group eq 'positives' ? 'match' : 'mismatch';
my $action = $group eq 'positives' ? 'like' : 'unlike';
# and then each test case...
foreach my $test ( @{ $cases{$group} } ) {
# tolerate any missing test names
my $test_name = defined $test->{'name'} ? $test->{'name'} : '';
note("Expecting $state for $test_name -- $test->{'test'}");
{
no strict 'refs';
&{$action}($test->{'test'}, $expanded, $test_name);
&{$action}($test->{'test'}, $collapsed, $test_name);
}
}
}