File: mech-dump.t

package info (click to toggle)
libwww-mechanize-perl 1.18-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 488 kB
  • ctags: 109
  • sloc: perl: 2,315; makefile: 39
file content (63 lines) | stat: -rw-r--r-- 1,667 bytes parent folder | download | duplicates (2)
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
#!perl -Tw

BEGIN {
    delete @ENV{ qw( IFS CDPATH ENV BASH_ENV PATH ) };
}

use warnings;
use strict;
use Test::More;
use File::Spec;
use LWP;

plan skip_all => "Not installing mech-dump" if -e File::Spec->catfile( qw( t SKIP-MECH-DUMP ) );
plan tests => 4;

my $exe = File::Spec->catfile( qw( blib script mech-dump ) );
if ( $^O eq "VMS" ) {
    $exe = qq[mcr $^X "-mblib" $exe];
}

# Simply use a file: uri instead of the filename to make this test
# more independent of what URI::* thinks.
my $data = 'file:t/google.html';

my $perl = $1 if $^X =~ /^(.+)$/;
my $command = "$perl -Mblib $exe --forms $data";

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)
  q=
  btnG=Google Search              (submit)
  btnI=I'm Feeling Lucky          (submit)
EOF
} else {
    $expected = <<'EOF';
GET file:/target-page [bob-the-form]
  hl=en                          (hidden readonly)
  ie=ISO-8859-1                  (hidden readonly)
  q=                             (text)
  btnG=Google Search             (submit)
  btnI=I'm Feeling Lucky         (submit)
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" );