1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
#!perl
use warnings;
use strict;
use Test::More;
use File::Spec ();
use LWP ();
BEGIN {
delete @ENV{qw( IFS CDPATH ENV BASH_ENV PATH )};
}
plan skip_all => 'Not installing mech-dump'
if -e File::Spec->catfile(qw( t SKIP-MECH-DUMP ));
my $exe = File::Spec->catfile(qw( script mech-dump ));
if ( $^O eq 'VMS' ) {
$exe = qq[mcr $^X -Ilib $exe];
}
$exe = '/usr/bin/mech-dump' if $ENV{AUTOPKGTEST_TMP};
my $perl;
$perl = $1 if $^X =~ /^(.+)$/;
subtest 'Success' => sub {
# Simply use a file: uri instead of the filename to make this test
# more independent of what URI::* thinks.
my $source = 'file:t/google.html t/find_inputs.html t/html_file.txt';
my $command = "$perl -Ilib $exe --forms --images --links $source";
my $actual = `$command`;
my $expected;
if ( $LWP::VERSION < 5.800 ) {
$expected = <<'EOF';
GET file:/target-page [bob-the-form]
hl=en (hidden)
ie=ISO-8859-1 (hidden)
notgoogle= (hidden readonly)
q=
btnG=Google Search (submit)
btnI=I'm Feeling Lucky (submit)
/images/logo.gif
/imghp?hl=en&tab=wi&ie=UTF-8
/grphp?hl=en&tab=wg&ie=UTF-8
/dirhp?hl=en&tab=wd&ie=UTF-8
/nwshp?hl=en&tab=wn&ie=UTF-8
/advanced_search?hl=en
/preferences?hl=en
/language_tools?hl=en
/tour/services/query.html
/ads/
/services/
/options/
/about.html
POST http://localhost/ (multipart/form-data) [1st_form]
1a= (text)
submit1=Submit (image)
submit2=Submit (submit)
POST http://localhost/ [2nd_form]
YourMom= (text)
opt[2]= (text)
1b= (text)
submit=Submit (submit)
POST http://localhost/ [3rd_form]
YourMom= (text)
YourDad= (text)
YourSister= (text)
YourSister= (text)
submit=Submit (submit)
GET http://localhost [text-form]
one= (text)
EOF
}
else {
$expected = <<'EOF';
GET file:/target-page [bob-the-form]
hl=en (hidden readonly)
ie=ISO-8859-1 (hidden readonly)
notgoogle= (hidden readonly)
q= (text)
btnG=Google Search (submit)
btnI=I'm Feeling Lucky (submit)
/images/logo.gif
/imghp?hl=en&tab=wi&ie=UTF-8
/grphp?hl=en&tab=wg&ie=UTF-8
/dirhp?hl=en&tab=wd&ie=UTF-8
/nwshp?hl=en&tab=wn&ie=UTF-8
/advanced_search?hl=en
/preferences?hl=en
/language_tools?hl=en
/tour/services/query.html
/ads/
/services/
/options/
/about.html
POST http://localhost/ (multipart/form-data) [1st_form]
1a= (text)
submit1=Submit (image)
submit2=Submit (submit)
POST http://localhost/ [2nd_form]
YourMom= (text)
opt[2]= (text)
1b= (text)
submit=Submit (submit)
POST http://localhost/ [3rd_form]
YourMom= (text)
YourDad= (text)
YourSister= (text)
YourSister= (text)
submit=Submit (submit)
GET http://localhost [text-form]
one= (text)
EOF
}
my @actual = split /\s*\n/, $actual;
my @expected = split /\s*\n/, $expected;
# First line is platform-dependent, so handle it accordingly.
shift @expected;
my $first = shift @actual;
like(
$first,
qr/^GET file:.*\/target-page \[bob-the-form\]/,
'First line matches'
);
cmp_ok( @expected, '>', 0, 'Still some expected' );
cmp_ok( @actual, '>', 0, 'Still some actual' );
is_deeply( \@actual, \@expected, 'Rest of the lines match' );
};
done_testing;
|