| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Tiny; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Test::Tiny -- Write simple tests, simply. |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Test::Tiny tests => NUMBER; |
|
10
|
|
|
|
|
|
|
ok(TEST [, MESSAGE]); # pass if TEST is true, and print MESSAGE |
|
11
|
|
|
|
|
|
|
show(TEST); # pass if eval(TEST) is true, print TEST |
|
12
|
|
|
|
|
|
|
SKIP: { |
|
13
|
|
|
|
|
|
|
skip(MESSAGE, N); |
|
14
|
|
|
|
|
|
|
# skip this code, including N tests |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
BAIL_OUT([MESSAGE]); # give up, printing MESSAGE. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = '0.02'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub import |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
4
|
|
|
4
|
|
13
|
my $caller = caller; |
|
25
|
4
|
|
|
|
|
15
|
*{"$caller\::$_"} = \&$_ for qw(ok show skip BAIL_OUT done_testing); |
|
|
20
|
|
|
|
|
94
|
|
|
26
|
4
|
100
|
|
|
|
21
|
$PLAN = @_ == 3 ? 0+$_[2] : -1; |
|
27
|
4
|
100
|
|
|
|
7648
|
print "1..", $PLAN < 0 ? 0 : $PLAN, "\n"; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub ok |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
7
|
|
|
7
|
1
|
13
|
my $res = shift; |
|
33
|
7
|
100
|
|
|
|
18
|
if ($res) { |
|
34
|
6
|
|
|
|
|
8
|
++$SUCC; |
|
35
|
|
|
|
|
|
|
} else { |
|
36
|
1
|
|
|
|
|
4
|
print "not "; |
|
37
|
1
|
|
|
|
|
2
|
++$FAIL; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
7
|
|
50
|
|
|
31
|
(my $desc = shift || '') =~ s/\n/\n# /g; |
|
40
|
7
|
50
|
|
|
|
80
|
print "ok ", $SUCC + $FAIL, ($desc ? " - $desc" : ""), "\n"; |
|
41
|
7
|
100
|
|
|
|
26
|
if (!$res) { |
|
42
|
1
|
|
|
|
|
7
|
my ($pack, $file, $line, $i); |
|
43
|
1
|
|
|
|
|
7
|
($pack, $file, $line) = caller(++$i) while $pack eq 'Test::Tiny'; |
|
44
|
1
|
|
|
|
|
107
|
print "# Failed at $file line $line\n"; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub show |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
1
|
|
|
1
|
1
|
2
|
my $test = shift; |
|
51
|
1
|
|
|
|
|
81
|
ok(eval($test), $test); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub skip |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
1
|
|
|
1
|
1
|
3
|
my ($why, $n) = @_; |
|
57
|
1
|
|
|
|
|
8
|
ok(1, "skipped -- $why") while $n-- > 0; |
|
58
|
1
|
|
|
|
|
118
|
last SKIP; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub BAIL_OUT |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
0
|
|
|
0
|
1
|
0
|
print "Bail out!", @_, "\n"; |
|
64
|
0
|
|
|
|
|
0
|
exit 255; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub done_testing |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
1
|
|
|
1
|
1
|
7
|
undef $EXIT; |
|
70
|
1
|
|
|
|
|
86
|
exit $FAIL; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$EXIT = sub { |
|
74
|
|
|
|
|
|
|
exit($FAIL || abs($PLAN-$SUCC)); |
|
75
|
|
|
|
|
|
|
}; |
|
76
|
|
|
|
|
|
|
|
|
77
|
4
|
100
|
|
4
|
|
24
|
END { $EXIT->() if $EXIT; } |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
|
80
|
|
|
|
|
|
|
__END__ |