File: 20-remap.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 (45 lines) | stat: -rw-r--r-- 1,325 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
35
36
37
38
39
40
41
42
43
44
45
#!perl

use strict;
use warnings;
use Test::More $^O eq 'linux' ? (tests => 15) : skip_all => 'Only works on Linux';
use File::Map qw/map_handle map_anonymous remap/;
use Test::Fatal 'lives_ok';
use Test::Warnings;

open my $fh, '>', undef or die "Couln't open tempfile: $!\n";

print {$fh} "$_ pidgeons are evil\n" for 1 .. 1000;

my $map;
lives_ok { map_handle $map, $fh, '+>' } 'Can map tempfile';

is length $map, -s $fh, 'map length equals file length';

lives_ok { substr $map, 0, 1, '1' } 'Can write to start of map';

print {$fh} "$_ pidgeons are evil\n" for 1001 .. 2000;

lives_ok { remap $map, -s $fh } 'Can remap file';

is length $map, -s $fh, 'map length equals file length';

lives_ok { substr $map, 1, 1, '2' } 'Can write to start of map';

lives_ok { substr $map, -1, 1, '2' } 'Can write to end of map';

my $anon;
lives_ok { map_anonymous $anon, 4096, 'private' } 'Creating an anonymous mapping';

is length $anon, 4096, 'length of anonymous map is alright';

lives_ok { substr $anon, 0, 1, '1' } 'Can write to start of anonymous map';

lives_ok { remap $anon, 65535 } 'Can remap anonymous mapping';

is length $anon, 65535, '$anon is lengthened';

lives_ok { substr $anon, 1, 1, '2' } 'Can write to start of anonymous map';

lives_ok { substr $anon, -1, 1, "\0" } 'Can write to new end of anonymous map';