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