Switch from pkg-config to pkgconf
[dpkg.git] / scripts / t / Dpkg_File.t
bloba1292af39f582952af5d0dcacbce94ee35003eec
1 #!/usr/bin/perl
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/>.
16 use strict;
17 use warnings;
19 use Test::More tests => 10;
20 use Test::Dpkg qw(:paths);
22 use File::Compare;
23 use File::Path qw(rmtree);
25 BEGIN {
26 use_ok('Dpkg::File');
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");
35 $data_ref = <<'DATA';
36 first line
37 next line
38 final line
39 DATA
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);
50 close $data_fh;
51 $data_ref = <<'DATA';
52 next line
53 final line
54 DATA
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");
65 close $data_fh;
66 ok(compare("$tempdir/append-me", "$datadir/append-me") == 0,
67 'dumped appended data');
69 $data = undef;
70 eval {
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');