summaryrefslogtreecommitdiffstats
path: root/t/dh_compress.t
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 21:06:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 21:06:40 +0000
commitd827c6cf1631209f5042a9d1d8a7ecc24223c8a0 (patch)
tree91a431d301efd0e524bdfb0c46e97d591a9d7b03 /t/dh_compress.t
parentInitial commit. (diff)
downloaddebhelper-317edf61ca7b4a9acdf8a38e4b634bad6c07ddf6.tar.xz
debhelper-317edf61ca7b4a9acdf8a38e4b634bad6c07ddf6.zip
Adding upstream version 13.11.4.upstream/13.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 't/dh_compress.t')
-rwxr-xr-xt/dh_compress.t114
1 files changed, 114 insertions, 0 deletions
diff --git a/t/dh_compress.t b/t/dh_compress.t
new file mode 100755
index 0000000..1eb6156
--- /dev/null
+++ b/t/dh_compress.t
@@ -0,0 +1,114 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use File::Basename qw(dirname);
+use lib dirname(__FILE__);
+use Test::DH;
+
+use File::Path qw(make_path remove_tree);
+use Test::More;
+use Debian::Debhelper::Dh_Lib qw(!dirname);
+
+my $PREFIX = 'debian/debhelper/usr/share/doc/debhelper';
+
+plan tests => 2;
+
+each_compat_subtest {
+ # we are testing compressing doc txt files
+ # foo.txt is 2k and bar.txt is 5k
+ mk_test_dir();
+
+ # default operation, bar.txt becomes bar.txt.gz and foo.txt is
+ # unchanged
+ ok(run_dh_tool('dh_compress'));
+
+ is_deeply(
+ [map { s{${PREFIX}/}{}; $_ } sort glob "$PREFIX/*"],
+ [qw|bar.txt.gz foo.txt|],
+ '5k txt doc compressed, 2k txt doc not compressed'
+ );
+
+ mk_test_dir();
+
+ # now if I want to pass both on the command line to dh_compress,
+ # it should compress both
+ ok(run_dh_tool('dh_compress', '--',
+ 'usr/share/doc/debhelper/foo.txt',
+ 'usr/share/doc/debhelper/bar.txt'));
+
+ is_deeply(
+ [map { s{${PREFIX}/}{}; $_ } sort glob "$PREFIX/*"],
+ [qw|bar.txt.gz foo.txt.gz|],
+ 'both 5k and 2k txt docs compressed'
+ );
+
+ mk_test_dir();
+
+ # absolute paths should also work
+ ok(run_dh_tool('dh_compress', '--',
+ '/usr/share/doc/debhelper/foo.txt',
+ '/usr/share/doc/debhelper/bar.txt'));
+
+ is_deeply(
+ [map { s{${PREFIX}/}{}; $_ } sort glob "$PREFIX/*"],
+ [qw|bar.txt.gz foo.txt.gz|],
+ 'both 5k and 2k txt docs compressed by absolute path args'
+ );
+
+ rm_test_dir();
+
+ mk_test_dir();
+
+ is(system('cp', '-la', "${PREFIX}/bar.txt", "${PREFIX}/hardlink.txt"), 0,
+ 'create hardlink');
+
+ ok(run_dh_tool('dh_compress'));
+
+ is_deeply(
+ [map { s{${PREFIX}/}{}; $_ } sort glob "$PREFIX/*"],
+ [qw|bar.txt.gz foo.txt hardlink.txt.gz|],
+ 'the 5k and its hardlink txt docs compressed'
+ );
+
+ # Verify that the hardlink is preserved.
+ my ($dev1, $inode1) = stat("${PREFIX}/bar.txt.gz") // error("stat ${PREFIX}/bar.txt.gz: $!");
+ my ($dev2, $inode2) = stat("${PREFIX}/hardlink.txt.gz") // error("stat ${PREFIX}/hardlink.txt.gz: $!");
+
+ is($dev1, $dev2, 'Still hardlinked');
+ is($inode1, $inode2, 'Still hardlinked');
+
+ rm_test_dir();
+};
+
+each_compat_from_and_above_subtest(12, sub {
+ make_path("${PREFIX}/examples");
+ create_file_of_size("${PREFIX}/examples/foo.py", 5120);
+ ok(run_dh_tool('dh_compress'));
+ ok(-f "${PREFIX}/examples/foo.py", "${PREFIX}/examples/foo.py is not compressed");
+ ok(! -f "${PREFIX}/examples/foo.py.gz", "${PREFIX}/examples/foo.py is not compressed");
+});
+
+sub create_file_of_size {
+ my ($filename, $size) = @_;
+ open(my $fh, '>', $filename) or error("open($filename) failed: $!");
+ print {$fh} 'X' x $size;
+ close($fh) or error("close($filename) failed: $!");
+}
+
+sub mk_test_dir {
+ rm_test_dir();
+
+ make_path($PREFIX);
+
+ create_file_of_size("${PREFIX}/foo.txt", 2048);
+ create_file_of_size("${PREFIX}/bar.txt", 5120);
+}
+
+sub rm_test_dir {
+ remove_tree('debian/debhelper');
+
+ rm_files('debian/debhelper.debhelper.log');
+}
+