File: 10-empty.t

package info (click to toggle)
libfile-map-perl 0.71-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 784 kB
  • sloc: perl: 365; ansic: 97; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 982 bytes parent folder | download | duplicates (5)
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
#!perl

use strict;
use warnings;
use File::Map qw/:map lock_map sync/;
use IO::Handle;
use Test::More tests => 9;
use Test::Warnings 0.005 qw/warning/;
use Test::Fatal qw/lives_ok/;

open my $fh, '+<:raw', undef;

my $mmaped;

lives_ok { map_handle $mmaped, $fh } "map succeeded";
ok(defined $mmaped,                  "mmaped is defined");
cmp_ok(length $mmaped, '==', 0,      "length of mmaped is big enough");
ok($mmaped eq "",                    "mmaped eq \"\"");
is($mmaped, "",                      "mmaped is \"\"");

lives_ok { sync $mmaped } "can fake syncing empty file";

TODO: {
	todo_skip '5.8.7- gives spurious warnings', 2 if $] <= 5.008007;
	my $mmaped2;
	lives_ok { map_handle $mmaped2, $fh, '>' } "Can't map empty file writably";

	like(warning { substr $mmaped2, 0, 0, "1" }, qr/^Can't overwrite an empty map at /, 'Shouldn\'t assign to empty map');
}

foreach my $filename ( 1, 2 ) {
    my $input_filename = $0;
    map_file my $input, $input_filename, '<';
}