@@ -4,33 +4,37 @@ use warnings;
4
4
use strict;
5
5
6
6
use Test::More;
7
- use File::Spec ();
8
- use LWP ();
7
+ use Test::Output qw( output_like ) ;
8
+ use File::Spec ();
9
+ use LWP ();
9
10
10
11
BEGIN {
11
- delete @ENV { qw( IFS CDPATH ENV BASH_ENV PATH ) };
12
+ delete @ENV {qw( IFS CDPATH ENV BASH_ENV PATH ) };
12
13
}
13
14
14
- plan skip_all => ' Not installing mech-dump' if -e File::Spec -> catfile( qw( t SKIP-MECH-DUMP ) );
15
- plan tests => 4 ;
15
+ plan skip_all => ' Not installing mech-dump'
16
+ if -e File::Spec -> catfile( qw( t SKIP-MECH-DUMP ) ) ;
16
17
17
- my $exe = File::Spec-> catfile( qw( script mech-dump ) );
18
+ my $exe = File::Spec-> catfile(qw( script mech-dump ) );
18
19
if ( $^O eq ' VMS' ) {
19
- $exe = qq[ mcr $^X -Ilib $exe ] ;
20
+ $exe = qq[ mcr $^X -Ilib $exe ] ;
20
21
}
21
22
23
+ my $perl ;
24
+ $perl = $1 if $^X =~ / ^(.+)$ / ;
25
+
26
+ subtest ' Success' => sub {
27
+
22
28
# Simply use a file: uri instead of the filename to make this test
23
29
# more independent of what URI::* thinks.
24
- my $source = ' file:t/google.html t/find_inputs.html t/html_file.txt' ;
30
+ my $source = ' file:t/google.html t/find_inputs.html t/html_file.txt' ;
25
31
26
- my $perl ;
27
- $perl = $1 if $^X =~ / ^(.+)$ / ;
28
- my $command = " $perl -Ilib $exe --forms --images --links $source " ;
32
+ my $command = " $perl -Ilib $exe --forms --images --links $source " ;
29
33
30
- my $actual = ` $command ` ;
34
+ my $actual = ` $command ` ;
31
35
32
- my $expected ;
33
- if ( $LWP::VERSION < 5.800 ) {
36
+ my $expected ;
37
+ if ( $LWP::VERSION < 5.800 ) {
34
38
$expected = <<'EOF' ;
35
39
GET file:/target-page [bob-the-form]
36
40
hl=en (hidden)
@@ -78,7 +82,8 @@ POST http://localhost/ [3rd_form]
78
82
GET http://localhost [text-form]
79
83
one= (text)
80
84
EOF
81
- } else {
85
+ }
86
+ else {
82
87
$expected = <<'EOF' ;
83
88
GET file:/target-page [bob-the-form]
84
89
hl=en (hidden readonly)
@@ -126,18 +131,43 @@ POST http://localhost/ [3rd_form]
126
131
GET http://localhost [text-form]
127
132
one= (text)
128
133
EOF
129
- }
130
-
131
- my @actual = split /\s *\n/, $actual ;
132
- my @expected = split /\s *\n/, $expected ;
133
-
134
- # First line is platform-dependent, so handle it accordingly.
135
- shift @expected ;
136
- my $first = shift @actual ;
137
- like( $first , qr / ^GET file:.*\/ target-page \[ bob-the-form\] / , ' First line matches' );
138
-
139
- cmp_ok( @expected , ' >' , 0, ' Still some expected' );
140
- cmp_ok( @actual , ' >' , 0, ' Still some actual' );
141
-
142
- is_deeply( \@actual , \@expected , ' Rest of the lines match' );
143
-
134
+ }
135
+
136
+ my @actual = split /\s *\n/, $actual ;
137
+ my @expected = split /\s *\n/, $expected ;
138
+
139
+ # First line is platform-dependent, so handle it accordingly.
140
+ shift @expected ;
141
+ my $first = shift @actual ;
142
+ like( $first ,
143
+ qr / ^GET file:.*\/ target-page \[ bob-the-form\] / ,
144
+ ' First line matches' );
145
+
146
+ cmp_ok( @expected , ' >' , 0, ' Still some expected' );
147
+ cmp_ok( @actual , ' >' , 0, ' Still some actual' );
148
+
149
+ is_deeply( \@actual , \@expected , ' Rest of the lines match' );
150
+ };
151
+
152
+ subtest ' Local file not found' => sub {
153
+ SKIP: {
154
+ # See https://stackoverflow.com/a/32054866/1331451
155
+ skip ' capturing output from system() is broken in 5.14 and 5.16 on Windows' , 1
156
+ if $^O eq ' MSWin32' && ( $] >= 5.014 && $] < 5.017 );
157
+
158
+ # The following file should not exist.
159
+ my $source = ' file:not_found.404' ;
160
+
161
+ my $command = " $perl -Ilib $exe $source " ;
162
+
163
+ output_like(
164
+ sub {
165
+ system $command ;
166
+ },
167
+ undef ,
168
+ qr / file:not_found.404 returns status 404/ ,
169
+ ' Errors when a local file is not found' );
170
+ };
171
+ };
172
+
173
+ done_testing;
0 commit comments