This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/op/qr.t: Don't use fancy apostrophe
[perl5.git] / t / op / require_37033.t
CommitLineData
87606032 1#!perl -w
87606032
NC
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
b5efbd1f 6chdir 't' if -d 't';
87606032 7require './test.pl';
624c42e2 8set_up_inc( 'lib' );
87606032 9
0b1b7115
JH
10use strict;
11
87606032
NC
12sub 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
36is(fileno STDIN, 0, 'STDIN is open on file descriptor 0');
37test_require('(STDIN open)');
38
39close STDIN or die "Can't close STDIN: $!";
40
41is(fileno STDIN, undef, 'STDIN is closed');
42test_require('(STDIN closed)', 0);
43
44done_testing();