Commit | Line | Data |
635c7876 |
1 | #!/usr/local/bin/perl -w |
2 | |
3 | use strict ; |
99709852 |
4 | use File::Slurp ; |
635c7876 |
5 | |
6 | use Carp ; |
7 | use POSIX qw( :fcntl_h ) ; |
99709852 |
8 | use Test::More tests => 1 ; |
635c7876 |
9 | |
10 | # in case SEEK_SET isn't defined in older perls. it seems to always be 0 |
11 | |
12 | BEGIN { |
13 | |
99709852 |
14 | *SEEK_SET = sub { 0 } unless defined \&SEEK_SET ; |
635c7876 |
15 | } |
16 | |
17 | SKIP: { |
18 | |
19 | eval { require B } ; |
20 | |
21 | skip <<TEXT, 1 if $@ ; |
22 | B.pm not found in this Perl. This will cause slurping of |
23 | the DATA handle to fail. |
24 | TEXT |
25 | |
26 | test_data_list_slurp() ; |
27 | } |
28 | |
29 | exit ; |
30 | |
31 | |
32 | sub test_data_list_slurp { |
33 | |
34 | my $data_seek = tell( \*DATA ); |
35 | |
36 | # first slurp in the lines |
12444d55 |
37 | |
635c7876 |
38 | my @slurp_lines = read_file( \*DATA ) ; |
39 | |
40 | # now seek back and read all the lines with the <> op and we make |
41 | # golden data sets |
42 | |
43 | seek( \*DATA, $data_seek, SEEK_SET ) || die "seek $!" ; |
44 | my @data_lines = <DATA> ; |
45 | |
46 | # test the array slurp |
47 | |
48 | ok( eq_array( \@data_lines, \@slurp_lines ), 'list slurp of DATA' ) ; |
49 | } |
50 | |
51 | __DATA__ |
52 | line one |
53 | second line |
54 | more lines |
55 | still more |
56 | |
57 | enough lines |
58 | |
59 | we can't test long handle slurps from DATA since i would have to type |
60 | too much stuff |
61 | |
62 | so we will stop here |