File: sysopen_strict.t

package info (click to toggle)
libtest-mockfile-perl 0.037-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: perl: 4,110; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 817 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -w

use strict;
use warnings;

use Test2::Bundle::Extended;
use Test2::Plugin::NoWarnings;

my $can_run;
BEGIN {
    $can_run = ($^V ge 5.28.0);
}

use Test::MockFile ($can_run ? ( plugin => 'FileTemp' ) : ());

use Fcntl;
use File::Temp;

plan skip_all => 'Needs FileTemp plugin' if !$can_run;

my $dir = File::Temp::tempdir( CLEANUP => 1 );

my ($separator) = $dir =~ m<([\\/])> or die "No separator in $dir!";

Test::MockFile::add_strict_rule(
    'open',
    qr<\Q$dir$separator\E>,
    1,
);

my $path = "$dir${separator}file";
sysopen my $fh, $path, Fcntl::O_WRONLY | Fcntl::O_CREAT or die "sysopen($path): $!";

my $fh_str = "$fh";

my $err = dies { sysopen my $fh2, $fh, Fcntl::O_RDONLY };
like(
    $err,
    qr<\Q$fh_str\E>,
    'sysopen() to read a filehandle fails',
);

done_testing;

1;