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 46 47 48 49 50 51 52 53 54
|
use strict;
use warnings;
use File::Spec ();
use File::Slurp;
use File::Temp qw(tempfile);
use IO::Handle ();
use POSIX qw( :fcntl_h ) ;
use Test::More;
plan tests => 9;
# get the current position (BYTES)_
my $data_seek = tell(\*DATA);
ok($data_seek, 'tell: find position of __DATA__');
# get the baseline to test against
my @data_lines = <DATA>;
ok(@data_lines, 'readfile<>: list context, joined - grabbed __DATA__');
my $data_text = join '', @data_lines;
ok($data_text, 'Got a good baseline text');
# seek back to that inital BYTES position
my $seek = seek(\*DATA, $data_seek, 0) || die "seek $!" ;
ok($seek, 'seek: Move back to original __DATA__ position');
# first slurp in the text
my $slurp_text = read_file(\*DATA);
ok($slurp_text, 'read_file: scalar context - grabbed __DATA__');
is($slurp_text, $data_text, 'scalar read matches baseline');
# seek back to that inital BYTES position
$seek = seek(\*DATA, $data_seek, 0) || die "seek $!" ;
ok($seek, 'seek: Move back to original __DATA__ position');
# first slurp in the lines
my @slurp_lines = read_file(\*DATA);
ok(@slurp_lines, 'read_file: list context - grabbed __DATA__');
is_deeply(\@slurp_lines, \@data_lines, 'list read matches baseline');
exit();
__DATA__
line one
second line
more lines
still more
enough lines
we can't test long handle slurps from DATA since i would have to type
too much stuff
so we will stop here
|