|
| 1 | +#!./perl -w |
| 2 | +use strict; |
| 3 | + |
| 4 | +use Test::More; |
| 5 | + |
| 6 | +## unit test for RT 132008 - https://rt.perl.org/Ticket/Display.html?id=132008 |
| 7 | + |
| 8 | +if ( $^O eq 'MSWin32' || !-e q{/dev/tty} ) { |
| 9 | + plan skip_all => "Test not tested on windows or when /dev/tty do not exists"; |
| 10 | +} |
| 11 | +else { |
| 12 | + plan tests => 9; |
| 13 | +} |
| 14 | + |
| 15 | +if ( -e q[&STDERR] ) { |
| 16 | + note q[Removing existing file &STDERR]; |
| 17 | + unlink q[&STDERR] or die q{Cannot remove existign file &STDERR [probably created from a previous run]}; |
| 18 | +} |
| 19 | + |
| 20 | +use_ok('Term::ReadLine'); |
| 21 | +can_ok( 'Term::ReadLine::Stub', qw{new devtty findConsole} ); |
| 22 | + |
| 23 | +is( Term::ReadLine->devtty(), q{/dev/tty} ); |
| 24 | +my @out = Term::ReadLine::Stub::findConsole(); |
| 25 | +is_deeply \@out, [ q{/dev/tty}, q{/dev/tty} ], "findConsole is using /dev/tty"; |
| 26 | + |
| 27 | +{ |
| 28 | + no warnings 'redefine'; |
| 29 | + my $donotexist = q[/this/should/not/exist/hopefully]; |
| 30 | + |
| 31 | + ok !-e $donotexist, "File $donotexist does not exist"; |
| 32 | + local *Term::ReadLine::Stub::devtty = sub { $donotexist }; |
| 33 | + is( Term::ReadLine->devtty(), $donotexist, "devtty mocked" ); |
| 34 | + |
| 35 | + my @out = Term::ReadLine::Stub::findConsole(); |
| 36 | + is_deeply \@out, [ q{&STDIN}, q{&STDERR} ], "findConsole is using /dev/tty" or diag explain \@out; |
| 37 | + |
| 38 | + ok !-e q[&STDERR], 'file &STDERR do not exist before Term::ReadLine call'; |
| 39 | + my $tr = Term::ReadLine->new('whatever'); |
| 40 | + ok !-e q[&STDERR], 'file &STDERR was not created by mistake'; |
| 41 | +} |
0 commit comments