This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Force LONG_DOUBLEKIND always to be probed for.
[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
b5efbd1f 7chdir 't' if -d 't';
87606032
NC
8require './test.pl';
9@INC = 'lib';
10
11sub test_require {
12 my ($state, $want) = @_;
13 delete $INC{'test_use_14937.pm'};
14 open my $fh, '<', 'README' or die "Can't open README: $!";
15 my $fileno = fileno $fh;
16 if (defined $want) {
17 is($fileno, $want,
18 "file handle has correct numeric file descriptor $state");
19 } else {
20 like($fileno, qr/\A\d+\z/,
21 "file handle has a numeric file descriptor $state");
22 }
23 close $fh or die;
24
25 is($INC{'test_use_14937.pm'}, undef, "test_use_14937 isn't loaded $state");
26 require test_use_14937;
27 isnt($INC{'test_use_14937.pm'}, undef, "test_use_14937 is loaded $state");
28
29 open $fh, '<', 'README' or die "Can't open README: $!";
30 is(fileno $fh, $fileno,
31 "file handle has the same numeric file descriptor $state");
32 close $fh or die;
33}
34
35is(fileno STDIN, 0, 'STDIN is open on file descriptor 0');
36test_require('(STDIN open)');
37
38close STDIN or die "Can't close STDIN: $!";
39
40is(fileno STDIN, undef, 'STDIN is closed');
41test_require('(STDIN closed)', 0);
42
43done_testing();