This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get t/uni/cache.t working under minitest
[perl5.git] / t / op / require_37033.t
CommitLineData
87606032
NC
1#!perl -w
2use strict;
3
4# Check that require doesn't leave the handle it uses open, if it happens that
5# the handle it opens gets file descriptor 0. RT #37033.
6
7require './test.pl';
8@INC = 'lib';
9
10sub test_require {
11 my ($state, $want) = @_;
12 delete $INC{'test_use_14937.pm'};
13 open my $fh, '<', 'README' or die "Can't open README: $!";
14 my $fileno = fileno $fh;
15 if (defined $want) {
16 is($fileno, $want,
17 "file handle has correct numeric file descriptor $state");
18 } else {
19 like($fileno, qr/\A\d+\z/,
20 "file handle has a numeric file descriptor $state");
21 }
22 close $fh or die;
23
24 is($INC{'test_use_14937.pm'}, undef, "test_use_14937 isn't loaded $state");
25 require test_use_14937;
26 isnt($INC{'test_use_14937.pm'}, undef, "test_use_14937 is loaded $state");
27
28 open $fh, '<', 'README' or die "Can't open README: $!";
29 is(fileno $fh, $fileno,
30 "file handle has the same numeric file descriptor $state");
31 close $fh or die;
32}
33
34is(fileno STDIN, 0, 'STDIN is open on file descriptor 0');
35test_require('(STDIN open)');
36
37close STDIN or die "Can't close STDIN: $!";
38
39is(fileno STDIN, undef, 'STDIN is closed');
40test_require('(STDIN closed)', 0);
41
42done_testing();