11use strict;
22use warnings;
33
4- use Test;
5- plan tests => 58 ;
4+ use Test::More ;
5+ plan tests => 59 ;
66
77use HTTP::Request::Common;
88
99my $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" );
2121ok($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
3333ok(!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\n b\r\n c\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
104104unlink ($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" );
109109ok($r -> header(' Content_type' ) =~ / boundary="?([^"]+)"?/ );
110110my $boundary = $1 ;
111111
112112my $c = $r -> content;
113113$c =~ s /\r // g ;
114114my @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\n bar\n baz/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\n bar\n baz/ 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\012 Content-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\012 Content-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.
144145my %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
185186my $code = $r -> content;
186187my $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 );
204205POST http://www.example.com
205206Content-Length: 0
206207Content-Type: application/x-www-form-urlencoded
207208
208209EOT
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 );
212213POST http://www.example.com
213214Content-Length: 0
214215Content-Type: multipart/form-data; boundary=none
215216
216217EOT
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 );
221222POST http://www.example.com
222223Content-Length: 0
223224Content-Type: multipart/form-data
224225
225226EOT
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);
0 commit comments