Debian Codegraph @

t/04-history-invariant.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3
4 use lib './inc';
5 use IO::Catch;
6
7 # pre-5.8.0's warns aren't caught by a tied STDERR.
8 tie *STDOUT, 'IO::Catch', '_STDOUT_' or die $!;
9
10 our( @history_invariant, @history_add );
11
12 BEGIN {
13 # Disable all ReadLine functionality
14 $ENV{PERL_RL} = 0;
15
16 # Also disable the paged output of Term::Shell
17
18 @history_invariant = qw(
19 browse
20 cookies
21 dump
22 eval
23 exit
24 forms
25 history
26 links
27 parse
28 quit
29 restart
30 script
31 set
32 source
33 tables
34 versions
35 ct
36 response
37 title
38 headers
39 );
40 push @history_invariant, "headers 1","headers 12","headers 2","headers 12345";
41 push @history_invariant, "#"," #", "# a comment", " # another comment";
42
43 @history_add = qw(
44 autofill
45 back
46 click
47 content
48 fillout
49 get
50 open
51 reload
52 save
53 submit
54 table
55 ua
56 value
57 tick
58 untick
59 referer
60 referrer
61 timeout
62 );
63 };
64
65 # For testing the "versions" command
66 sub WWW::Mechanize::Shell::print_pairs {};
67
68 use Test::More tests => scalar @history_invariant +1;
69 SKIP: {
70
71 use_ok('WWW::Mechanize::Shell');
72
73 # Silence all warnings
74 #$SIG{__WARN__} = sub {};
75
76 my $s = WWW::Mechanize::Shell->new( 'test', rcfile => undef, warnings => undef );
77 $s->agent->{content} = '';
78
79 my @history;
80
81 sub disable {
82 my ($namespace,$subname) = @_;
83 no strict 'refs';
84 no warnings 'redefine';
85 *{"$namespace\::$subname"} = sub { return };
86 };
87
88 { no warnings 'redefine','once';
89 *WWW::Mechanize::Shell::add_history = sub {
90 shift;
91 push @history, join "", @_;
92 };
93
94 *WWW::Mechanize::links = sub {()};
95 };
96
97 disable( "WWW::Mechanize::Shell", $_ )
98 for (qw( restart_shell browser ));
99
100 disable( "WWW::Mechanize",$_ )
101 for (qw( cookie_jar current_form forms ));
102
103 disable( "Term::Shell",$_ )
104 for (qw( print_pairs ));
105
106 for my $cmd (@history_invariant) {
107 @history = ();
108 $s->cmd($cmd);
109 is_deeply( \@history, [], "$cmd is history invariant");
110 };
111 };