1#!/usr/bin/perl -w 2 3BEGIN { 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 13use strict; 14use Test::More tests => 11; 15use ExtUtils::MakeMaker; 16use TieOut; 17use TieIn; 18 19eval q{ 20 prompt(); 21}; 22like( $@, qr/^Not enough arguments for ExtUtils::MakeMaker::prompt/, 23 'no args' ); 24 25eval { 26 prompt(undef); 27}; 28like( $@, qr/^prompt function called without an argument/, 29 'undef message' ); 30 31my $stdout = tie *STDOUT, 'TieOut' or die; 32 33 34$ENV{PERL_MM_USE_DEFAULT} = 1; 35is( prompt("Foo?"), '', 'no default' ); 36like( $stdout->read, qr/^Foo\?\s*\n$/, ' question' ); 37 38is( prompt("Foo?", undef), '', 'undef default' ); 39like( $stdout->read, qr/^Foo\?\s*\n$/, ' question' ); 40 41is( prompt("Foo?", 'Bar!'), 'Bar!', 'default' ); 42like( $stdout->read, qr/^Foo\? \[Bar!\]\s+Bar!\n$/, ' question' ); 43 44 45SKIP: { 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} 57