File: interactive_no_term_readkey.t

package info (click to toggle)
libio-prompter-perl 0.003000-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 332 kB
  • sloc: perl: 1,176; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 700 bytes parent folder | download | duplicates (7)
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

use lib qw< slib >;

use 5.010;
use warnings;
use Test::More;

use IO::Prompter;

if (!-t *STDIN || !-t *STDERR) {
    plan('skip_all' => 'Non-interactive test environment');
}
else {
    plan('no_plan');
}

select *STDERR;

my %ok = (
    'Pure prompt'       => 0,
    'Assignment prompt' => 0,
    '$_ unaffected'     => 0,
);

say {STDERR} q{};

if (prompt -i, "\tEnter an integer: ") {
    $ok{'Pure prompt'} = m{ ^ \s* [+-]? \d++ \s* $ }x;
}

$_ = 'UNDERBAR';
if (my $input = prompt -i, "\tEnter another integer: ") {
    $ok{'Assignment prompt'} = $input =~ m{ ^ \s* [+-]? \d++ \s* $ }x;
    $ok{'$_ unaffected'} = $_ eq 'UNDERBAR';
}

for my $test (keys %ok) {
    ok $ok{$test} => $test;
}