Skip to content

Commit 9a23ea2

Browse files
committed
Make tests use Test.pm
1 parent 1ec5048 commit 9a23ea2

19 files changed

+340
-531
lines changed

t/base/cookies.t

Lines changed: 67 additions & 110 deletions
Large diffs are not rendered by default.

t/base/date.t

Lines changed: 46 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1+
#!perl -w
2+
3+
use strict;
4+
use Test;
5+
6+
plan tests => 133;
7+
18
use HTTP::Date;
29

310
require Time::Local if $^O eq "MacOS";
411
my $offset = ($^O eq "MacOS") ? Time::Local::timegm(0,0,0,1,0,70) : 0;
512

6-
print "1..59\n";
7-
8-
$no = 1;
9-
$| = 1;
10-
sub ok {
11-
print "not " if $_[0];
12-
print "ok $no\n";
13-
$no++;
14-
}
15-
1613
# test str2time for supported dates. Test cases with 2 digit year
1714
# will probably break in year 2044.
1815
my(@tests) =
@@ -72,30 +69,24 @@ for (@tests) {
7269
my $t2 = str2time(lc($_), "GMT");
7370
my $t3 = str2time(uc($_), "GMT");
7471

75-
$t = "UNDEF" unless defined $t;
76-
print "'$_' => $t\n";
77-
print $@ if $@;
78-
print "not " if $t eq 'UNDEF' || $t != $time
79-
|| $t2 != $time
80-
|| $t3 != $time;
81-
ok;
72+
print "\n# '$_'\n";
73+
74+
ok($t, $time);
75+
ok($t2, $time);
76+
ok($t3, $time);
8277
}
8378

8479
# test time2str
85-
die "time2str failed"
86-
unless time2str($time) eq 'Thu, 03 Feb 1994 00:00:00 GMT';
80+
ok(time2str($time), 'Thu, 03 Feb 1994 00:00:00 GMT');
8781

8882
# test the 'ls -l' format with missing year$
8983
# round to nearest minute 3 days ago.
9084
$time = int((time - 3 * 24*60*60) /60)*60;
91-
($min, $hr, $mday, $mon) = (localtime $time)[1,2,3,4];
85+
my ($min, $hr, $mday, $mon) = (localtime $time)[1,2,3,4];
9286
$mon = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
93-
$str = sprintf("$mon %02d %02d:%02d", $mday, $hr, $min);
94-
$t = str2time($str);
95-
$t = "UNDEF" unless defined $t;
96-
print "'$str' => $t ($time)\n";
97-
print "not " if $t != $time;
98-
ok;
87+
my $str = sprintf("$mon %02d %02d:%02d", $mday, $hr, $min);
88+
my $t = str2time($str);
89+
ok($t, $time);
9990

10091
# try some garbage.
10192
for (undef, '', 'Garbage',
@@ -121,10 +112,9 @@ for (undef, '', 'Garbage',
121112
$bad++;
122113
}
123114
};
124-
print defined($_) ? "'$_'\n" : "undef\n";
125-
print $@ if $@;
126-
print "not " if $bad;
127-
ok;
115+
print defined($_) ? "\n# '$_'\n" : "\n# undef\n";
116+
ok(!$@);
117+
ok(!$bad);
128118
}
129119

130120
print "Testing AM/PM gruff...\n";
@@ -134,60 +124,57 @@ use HTTP::Date qw(time2iso time2isoz);
134124

135125
print "Testing time2iso functions\n";
136126

137-
$t = time2iso(str2time("11-12-96 0:00AM"));print "$t\n";
138-
ok($t ne "1996-11-12 00:00:00");
127+
$t = time2iso(str2time("11-12-96 0:00AM"));
128+
ok($t, "1996-11-12 00:00:00");
139129

140-
$t = time2iso(str2time("11-12-96 12:00AM"));print "$t\n";
141-
ok($t ne "1996-11-12 00:00:00");
130+
$t = time2iso(str2time("11-12-96 12:00AM"));
131+
ok($t, "1996-11-12 00:00:00");
142132

143-
$t = time2iso(str2time("11-12-96 0:00PM"));print "$t\n";
144-
ok($t ne "1996-11-12 12:00:00");
133+
$t = time2iso(str2time("11-12-96 0:00PM"));
134+
ok($t, "1996-11-12 12:00:00");
145135

146-
$t = time2iso(str2time("11-12-96 12:00PM"));print "$t\n";
147-
ok($t ne "1996-11-12 12:00:00");
136+
$t = time2iso(str2time("11-12-96 12:00PM"));
137+
ok($t, "1996-11-12 12:00:00");
148138

149139

150-
$t = time2iso(str2time("11-12-96 1:05AM"));print "$t\n";
151-
ok($t ne "1996-11-12 01:05:00");
140+
$t = time2iso(str2time("11-12-96 1:05AM"));
141+
ok($t, "1996-11-12 01:05:00");
152142

153-
$t = time2iso(str2time("11-12-96 12:05AM"));print "$t\n";
154-
ok($t ne "1996-11-12 00:05:00");
143+
$t = time2iso(str2time("11-12-96 12:05AM"));
144+
ok($t, "1996-11-12 00:05:00");
155145

156-
$t = time2iso(str2time("11-12-96 1:05PM"));print "$t\n";
157-
ok($t ne "1996-11-12 13:05:00");
146+
$t = time2iso(str2time("11-12-96 1:05PM"));
147+
ok($t, "1996-11-12 13:05:00");
158148

159-
$t = time2iso(str2time("11-12-96 12:05PM"));print "$t\n";
160-
ok($t ne "1996-11-12 12:05:00");
149+
$t = time2iso(str2time("11-12-96 12:05PM"));
150+
ok($t, "1996-11-12 12:05:00");
161151

162152
$t = str2time("2000-01-01 00:00:01.234");
163153
print "FRAC $t = ", time2iso($t), "\n";
164-
ok(abs(($t - int($t)) - 0.234) > 0.000001);
154+
ok(abs(($t - int($t)) - 0.234) < 0.000001);
165155

166156
$a = time2iso;
167157
$b = time2iso(500000);
168158
print "LOCAL $a $b\n";
169-
$az = time2isoz;
170-
$bz = time2isoz(500000);
159+
my $az = time2isoz;
160+
my $bz = time2isoz(500000);
171161
print "GMT $az $bz\n";
172162

173-
for ($a, $b) { ok if /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/; }
174-
for ($az, $bz) { ok if /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$/; }
163+
for ($a, $b) { ok(/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/); }
164+
for ($az, $bz) { ok(/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$/); }
175165

176166
# Test the parse_date interface
177167
use HTTP::Date qw(parse_date);
178168

179-
@d = parse_date("Jan 1 2001");
169+
my @d = parse_date("Jan 1 2001");
180170

181-
print "not " if defined(pop(@d)) ||
182-
"@d" ne "2001 1 1 0 0 0";
183-
ok;
171+
ok(!defined(pop(@d)));
172+
ok("@d", "2001 1 1 0 0 0");
184173

185174
# This test will break around year 2070
186-
print "not " unless parse_date("03-Feb-20") eq "2020-02-03 00:00:00";
187-
ok;
175+
ok(parse_date("03-Feb-20"), "2020-02-03 00:00:00");
188176

189177
# This test will break around year 2048
190-
print "not " unless parse_date("03-Feb-98") eq "1998-02-03 00:00:00";
191-
ok;
178+
ok(parse_date("03-Feb-98"), "1998-02-03 00:00:00");
192179

193180
print "HTTP::Date $HTTP::Date::VERSION\n";

t/base/headers-auth.t

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
print "1..4\n";
1+
#!perl -w
2+
3+
use strict;
4+
use Test;
5+
6+
plan tests => 6;
27

38
use HTTP::Response;
49
use HTTP::Headers::Auth;
510

6-
$res = HTTP::Response->new(401);
11+
my $res = HTTP::Response->new(401);
712
$res->push_header(WWW_Authenticate => qq(Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2"));
813
$res->push_header(WWW_Authenticate => qq(Basic Realm="WallyWorld", foo=bar, bar=baz));
914

1015
print $res->as_string;
1116

12-
%auth = $res->www_authenticate;
17+
my %auth = $res->www_authenticate;
1318

14-
print "not " unless keys(%auth) == 3;
15-
print "ok 1\n";
19+
ok(keys(%auth), 3);
1620

17-
print "not " unless $auth{basic}{realm} eq "WallyWorld" &&
18-
$auth{bar}{realm} eq "WallyWorld2";
19-
print "ok 2\n";
21+
ok($auth{basic}{realm}, "WallyWorld");
22+
ok($auth{bar}{realm}, "WallyWorld2");
2023

2124
$a = $res->www_authenticate;
22-
print "not " unless $a eq 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz';
23-
print "ok 3\n";
25+
ok($a, 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz');
2426

2527
$res->www_authenticate("Basic realm=foo1");
2628
print $res->as_string;
2729

28-
$res->www_authenticate(Basic => {realm => foo2});
30+
$res->www_authenticate(Basic => {realm => "foo2"});
2931
print $res->as_string;
3032

31-
$res->www_authenticate(Basic => [realm => foo3, foo=>33],
33+
$res->www_authenticate(Basic => [realm => "foo3", foo=>33],
3234
Digest => {nonce=>"bar", foo=>'foo'});
3335
print $res->as_string;
3436

3537
$_ = $res->as_string;
3638

37-
print "not " unless /WWW-Authenticate: Basic realm="foo3", foo=33/ &&
38-
(/WWW-Authenticate: Digest nonce=bar, foo=foo/ ||
39-
/WWW-Authenticate: Digest foo=foo, nonce=bar/);
40-
print "ok 4\n";
39+
ok(/WWW-Authenticate: Basic realm="foo3", foo=33/);
40+
ok(/WWW-Authenticate: Digest nonce=bar, foo=foo/ ||
41+
/WWW-Authenticate: Digest foo=foo, nonce=bar/);
4142

t/base/headers-etag.t

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
print "1..4\n";
1+
#!perl -w
2+
3+
use strict;
4+
use Test;
5+
6+
plan tests => 4;
27

38
require HTTP::Headers::ETag;
49

5-
$h = HTTP::Headers->new;
10+
my $h = HTTP::Headers->new;
11+
612
$h->etag("tag1");
7-
print "not " unless $h->etag eq qq("tag1");
8-
print "ok 1\n";
13+
ok($h->etag, qq("tag1"));
914

1015
$h->etag("w/tag2");
11-
print "not " unless $h->etag eq qq(W/"tag2");
12-
print "ok 2\n";
16+
ok($h->etag, qq(W/"tag2"));
1317

1418
$h->if_match(qq(W/"foo", bar, baz), "bar");
1519
$h->if_none_match(333);
1620

1721
$h->if_range("tag3");
18-
print "not " unless $h->if_range eq qq("tag3");
19-
print "ok 3\n";
22+
ok($h->if_range, qq("tag3"));
2023

21-
$t = time;
24+
my $t = time;
2225
$h->if_range($t);
23-
print "not " unless $h->if_range == $t;
24-
print "ok 4\n";
25-
26+
ok($h->if_range, $t);
2627

2728
print $h->as_string;
2829

t/base/headers-util.t

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#!perl -w
2+
13
use strict;
2-
use HTTP::Headers::Util qw(split_header_words join_header_words);
4+
use Test;
35

4-
my $extra_tests = 2;
6+
use HTTP::Headers::Util qw(split_header_words join_header_words);
57

68
my @s_tests = (
79

@@ -26,36 +28,18 @@ my @s_tests = (
2628
'Basic; realm="\"foo\\\\bar\""'],
2729
);
2830

29-
print "1..", @s_tests + $extra_tests, "\n";
31+
plan tests => @s_tests + 2;
3032

31-
my $testno = 1;
32-
33-
print "split_header_words() tests\n";
3433
for (@s_tests) {
3534
my($arg, $expect) = @$_;
3635
my @arg = ref($arg) ? @$arg : $arg;
3736

3837
my $res = join_header_words(split_header_words(@arg));
39-
if ($res ne $expect) {
40-
print "\nUnexpected result: '$res'\n";
41-
print " Expected: '$expect'\n";
42-
print " when parsing '", join(", ", @arg), "'\n";
43-
eval {
44-
require Data::Dumper;
45-
my @p = split_header_words(@arg);
46-
print Data::Dumper::Dumper(\@p);
47-
};
48-
print "not ";
49-
}
50-
print "ok ", $testno++, "\n";
38+
ok($res, $expect);
5139
}
5240

5341

54-
print "Extra tests\n";
42+
print "# Extra tests\n";
5543
# some extra tests
56-
print "not " unless join_header_words("foo" => undef, "bar" => "baz")
57-
eq "foo; bar=baz";
58-
print "ok ", $testno++, "\n";
59-
60-
print "not " unless join_header_words() eq "";
61-
print "ok ", $testno++, "\n";
44+
ok(join_header_words("foo" => undef, "bar" => "baz"), "foo; bar=baz");
45+
ok(join_header_words(), "");

0 commit comments

Comments
 (0)