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