xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/t/prompt.t (revision 56d68f1e19ff848c889ecfa71d3a06340ff64892)
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$ENV{PERL_MM_USE_DEFAULT} = 0;
39close STDIN;
40my $stdin = tie *STDIN, 'TieIn' or die;
41$stdin->write("From STDIN");
42ok( !-t STDIN,      'STDIN not a tty' );
43
44is( prompt("Foo?", 'Bar!'), 'From STDIN',     'from STDIN' );
45like( $stdout->read,  qr/^Foo\? \[Bar!\]\s*$/,      '  question' );
46