1 ### Term::UI test suite ###
4 use lib qw[../lib lib];
5 use Test::More tests => 13;
10 ### make sure we can do this automatically ###
11 $Term::UI::AUTOREPLY = $Term::UI::AUTOREPLY = 1;
12 $Term::UI::VERBOSE = $Term::UI::VERBOSE = 0;
17 ### perl core gets upset if we print stuff to STDOUT...
18 if( $ENV{PERL_CORE} ) {
19 *STDOUT_SAVE = *STDOUT_SAVE = *STDOUT;
21 open *STDOUT, ">termui.$$" or diag("Could not open tempfile");
23 END { unlink "termui.$$" if $ENV{PERL_CORE} }
26 ### so T::RL doesn't go nuts over no console
27 BEGIN{ $ENV{LINES}=25; $ENV{COLUMNS}=80; }
28 my $term = Term::ReadLine->new('test')
29 or diag "Could not create a new term. Dying", die;
32 prompt => "What is your favourite colour?",
33 choices => [qw|blue red green|],
38 my $args = \%{ $tmpl };
40 is( $term->get_reply( %$args ), 'blue', q[Checking reply with defaults and choices] );
44 my $args = \%{ $tmpl };
45 delete $args->{choices};
47 is( $term->get_reply( %$args ), 'blue', q[Checking reply with defaults] );
52 prompt => 'Do you like cookies?',
56 is( $term->ask_yn( %$args ), 1, q[Asking yes/no with 'yes' as default] );
61 prompt => 'Do you like Python?',
65 is( $term->ask_yn( %$args ), 0, q[Asking yes/no with 'no' as default] );
69 # used to print: Use of uninitialized value in length at Term/UI.pm line 141.
72 prompt => 'Uninit warning on empty default',
76 local $SIG{__WARN__} = sub { $warnings .= "@_" };
78 my $res = $term->get_reply( %$args );
80 ok( !$res, "Empty result on autoreply without default" );
81 is( $warnings, '', " No warnings with empty default" );
82 unlike( $warnings, qr|Term.UI|,
83 " No warnings from Term::UI" );
87 # used to print: Use of uninitialized value in string at Params/Check.pm
90 prompt => 'Undef warning on failing allow',
95 local $SIG{__WARN__} = sub { $warnings .= "@_" };
97 my $res = $term->get_reply( %$args );
99 ok( !$res, "Empty result on autoreply without default" );
100 is( $warnings, '', " No warnings with failing allow" );
101 unlike( $warnings, qr|Params.Check|,
102 " No warnings from Params::Check" );
106 #### test parse_options
108 my $str = q[command --no-foo --baz --bar=0 --quux=bleh ] .
109 q[--option="some'thing" -one-dash -single=blah' foo];
111 my $munged = 'command foo';
117 option => q[some'thing],
122 my ($href,$rest) = $term->parse_options( $str );
124 is_deeply( $href, $expected, q[Parsing options] );
125 is($rest,$munged, q[Remaining unparsed string] );