/
More.tra
122 lines (114 loc) · 2.67 KB
/
More.tra
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class Test::Builder {
sub new() {
self.bless({
counter => 0,
failed => 0,
});
}
sub counter() { ${self}[counter] }
sub incr_counter() {
${self}[counter] = ${self}[counter] + 1;
}
sub incr_failed() {
${self}[failed] = ${self}[failed] + 1;
}
sub failed() {
return ${self}[failed];
}
sub ok($b, $msg=undef) {
if ($b) {
self.pass($msg);
return true;
} else {
self.fail($msg);
return false;
}
}
sub pass($msg=undef) {
self.incr_counter();
print("ok " + self.counter);
if ($msg!=undef) {
print(" - " + $msg);
}
print("\n");
return true;
}
sub fail($msg=undef) {
self.incr_counter();
print("not ok " + self.counter);
if ($msg!=undef) {
print(" - " + $msg);
}
print("\n");
self.incr_failed;
return false;
}
sub is($a, $b, $msg=undef) {
if ($a==$b) {
self.pass($msg);
return true;
} else {
self.incr_counter;
print("not ok " + self.counter);
if $msg != undef {
print(" - " + $msg);
}
print("\n");
say(" # got: " + $a);
say(" # expected: " + $b);
self.incr_failed;
return false;
}
}
sub like($a, $b, $msg=undef) {
self.incr_counter;
if ($a.match($b)) {
print("ok " + self.counter);
if $msg!=undef {
print(" - " + $msg);
}
print("\n");
return true;
} else {
print("not ok " + self.counter);
if $msg!=undef {
print(" - " + $msg);
}
say(" # got: " + $a);
say(" # expected: " + $b);
self.incr_failed;
return false;
}
}
sub note($msg) {
say("# " + $msg);
}
sub done_testing() {
say("1.." + self.counter);
if (self.counter == 0) {
say('# No tests run!');
}
if (self.failed > 0) {
# printf("# Looks like you failed %d test of %d.", self.failed, $counter);
}
}
}
my $BUILDER = Test::Builder.new();
sub ok($b, $msg=undef) {
$BUILDER.ok($b, $msg);
}
sub fail($msg=undef) {
$BUILDER.fail($msg);
}
sub is($a, $b, $msg=undef) {
$BUILDER.is($a, $b, $msg);
}
sub like($a, $b, $msg=undef) {
$BUILDER.like($a, $b, $msg);
}
sub note($msg) {
$BUILDER.note($msg);
}
sub done_testing() {
$BUILDER.done_testing();
}