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