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