82dee7de92a0bd35 failed to add ext/lib/Makefile.PL. Oops.
[p5sagit/p5-mst-13.2.git] / ext / ExtUtils-MakeMaker / t / prompt.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     unshift @INC, 't/lib';
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 }