[debsums] 01/06: Add second fake chroot for testing clean packages
Axel Beckert
abe at deuxchevaux.org
Thu Mar 26 00:53:55 UTC 2015
This is an automated email from the git hooks/post-receive script.
abe pushed a commit to branch master
in repository debsums.
commit e9c32f324a4a10efc53895aaca38170201e76a86
Author: Axel Beckert <abe at deuxchevaux.org>
Date: Thu Mar 26 01:10:07 2015 +0100
Add second fake chroot for testing clean packages
Refactor testing for less code duplication.
---
t/debsums.t | 101 +++++++++++++--------
t/{fakechroot => fakechroot-clean}/etc/fakepkg.cfg | 0
.../usr/share/doc/fakepkg/changelog.Debian.gz | Bin
.../usr/share/doc/fakepkg/copyright | 0
.../var/lib/dpkg/info/fakepkg.conffiles | 1 +
.../var/lib/dpkg/info/fakepkg.list | 2 -
.../var/lib/dpkg/info/fakepkg.md5sums | 1 -
.../var/lib/dpkg/status | 1 -
.../var/lib/dpkg/updates/.emptydir | 0
.../etc/fakepkg-broken.cfg | 0
t/{fakechroot => fakechroot-dirty}/etc/fakepkg.cfg | 0
.../usr/share/doc/fakepkg/README | 0
.../usr/share/doc/fakepkg/changelog.Debian.gz | Bin
.../usr/share/doc/fakepkg/copyright | 0
.../var/lib/dpkg/info/fakepkg.conffiles | 0
.../var/lib/dpkg/info/fakepkg.list | 0
.../var/lib/dpkg/info/fakepkg.md5sums | 0
.../var/lib/dpkg/status | 0
.../var/lib/dpkg/updates/.emptydir | 0
19 files changed, 65 insertions(+), 41 deletions(-)
diff --git a/t/debsums.t b/t/debsums.t
index 0a4fc8f..0463e2a 100644
--- a/t/debsums.t
+++ b/t/debsums.t
@@ -8,56 +8,77 @@ use warnings;
use Test::More;
use Test::Command::Simple;
-# Default dummy chroot as test bed
-my $chroot_option = '--root=t/fakechroot';
+my $command;
+my $chroot;
+my @command;
# Untaint stuff
delete $ENV{PATH};
# First check if we are testing a source package (debsums in current
# directory) or an installed package (full path).
-my $command;
foreach my $cmd (qw(./debsums /usr/bin/debsums)) {
$command = $cmd if -x $cmd;
}
ok($command, "Command debsums found at $command");
-my @command = ($command, $chroot_option);
-
-# Test running without any further parameters
-run(@command);
-is(stderr, '', 'STDERR is empty');
-is(stdout, <<'EOT', 'STDOUT as expected (2 OK, 1 FAILED)');
-t/fakechroot/usr/share/doc/fakepkg/copyright OK
-t/fakechroot/usr/share/doc/fakepkg/changelog.Debian.gz OK
-t/fakechroot/usr/share/doc/fakepkg/README FAILED
-EOT
-is(rc >> 8, 2, 'Exit code is 2');
-# Test option -c
-run(@command, '-c');
-is(stderr, '', 'STDERR is empty');
-is(stdout, <<'EOT', 'STDOUT as expected (1 FAILED)');
-t/fakechroot/usr/share/doc/fakepkg/README
-EOT
-is(rc >> 8, 2, 'Exit code is 2');
-
-# Test option -e
-run(@command);
-is(stderr, '', 'STDERR is empty');
-is(sort_lines(stdout), sort_lines(<<'EOT'), 'STDOUT as expected (1 OK, 1 FAILED)');
-t/fakechroot/etc/fakepkg.cfg OK
-t/fakechroot/etc/fakepkg-broken.cfg FAILED
+foreach my $state (qw(clean dirty)) {
+ $chroot = "t/fakechroot-$state";
+ my $exit_code = $state eq 'clean' ? 0 : 2;
+
+ foreach my $pkg ('', 'fakepkg') {
+ @command = ($command, "--root=$chroot");
+ @command = (@command, $pkg) if $pkg;
+
+ my $expected = <<"EOT";
+$chroot/usr/share/doc/fakepkg/copyright OK
+$chroot/usr/share/doc/fakepkg/changelog.Debian.gz OK
+$chroot/usr/share/doc/fakepkg/README FAILED
EOT
-is(rc >> 8, 2, 'Exit code is 2');
-
-# Test option -ce and variants
-foreach my $option (qw(-ce -ec)) {
- run(@command, $option);
- is(stderr, '', 'STDERR is empty');
- is(stdout, <<'EOT', 'STDOUT as expected (1 FAILED)');
-t/fakechroot/etc/fakepkg-broken.cfg
+ $expected = remove_failed($expected)
+ if $state eq 'clean';
+
+ my $expected_conffiles = <<"EOT";
+$chroot/etc/fakepkg.cfg OK
+$chroot/etc/fakepkg-broken.cfg FAILED
EOT
- is(rc >> 8, 2, 'Exit code is 2');
+ $expected_conffiles = remove_failed($expected_conffiles)
+ if $state eq 'clean';
+
+ # Test running without any further parameters
+ run(@command);
+ is(stderr, '', 'STDERR is empty');
+ is(stdout, $expected, 'STDOUT as expected');
+ is(rc >> 8, $exit_code, "Exit code is $exit_code");
+
+ # Test option -c
+ run(@command, '-c');
+ is(stderr, '', 'STDERR is empty');
+ is(stdout,
+ $state eq 'clean' ? '' :
+ "$chroot/usr/share/doc/fakepkg/README\n",
+ 'STDOUT as expected');
+ is(rc >> 8, $exit_code, "Exit code is $exit_code");
+
+ # Test option -e
+ run(@command);
+ is(stderr, '', 'STDERR is empty');
+ is(sort_lines(stdout),
+ sort_lines($expected_conffiles),
+ 'STDOUT as expected');
+ is(rc >> 8, $exit_code, "Exit code is $exit_code");
+
+ # Test option -ce and variants
+ foreach my $option (qw(-ce -ec)) {
+ run(@command, $option);
+ is(stderr, '', 'STDERR is empty');
+ is(stdout,
+ $state eq 'clean' ? '' :
+ "$chroot/etc/fakepkg-broken.cfg\n",
+ 'STDOUT as expected');
+ is(rc >> 8, $exit_code, "Exit code is $exit_code");
+ }
+ }
}
done_testing();
@@ -67,3 +88,9 @@ sub sort_lines {
return join("\n", sort split("\n", $string)).
$string =~ m/\n\z/ ? "\n" : '';
}
+
+sub remove_failed {
+ my $string = shift;
+ return join("\n", grep { !/FAILED/ } split("\n", $string)).
+ ($string =~ m/\n\z/ ? "\n" : '');
+}
diff --git a/t/fakechroot/etc/fakepkg.cfg b/t/fakechroot-clean/etc/fakepkg.cfg
similarity index 100%
copy from t/fakechroot/etc/fakepkg.cfg
copy to t/fakechroot-clean/etc/fakepkg.cfg
diff --git a/t/fakechroot/usr/share/doc/fakepkg/changelog.Debian.gz b/t/fakechroot-clean/usr/share/doc/fakepkg/changelog.Debian.gz
similarity index 100%
copy from t/fakechroot/usr/share/doc/fakepkg/changelog.Debian.gz
copy to t/fakechroot-clean/usr/share/doc/fakepkg/changelog.Debian.gz
diff --git a/t/fakechroot/usr/share/doc/fakepkg/copyright b/t/fakechroot-clean/usr/share/doc/fakepkg/copyright
similarity index 100%
copy from t/fakechroot/usr/share/doc/fakepkg/copyright
copy to t/fakechroot-clean/usr/share/doc/fakepkg/copyright
diff --git a/t/fakechroot-clean/var/lib/dpkg/info/fakepkg.conffiles b/t/fakechroot-clean/var/lib/dpkg/info/fakepkg.conffiles
new file mode 100644
index 0000000..8e3fbe9
--- /dev/null
+++ b/t/fakechroot-clean/var/lib/dpkg/info/fakepkg.conffiles
@@ -0,0 +1 @@
+/etc/fakepkg.cfg
diff --git a/t/fakechroot/var/lib/dpkg/info/fakepkg.list b/t/fakechroot-clean/var/lib/dpkg/info/fakepkg.list
similarity index 73%
copy from t/fakechroot/var/lib/dpkg/info/fakepkg.list
copy to t/fakechroot-clean/var/lib/dpkg/info/fakepkg.list
index 77a8665..15e4d61 100644
--- a/t/fakechroot/var/lib/dpkg/info/fakepkg.list
+++ b/t/fakechroot-clean/var/lib/dpkg/info/fakepkg.list
@@ -4,7 +4,5 @@
/usr/share/doc/fakepkg
/usr/share/doc/fakepkg/copyright
/usr/share/doc/fakepkg/changelog.Debian.gz
-/usr/share/doc/fakepkg/README
/etc
-/etc/fakepkg-broken.cfg
/etc/fakepkg.cfg
diff --git a/t/fakechroot/var/lib/dpkg/info/fakepkg.md5sums b/t/fakechroot-clean/var/lib/dpkg/info/fakepkg.md5sums
similarity index 69%
copy from t/fakechroot/var/lib/dpkg/info/fakepkg.md5sums
copy to t/fakechroot-clean/var/lib/dpkg/info/fakepkg.md5sums
index 492102e..05dad8d 100644
--- a/t/fakechroot/var/lib/dpkg/info/fakepkg.md5sums
+++ b/t/fakechroot-clean/var/lib/dpkg/info/fakepkg.md5sums
@@ -1,3 +1,2 @@
52f02364e60d4865543a2e935533ef33 usr/share/doc/fakepkg/copyright
082797d51b0c32d421e274b05926618a usr/share/doc/fakepkg/changelog.Debian.gz
-deadbeefcafebabedeadbeefcafebabe usr/share/doc/fakepkg/README
diff --git a/t/fakechroot/var/lib/dpkg/status b/t/fakechroot-clean/var/lib/dpkg/status
similarity index 86%
copy from t/fakechroot/var/lib/dpkg/status
copy to t/fakechroot-clean/var/lib/dpkg/status
index 539070f..c040b54 100644
--- a/t/fakechroot/var/lib/dpkg/status
+++ b/t/fakechroot-clean/var/lib/dpkg/status
@@ -10,4 +10,3 @@ Description: dummy package for debsums' test suite
This is an empty dummy package just used for debsums' test suite.
Conffiles:
/etc/fakepkg.cfg dc0b26e33cba0138a27aa00dcc90ae09
- /etc/fakepkg-broken.cfg deadbeefcafebabedeadbeefcafebabe
diff --git a/t/fakechroot/var/lib/dpkg/updates/.emptydir b/t/fakechroot-clean/var/lib/dpkg/updates/.emptydir
similarity index 100%
copy from t/fakechroot/var/lib/dpkg/updates/.emptydir
copy to t/fakechroot-clean/var/lib/dpkg/updates/.emptydir
diff --git a/t/fakechroot/etc/fakepkg-broken.cfg b/t/fakechroot-dirty/etc/fakepkg-broken.cfg
similarity index 100%
rename from t/fakechroot/etc/fakepkg-broken.cfg
rename to t/fakechroot-dirty/etc/fakepkg-broken.cfg
diff --git a/t/fakechroot/etc/fakepkg.cfg b/t/fakechroot-dirty/etc/fakepkg.cfg
similarity index 100%
rename from t/fakechroot/etc/fakepkg.cfg
rename to t/fakechroot-dirty/etc/fakepkg.cfg
diff --git a/t/fakechroot/usr/share/doc/fakepkg/README b/t/fakechroot-dirty/usr/share/doc/fakepkg/README
similarity index 100%
rename from t/fakechroot/usr/share/doc/fakepkg/README
rename to t/fakechroot-dirty/usr/share/doc/fakepkg/README
diff --git a/t/fakechroot/usr/share/doc/fakepkg/changelog.Debian.gz b/t/fakechroot-dirty/usr/share/doc/fakepkg/changelog.Debian.gz
similarity index 100%
rename from t/fakechroot/usr/share/doc/fakepkg/changelog.Debian.gz
rename to t/fakechroot-dirty/usr/share/doc/fakepkg/changelog.Debian.gz
diff --git a/t/fakechroot/usr/share/doc/fakepkg/copyright b/t/fakechroot-dirty/usr/share/doc/fakepkg/copyright
similarity index 100%
rename from t/fakechroot/usr/share/doc/fakepkg/copyright
rename to t/fakechroot-dirty/usr/share/doc/fakepkg/copyright
diff --git a/t/fakechroot/var/lib/dpkg/info/fakepkg.conffiles b/t/fakechroot-dirty/var/lib/dpkg/info/fakepkg.conffiles
similarity index 100%
rename from t/fakechroot/var/lib/dpkg/info/fakepkg.conffiles
rename to t/fakechroot-dirty/var/lib/dpkg/info/fakepkg.conffiles
diff --git a/t/fakechroot/var/lib/dpkg/info/fakepkg.list b/t/fakechroot-dirty/var/lib/dpkg/info/fakepkg.list
similarity index 100%
rename from t/fakechroot/var/lib/dpkg/info/fakepkg.list
rename to t/fakechroot-dirty/var/lib/dpkg/info/fakepkg.list
diff --git a/t/fakechroot/var/lib/dpkg/info/fakepkg.md5sums b/t/fakechroot-dirty/var/lib/dpkg/info/fakepkg.md5sums
similarity index 100%
rename from t/fakechroot/var/lib/dpkg/info/fakepkg.md5sums
rename to t/fakechroot-dirty/var/lib/dpkg/info/fakepkg.md5sums
diff --git a/t/fakechroot/var/lib/dpkg/status b/t/fakechroot-dirty/var/lib/dpkg/status
similarity index 100%
rename from t/fakechroot/var/lib/dpkg/status
rename to t/fakechroot-dirty/var/lib/dpkg/status
diff --git a/t/fakechroot/var/lib/dpkg/updates/.emptydir b/t/fakechroot-dirty/var/lib/dpkg/updates/.emptydir
similarity index 100%
rename from t/fakechroot/var/lib/dpkg/updates/.emptydir
rename to t/fakechroot-dirty/var/lib/dpkg/updates/.emptydir
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/debsums.git
More information about the Pkg-perl-cvs-commits
mailing list