Skip to content

Commit eee9abb

Browse files
Copilotoalders
andcommitted
Fix form.t to work with HTTP::Message 7.01+
Co-authored-by: oalders <96205+oalders@users.noreply.github.com>
1 parent 9589a01 commit eee9abb

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

t/form.t

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ use warnings;
66
use Test::More;
77
use HTML::Form;
88

9+
# this handles all versions of HTTP::Message, both before and after
10+
# 7.01, when the stringification of requests changed
11+
sub is_maybe_nl {
12+
my ($got, $expected, $message) = @_;
13+
14+
local $Test::Builder::Level = $Test::Builder::Level + 1;
15+
16+
if ($got !~ m{\n$} && $expected =~ m{\n$}) {
17+
chomp($expected);
18+
}
19+
20+
is($got, $expected, $message);
21+
}
22+
923
my @warn;
1024
$SIG{__WARN__} = sub { push( @warn, $_[0] ) };
1125

@@ -83,7 +97,7 @@ EOT
8397
#print $f->dump;
8498
#print $f->click->as_string;
8599

86-
is( $f->click->as_string, <<'EOT');
100+
is_maybe_nl( $f->click->as_string, <<'EOT');
87101
POST http://localhost/
88102
Content-Length: 86
89103
Content-Type: application/x-www-form-urlencoded
@@ -463,7 +477,7 @@ EOT
463477
ok( $f->find_input("randomkey") );
464478
is( $f->find_input("randomkey")->challenge, "1234567890" );
465479
is( $f->find_input("randomkey")->keytype, "rsa" );
466-
is( $f->click->as_string, <<EOT);
480+
is_maybe_nl( $f->click->as_string, <<EOT);
467481
POST http://example.com/secure/keygen/test.cgi
468482
Content-Length: 19
469483
Content-Type: application/x-www-form-urlencoded
@@ -472,7 +486,7 @@ Field1=Default+Text
472486
EOT
473487

474488
$f->value( randomkey => "foo" );
475-
is( $f->click->as_string, <<EOT);
489+
is_maybe_nl( $f->click->as_string, <<EOT);
476490
POST http://example.com/secure/keygen/test.cgi
477491
Content-Length: 33
478492
Content-Type: application/x-www-form-urlencoded
@@ -602,7 +616,7 @@ $f = HTML::Form->parse( <<EOT, base => "http://localhost/" );
602616
</form>
603617
EOT
604618

605-
is( $f->click->as_string, <<EOT);
619+
is_maybe_nl( $f->click->as_string, <<EOT);
606620
POST http://localhost/
607621
Content-Length: 9
608622
Content-Type: application/x-www-form-urlencoded
@@ -617,7 +631,7 @@ $f = HTML::Form->parse( <<EOT, base => "http://localhost/" );
617631
</form>
618632
EOT
619633

620-
is( $f->click->as_string, <<EOT);
634+
is_maybe_nl( $f->click->as_string, <<EOT);
621635
POST http://localhost/
622636
Content-Length: 7
623637
Content-Type: application/x-www-form-urlencoded
@@ -674,4 +688,4 @@ GET http://localhost/target.html?foo=option+in+named
674688
EOT
675689
}
676690

677-
done_testing;
691+
done_testing;

0 commit comments

Comments
 (0)