Debian Codegraph @

t/24-source-file.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use lib './inc';
4 use IO::Catch;
5 use Test::HTTP::LocalServer;
6
7 our ( $_STDOUT_, $_STDERR_);
8 tie *STDOUT, 'IO::Catch', '_STDOUT_' or die $!;
9 tie *STDERR, 'IO::Catch', '_STDERR_' or die $!;
10
11 use Test::More tests => 5;
12
13 # Disable all ReadLine functionality
14 $ENV{PERL_RL} = 0;
15 delete $ENV{PAGER}
16 if $ENV{PAGER};
17 $ENV{PERL_HTML_DISPLAY_CLASS}="HTML::Display::Dump";
18
19 delete @ENV{qw(HTTP_PROXY http_proxy CGI_HTTP_PROXY)};
20
21 require WWW::Mechanize::Shell;
22 my $s = WWW::Mechanize::Shell->new( 'test', rcfile => undef, warnings => undef );
23
24 # Now test
25 my $server = Test::HTTP::LocalServer->spawn();
26
27 { no warnings 'redefine','once';
28 local *WWW::Mechanize::Shell::status = sub {};
29
30 $s->cmd( sprintf 'get "%s"', $server->url);
31 isnt($s->agent->content,"","Retrieved content");
32 $s->cmd("source t/source.mech");
33 isnt($_STDOUT_,"","Sourcing a file works");
34 is($_STDERR_,undef,"No warnings");
35 };
36
37 { no warnings 'redefine','once';
38 my $warned;
39 local *WWW::Mechanize::Shell::display_user_warning = sub { $warned++ };
40
41 $s->cmd("source t/does-not-exist.mech");
42 is($warned,1,"Warning for nonexistent files works");
43 is($_STDERR_,undef,"No warnings");
44 };
45