3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 use Test
::More tests
=> 10;
20 use Test
::Dpkg
qw(:paths);
23 use File
::Path
qw(rmtree);
29 my $datadir = test_get_data_path
();
30 my $tempdir = test_get_temp_path
();
32 my ($data, $data_ref, $data_fh);
34 $data = file_slurp
("$datadir/slurp-me");
40 is
($data, $data_ref, 'slurped data');
42 file_dump
("$tempdir/slurp-me", $data);
43 ok
(compare
("$tempdir/slurp-me", "$datadir/slurp-me") == 0,
44 'dumped slurped data');
46 open $data_fh, '<', "$datadir/slurp-me"
47 or die "cannot open $datadir/slurp-me for reading: $!";
48 my $discard = <$data_fh>;
49 $data = file_slurp
($data_fh);
55 is
($data, $data_ref, 'slurped partial data');
57 file_dump
("$tempdir/dump-partial", $data);
58 ok
(compare
("$tempdir/dump-partial", "$datadir/dump-partial") == 0,
59 'dumped slurped partial data');
61 open $data_fh, '>', "$tempdir/append-me"
62 or die "cannot create $tempdir/append-me: $!";
63 print { $data_fh } "append line\n";
64 file_dump
($data_fh, "new line\nend line\n");
66 ok
(compare
("$tempdir/append-me", "$datadir/append-me") == 0,
67 'dumped appended data');
71 $data = file_slurp
("$datadir/non-existent");
73 ok
($@
, 'cannot slurp missing file');
75 ok
(! -e
"$tempdir/touched", 'file to be touched does not exist');
76 file_touch
("$tempdir/touched");
77 ok
(-e
"$tempdir/touched", 'touched file exists');
78 ok
(-z
"$tempdir/touched", 'touched file is empty');