Commit | Line | Data |
479d2113 |
1 | #!/usr/bin/perl -w |
2 | |
3 | BEGIN { |
b78fd716 |
4 | unshift @INC, 't/lib'; |
479d2113 |
5 | } |
6 | |
7 | use strict; |
8 | use Test::More tests => 11; |
9 | use ExtUtils::MakeMaker; |
10 | use TieOut; |
11 | use TieIn; |
12 | |
13 | eval q{ |
14 | prompt(); |
15 | }; |
16 | like( $@, qr/^Not enough arguments for ExtUtils::MakeMaker::prompt/, |
17 | 'no args' ); |
18 | |
19 | eval { |
20 | prompt(undef); |
21 | }; |
22 | like( $@, qr/^prompt function called without an argument/, |
23 | 'undef message' ); |
24 | |
25 | my $stdout = tie *STDOUT, 'TieOut' or die; |
26 | |
27 | |
28 | $ENV{PERL_MM_USE_DEFAULT} = 1; |
29 | is( prompt("Foo?"), '', 'no default' ); |
30 | like( $stdout->read, qr/^Foo\?\s*\n$/, ' question' ); |
31 | |
32 | is( prompt("Foo?", undef), '', 'undef default' ); |
33 | like( $stdout->read, qr/^Foo\?\s*\n$/, ' question' ); |
34 | |
35 | is( prompt("Foo?", 'Bar!'), 'Bar!', 'default' ); |
36 | like( $stdout->read, qr/^Foo\? \[Bar!\]\s+Bar!\n$/, ' question' ); |
37 | |
38 | |
39 | SKIP: { |
40 | skip "eof() doesn't honor ties in 5.5.3", 3 if $] < 5.006; |
41 | |
42 | $ENV{PERL_MM_USE_DEFAULT} = 0; |
43 | close STDIN; |
44 | my $stdin = tie *STDIN, 'TieIn' or die; |
45 | $stdin->write("From STDIN"); |
46 | ok( !-t STDIN, 'STDIN not a tty' ); |
47 | |
48 | is( prompt("Foo?", 'Bar!'), 'From STDIN', 'from STDIN' ); |
49 | like( $stdout->read, qr/^Foo\? \[Bar!\]\s*$/, ' question' ); |
50 | } |