Skip to content

Commit 409b86f

Browse files
convert uses of Test.pm to Test::More
1 parent 669b5c2 commit 409b86f

16 files changed

Lines changed: 534 additions & 525 deletions

Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Revision history for HTTP-Message
22

3+
4+
- converted all uses of Test.pm to Test::More
5+
6+
37
6.08 2015-07-10
48
- Resolve new uninitialized warning from
59
HTTP::Request::Common::request_type_with_data (RT#105787)

Makefile.PL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ my %WriteMakefileArgs = (
3131
'Exporter' => '5.57',
3232
},
3333
TEST_REQUIRES => {
34-
'Test' => '0',
34+
'Test::More' => '0',
3535
},
3636

3737
META_MERGE => {

t/common-req.t

Lines changed: 71 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
use strict;
22
use warnings;
33

4-
use Test;
5-
plan tests => 58;
4+
use Test::More;
5+
plan tests => 59;
66

77
use HTTP::Request::Common;
88

99
my $r = GET 'http://www.sn.no/';
10-
print $r->as_string;
10+
note $r->as_string;
1111

12-
ok($r->method, "GET");
13-
ok($r->uri, "http://www.sn.no/");
12+
is($r->method, "GET");
13+
is($r->uri, "http://www.sn.no/");
1414

1515
$r = HEAD "http://www.sn.no/",
1616
If_Match => 'abc',
1717
From => 'aas@sn.no';
18-
print $r->as_string;
18+
note $r->as_string;
1919

20-
ok($r->method, "HEAD");
20+
is($r->method, "HEAD");
2121
ok($r->uri->eq("http://www.sn.no"));
2222

23-
ok($r->header('If-Match'), "abc");
24-
ok($r->header("from"), "aas\@sn.no");
23+
is($r->header('If-Match'), "abc");
24+
is($r->header("from"), "aas\@sn.no");
2525

2626
$r = PUT "http://www.sn.no",
2727
Content => 'foo';
28-
print $r->as_string, "\n";
28+
note $r->as_string, "\n";
2929

30-
ok($r->method, "PUT");
31-
ok($r->uri->host, "www.sn.no");
30+
is($r->method, "PUT");
31+
is($r->uri->host, "www.sn.no");
3232

3333
ok(!defined($r->header("Content")));
3434

35-
ok(${$r->content_ref}, "foo");
36-
ok($r->content, "foo");
37-
ok($r->content_length, 3);
35+
is(${$r->content_ref}, "foo");
36+
is($r->content, "foo");
37+
is($r->content_length, 3);
3838

3939
$r = PUT "http://www.sn.no",
4040
{ foo => "bar" };
41-
ok($r->content, "foo=bar");
41+
is($r->content, "foo=bar");
4242

4343
#--- Test POST requests ---
4444

@@ -49,38 +49,38 @@ $r = POST "http://www.sn.no", [foo => 'bar;baz',
4949
"nl" => "a\nb\r\nc\n",
5050
],
5151
bar => 'foo';
52-
print $r->as_string, "\n";
52+
note $r->as_string, "\n";
5353

54-
ok($r->method, "POST");
55-
ok($r->content_type, "application/x-www-form-urlencoded");
56-
ok($r->content_length, 83);
57-
ok($r->header("bar"), "foo");
58-
ok($r->content, "foo=bar%3Bbaz&baz=a&baz=b&baz=c&foo=zoo%3D%26&space+=+%2B+&nl=a%0D%0Ab%0D%0Ac%0D%0A");
54+
is($r->method, "POST");
55+
is($r->content_type, "application/x-www-form-urlencoded");
56+
is($r->content_length, 83);
57+
is($r->header("bar"), "foo");
58+
is($r->content, "foo=bar%3Bbaz&baz=a&baz=b&baz=c&foo=zoo%3D%26&space+=+%2B+&nl=a%0D%0Ab%0D%0Ac%0D%0A");
5959

6060
$r = POST "http://example.com";
61-
ok($r->content_length, 0);
62-
ok($r->content, "");
61+
is($r->content_length, 0);
62+
is($r->content, "");
6363

6464
$r = POST "http://example.com", [];
65-
ok($r->content_length, 0);
66-
ok($r->content, "");
65+
is($r->content_length, 0);
66+
is($r->content, "");
6767

6868
$r = POST "mailto:gisle\@aas.no",
6969
Subject => "Heisan",
7070
Content_Type => "text/plain",
7171
Content => "Howdy\n";
72-
#print $r->as_string;
72+
#note $r->as_string;
7373

74-
ok($r->method, "POST");
75-
ok($r->header("Subject"), "Heisan");
76-
ok($r->content, "Howdy\n");
77-
ok($r->content_type, "text/plain");
74+
is($r->method, "POST");
75+
is($r->header("Subject"), "Heisan");
76+
is($r->content, "Howdy\n");
77+
is($r->content_type, "text/plain");
7878

7979
{
8080
my @warnings;
8181
local $SIG{__WARN__} = sub { push @warnings, @_ };
8282
$r = POST 'http://unf.ug/', [];
83-
ok( "@warnings", '', 'empty POST' );
83+
is( "@warnings", '', 'empty POST' );
8484
}
8585

8686
#
@@ -99,55 +99,56 @@ $r = POST 'http://www.perl.org/survey.cgi',
9999
born => '1964',
100100
file => [$file],
101101
];
102-
#print $r->as_string;
102+
#note $r->as_string;
103103

104104
unlink($file) or warn "Can't unlink $file: $!";
105105

106-
ok($r->method, "POST");
107-
ok($r->uri->path, "/survey.cgi");
108-
ok($r->content_type, "multipart/form-data");
106+
is($r->method, "POST");
107+
is($r->uri->path, "/survey.cgi");
108+
is($r->content_type, "multipart/form-data");
109109
ok($r->header('Content_type') =~ /boundary="?([^"]+)"?/);
110110
my $boundary = $1;
111111

112112
my $c = $r->content;
113113
$c =~ s/\r//g;
114114
my @c = split(/--\Q$boundary/, $c);
115-
print "$c[5]\n";
115+
note "$c[5]\n";
116116

117-
ok(@c == 7 and $c[6] =~ /^--\n/); # 5 parts + header & trailer
117+
is(@c, 7);
118+
like($c[6], qr/^--\n/); # 5 parts + header & trailer
118119

119-
ok($c[2] =~ /^Content-Disposition:\s*form-data;\s*name="email"/m);
120-
ok($c[2] =~ /^gisle\@aas.no$/m);
120+
like($c[2], qr/^Content-Disposition:\s*form-data;\s*name="email"/m);
121+
like($c[2], qr/^gisle\@aas.no$/m);
121122

122-
ok($c[5] =~ /^Content-Disposition:\s*form-data;\s*name="file";\s*filename="$file"/m);
123-
ok($c[5] =~ /^Content-Type:\s*text\/plain$/m);
124-
ok($c[5] =~ /^foo\nbar\nbaz/m);
123+
like($c[5], qr/^Content-Disposition:\s*form-data;\s*name="file";\s*filename="$file"/m);
124+
like($c[5], qr/^Content-Type:\s*text\/plain$/m);
125+
like($c[5], qr/^foo\nbar\nbaz/m);
125126

126127
$r = POST 'http://www.perl.org/survey.cgi',
127128
[ file => [ undef, "xxy\"", Content_type => "text/html", Content => "<h1>Hello, world!</h1>" ]],
128129
Content_type => 'multipart/form-data';
129-
print $r->as_string;
130+
#note $r->as_string;
130131

131-
ok($r->content =~ /^--\S+\015\012Content-Disposition:\s*form-data;\s*name="file";\s*filename="xxy\\"/m);
132-
ok($r->content =~ /^Content-Type: text\/html/m);
133-
ok($r->content =~ /^<h1>Hello, world/m);
132+
like($r->content, qr/^--\S+\015\012Content-Disposition:\s*form-data;\s*name="file";\s*filename="xxy\\"/m);
133+
like($r->content, qr/^Content-Type: text\/html/m);
134+
like($r->content, qr/^<h1>Hello, world/m);
134135

135136
$r = POST 'http://www.perl.org/survey.cgi',
136137
Content_type => 'multipart/form-data',
137138
Content => [ file => [ undef, undef, Content => "foo"]];
138-
#print $r->as_string;
139+
#note $r->as_string;
139140

140-
ok($r->content !~ /filename=/);
141+
unlike($r->content, qr/filename=/);
141142

142143

143144
# The POST routine can now also take a hash reference.
144145
my %hash = (foo => 42, bar => 24);
145146
$r = POST 'http://www.perl.org/survey.cgi', \%hash;
146-
#print $r->as_string, "\n";
147-
ok($r->content =~ /foo=42/);
148-
ok($r->content =~ /bar=24/);
149-
ok($r->content_type, "application/x-www-form-urlencoded");
150-
ok($r->content_length, 13);
147+
#note $r->as_string, "\n";
148+
like($r->content, qr/foo=42/);
149+
like($r->content, qr/bar=24/);
150+
is($r->content_type, "application/x-www-form-urlencoded");
151+
is($r->content_length, 13);
151152

152153

153154
#
@@ -171,16 +172,16 @@ $r = POST 'http://www.perl.org/survey.cgi',
171172
born => '1964',
172173
file => [$file],
173174
];
174-
print $r->as_string, "\n";
175+
#note $r->as_string, "\n";
175176

176-
ok($r->method, "POST");
177-
ok($r->uri->path, "/survey.cgi");
178-
ok($r->content_type, "multipart/form-data");
179-
ok($r->header('Content_type') =~ /boundary="?([^"]+)"?/);
177+
is($r->method, "POST");
178+
is($r->uri->path, "/survey.cgi");
179+
is($r->content_type, "multipart/form-data");
180+
ok($r->header('Content_type') =~ qr/boundary="?([^"]+)"?/);
180181
$boundary = $1;
181-
ok(ref($r->content), "CODE");
182+
is(ref($r->content), "CODE");
182183

183-
ok(length($boundary) > 10);
184+
cmp_ok(length($boundary), '>', 10);
184185

185186
my $code = $r->content;
186187
my $chunk;
@@ -193,42 +194,42 @@ unlink($file) or warn "Can't unlink $file: $!";
193194

194195
$_ = join("", @chunks);
195196

196-
print int(@chunks), " chunks, total size is ", length($_), " bytes\n";
197+
#note int(@chunks), " chunks, total size is ", length($_), " bytes\n";
197198

198199
# should be close to expected size and number of chunks
199-
ok(abs(@chunks - 15 < 3));
200-
ok(abs(length($_) - 26589) < 20);
200+
cmp_ok(abs(@chunks - 15), '<', 3);
201+
cmp_ok(abs(length($_) - 26589), '<', 20);
201202

202203
$r = POST 'http://www.example.com';
203-
ok($r->as_string, <<EOT);
204+
is($r->as_string, <<EOT);
204205
POST http://www.example.com
205206
Content-Length: 0
206207
Content-Type: application/x-www-form-urlencoded
207208
208209
EOT
209210

210211
$r = POST 'http://www.example.com', Content_Type => 'form-data', Content => [];
211-
ok($r->as_string, <<EOT);
212+
is($r->as_string, <<EOT);
212213
POST http://www.example.com
213214
Content-Length: 0
214215
Content-Type: multipart/form-data; boundary=none
215216
216217
EOT
217218

218219
$r = POST 'http://www.example.com', Content_Type => 'form-data';
219-
#print $r->as_string;
220-
ok($r->as_string, <<EOT);
220+
#note $r->as_string;
221+
is($r->as_string, <<EOT);
221222
POST http://www.example.com
222223
Content-Length: 0
223224
Content-Type: multipart/form-data
224225
225226
EOT
226227

227228
$r = HTTP::Request::Common::DELETE 'http://www.example.com';
228-
ok($r->method, "DELETE");
229+
is($r->method, "DELETE");
229230

230231
$r = HTTP::Request::Common::PUT 'http://www.example.com',
231232
'Content-Type' => 'application/octet-steam',
232233
'Content' => 'foobarbaz',
233234
'Content-Length' => 12; # a slight lie
234-
ok($r->header('Content-Length'), 9);
235+
is($r->header('Content-Length'), 9);

t/headers-auth.t

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33

4-
use Test;
4+
use Test::More;
55

66
plan tests => 6;
77

@@ -12,31 +12,30 @@ my $res = HTTP::Response->new(401);
1212
$res->push_header(WWW_Authenticate => qq(Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2"));
1313
$res->push_header(WWW_Authenticate => qq(Basic Realm="WallyWorld", foo=bar, bar=baz));
1414

15-
print $res->as_string;
15+
note $res->as_string;
1616

1717
my %auth = $res->www_authenticate;
1818

19-
ok(keys(%auth), 3);
19+
is(keys(%auth), 3);
2020

21-
ok($auth{basic}{realm}, "WallyWorld");
22-
ok($auth{bar}{realm}, "WallyWorld2");
21+
is($auth{basic}{realm}, "WallyWorld");
22+
is($auth{bar}{realm}, "WallyWorld2");
2323

2424
$a = $res->www_authenticate;
25-
ok($a, 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz');
25+
is($a, 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz');
2626

2727
$res->www_authenticate("Basic realm=foo1");
28-
print $res->as_string;
28+
note $res->as_string;
2929

3030
$res->www_authenticate(Basic => {realm => "foo2"});
3131
print $res->as_string;
3232

3333
$res->www_authenticate(Basic => [realm => "foo3", foo=>33],
3434
Digest => {nonce=>"bar", foo=>'foo'});
35-
print $res->as_string;
35+
note $res->as_string;
3636

37-
$_ = $res->as_string;
37+
my $string = $res->as_string;
3838

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/);
39+
like($string, qr/WWW-Authenticate: Basic realm="foo3", foo=33/);
40+
like($string, qr/WWW-Authenticate: Digest (nonce=bar, foo=foo|foo=foo, nonce=bar)/);
4241

t/headers-etag.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
33

4-
use Test;
4+
use Test::More;
55

66
plan tests => 4;
77

@@ -10,20 +10,20 @@ require HTTP::Headers::ETag;
1010
my $h = HTTP::Headers->new;
1111

1212
$h->etag("tag1");
13-
ok($h->etag, qq("tag1"));
13+
is($h->etag, qq("tag1"));
1414

1515
$h->etag("w/tag2");
16-
ok($h->etag, qq(W/"tag2"));
16+
is($h->etag, qq(W/"tag2"));
1717

1818
$h->if_match(qq(W/"foo", bar, baz), "bar");
1919
$h->if_none_match(333);
2020

2121
$h->if_range("tag3");
22-
ok($h->if_range, qq("tag3"));
22+
is($h->if_range, qq("tag3"));
2323

2424
my $t = time;
2525
$h->if_range($t);
26-
ok($h->if_range, $t);
26+
is($h->if_range, $t);
2727

28-
print $h->as_string;
28+
note $h->as_string;
2929

0 commit comments

Comments
 (0)