| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Test::More tests => 3; |
| 4 |
|
| 5 |
# Disable all ReadLine functionality |
| 6 |
$ENV{PERL_RL} = 0; |
| 7 |
delete $ENV{PAGER} |
| 8 |
if $ENV{PAGER}; |
| 9 |
$ENV{PERL_HTML_DISPLAY_CLASS}="HTML::Display::Dump"; |
| 10 |
|
| 11 |
use_ok('WWW::Mechanize::Shell'); |
| 12 |
my $s = WWW::Mechanize::Shell->new( 'test', rcfile => undef, warnings => undef ); |
| 13 |
isa_ok $s, 'WWW::Mechanize::Shell'; |
| 14 |
|
| 15 |
my $have_tableextract = eval { |
| 16 |
require HTML::TableExtract; |
| 17 |
die "Need at least HTML::TableExtract v2, found '$HTML::TableExtract::VERSION'" |
| 18 |
unless $HTML::TableExtract::VERSION > 2; |
| 19 |
1 |
| 20 |
}; |
| 21 |
|
| 22 |
SKIP: { |
| 23 |
if ($@) { |
| 24 |
skip "Error loading HTML::TableExtract: '$@'", 1; |
| 25 |
} elsif (! $have_tableextract) { |
| 26 |
skip "Unknown error loading HTML::TableExtract, skipping tests", 1; |
| 27 |
} else { |
| 28 |
no warnings qw'redefine once'; |
| 29 |
local *WWW::Mechanize::Shell::status = sub {}; |
| 30 |
my @output; |
| 31 |
local *WWW::Mechanize::Shell::print_paged = sub { |
| 32 |
shift @_; |
| 33 |
push @output, grep { /\S/ } @_; |
| 34 |
}; |
| 35 |
$s->agent->{base} = 'http://example.com'; |
| 36 |
$s->agent->update_html(<<HTML); |
| 37 |
<html> |
| 38 |
<head><base href="http://example.com" /></head> |
| 39 |
<body> |
| 40 |
<table> |
| 41 |
<thead><tr><th>ID</th><th>age</th><th>name</th></tr></thead> |
| 42 |
<tbody> |
| 43 |
<tr><td>1</td><td>John</td><td>41</td></tr> |
| 44 |
<tr><td>2</td><td>Paul</td><td>47</td></tr> |
| 45 |
<tr><td>3</td><td>George</td><td>45</td></tr> |
| 46 |
<tr><td>4</td><td>Ringo</td><td>47</td></tr> |
| 47 |
</tbody> |
| 48 |
</table> |
| 49 |
</body> |
| 50 |
</html> |
| 51 |
HTML |
| 52 |
$s->cmd('table name age'); |
| 53 |
# TableExtract seems to be confused about the column order |
| 54 |
# hence we just check the number of rows: |
| 55 |
is(scalar @output, 5, "Five lines captured") |
| 56 |
or diag "@output"; |
| 57 |
} |
| 58 |
}; |