[Reproducible-commits] [dpkg] 21/105: libdpkg: Add a unit test for the trigger deferred parser
Niko Tyni
ntyni at moszumanska.debian.org
Mon May 2 13:49:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
ntyni pushed a commit to branch ntyni/reproducible_builds
in repository dpkg.
commit 08ca3174ca1a7fd7d9ba7fd1a3b136ea1a34b0d6
Author: Guillem Jover <guillem at debian.org>
Date: Wed Mar 2 01:03:15 2016 +0100
libdpkg: Add a unit test for the trigger deferred parser
---
debian/changelog | 1 +
lib/dpkg/t/.gitignore | 1 +
lib/dpkg/t/Makefile.am | 2 +
lib/dpkg/t/c-trigdeferred.c | 96 ++++++++++++++++++++++++++++++++++
lib/dpkg/t/t-trigdeferred.t | 123 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 223 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index d05bab8..7caa3ce 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -70,6 +70,7 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
- Fix building development documentation.
* Test suite:
- Add a unit test to compile perl code with warnings.
+ - Add a unit test for the trigger deferred parser.
* Documentation:
- Say value instead of option in deb-control(5).
- Mark debian changelog format in bold in dpkg-parsechangelog(1).
diff --git a/lib/dpkg/t/.gitignore b/lib/dpkg/t/.gitignore
index fbff216..32bfc55 100644
--- a/lib/dpkg/t/.gitignore
+++ b/lib/dpkg/t/.gitignore
@@ -1,3 +1,4 @@
+c-trigdeferred
t-ar
t-arch
t-buffer
diff --git a/lib/dpkg/t/Makefile.am b/lib/dpkg/t/Makefile.am
index 419fd4f..30c2bdb 100644
--- a/lib/dpkg/t/Makefile.am
+++ b/lib/dpkg/t/Makefile.am
@@ -42,10 +42,12 @@ test_programs = \
test_scripts = \
t-tar.t \
t-tree.t \
+ t-trigdeferred.t \
$(nil)
check_PROGRAMS = \
$(test_programs) \
+ c-trigdeferred \
t-tarextract \
t-treewalk \
$(nil)
diff --git a/lib/dpkg/t/c-trigdeferred.c b/lib/dpkg/t/c-trigdeferred.c
new file mode 100644
index 0000000..5c34949
--- /dev/null
+++ b/lib/dpkg/t/c-trigdeferred.c
@@ -0,0 +1,96 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * c-trigdeferred.c - test triggerd deferred file parser
+ *
+ * Copyright © 2016 Guillem Jover <guillem at debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <dpkg/dpkg-db.h>
+#include <dpkg/ehandle.h>
+#include <dpkg/trigdeferred.h>
+
+static void
+test_tdm_begin(const char *trig)
+{
+ printf("<T='%s'", trig);
+}
+
+static void
+test_tdm_package(const char *awname)
+{
+ printf(" P='%s'", awname);
+}
+
+static void
+test_tdm_end(void)
+{
+ printf(" E>\n");
+}
+
+static const struct trigdefmeths test_tdm = {
+ .trig_begin = test_tdm_begin,
+ .package = test_tdm_package,
+ .trig_end = test_tdm_end,
+};
+
+static int
+test_trigdeferred_parser(const char *admindir)
+{
+ enum trigdef_update_flags tduf;
+ enum trigdef_update_status tdus;
+
+ dpkg_db_set_dir(admindir);
+
+ trigdef_set_methods(&test_tdm);
+
+ tduf = TDUF_NO_LOCK | TDUF_WRITE_IF_EMPTY | TDUF_WRITE_IF_ENOENT;
+ tdus = trigdef_update_start(tduf);
+ if (tdus < TDUS_OK)
+ return -tdus + TDUS_OK;
+
+ trigdef_parse();
+
+ trigdef_process_done();
+
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ const char *admindir = argv[1];
+ int ret;
+
+ setvbuf(stdout, NULL, _IOLBF, 0);
+
+ push_error_context();
+
+ if (admindir == NULL)
+ ohshit("missing triggers deferred admindir");
+
+ ret = test_trigdeferred_parser(admindir);
+
+ pop_error_context(ehflag_normaltidy);
+
+ return ret;
+}
diff --git a/lib/dpkg/t/t-trigdeferred.t b/lib/dpkg/t/t-trigdeferred.t
new file mode 100755
index 0000000..6cded31
--- /dev/null
+++ b/lib/dpkg/t/t-trigdeferred.t
@@ -0,0 +1,123 @@
+#!/usr/bin/perl
+#
+# Copyright © 2016 Guillem Jover <guillem at debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+use version;
+
+use Test::More;
+use Cwd;
+use File::Path qw(make_path remove_tree);
+use File::Temp qw(tempdir);
+use File::Basename;
+use File::Find;
+
+use Dpkg::IPC;
+
+my $srcdir = $ENV{srcdir} || '.';
+my $builddir = $ENV{builddir} || '.';
+my $tmpdir = 't.tmp/t-trigdeferred';
+
+my @deferred = (
+ {
+ exitcode => 0,
+ original => <<'TEXT',
+
+ # Comment
+ # Another Comment
+ /root/pathname/file-trigger pkg-a pkg-b pkg-c
+named-trigger pkg-1 pkg-2 pkg-3
+parse-trigger pkg:a pkg+b pkg.0 0-pkg
+:other-trigger -
+TEXT
+ expected => <<'TEXT',
+<T='/root/pathname/file-trigger' P='pkg-a' P='pkg-b' P='pkg-c' E>
+<T='named-trigger' P='pkg-1' P='pkg-2' P='pkg-3' E>
+<T='parse-trigger' P='pkg:a' P='pkg+b' P='pkg.0' P='0-pkg' E>
+<T=':other-trigger' P='-' E>
+TEXT
+ }, {
+ exitcode => 2,
+ original => <<"TEXT",
+\b # invalid character
+TEXT
+ }, {
+ exitcode => 2,
+ original => <<'TEXT',
+trigger -pkg
+TEXT
+ }, {
+ exitcode => 2,
+ original => <<'TEXT',
+trigger +pkg
+TEXT
+ }, {
+ exitcode => 2,
+ original => <<'TEXT',
+trigger .pkg
+TEXT
+ }, {
+ exitcode => 2,
+ original => <<'TEXT',
+trigger :pkg
+TEXT
+ }, {
+ exitcode => 2,
+ original => 'missing newline',
+ }
+);
+
+plan tests => scalar(@deferred) * 3;
+
+# Set a known umask.
+umask 0022;
+
+sub make_file {
+ my ($pathname, $text) = @_;
+
+ open my $fh, '>', $pathname or die "cannot touch $pathname: $!";
+ print { $fh } $text;
+ close $fh;
+}
+
+sub test_trigdeferred {
+ my $stdout;
+ my $stderr;
+ my $admindir = "$tmpdir";
+
+ # Check triggers deferred file parsing.
+ make_path("$admindir/triggers");
+
+ foreach my $test (@deferred) {
+ make_file("$admindir/triggers/Unincorp", $test->{original});
+
+ spawn(exec => [ './c-trigdeferred', $admindir ],
+ nocheck => 1, to_string => \$stdout, error_to_string => \$stderr);
+ my $exitcode = $? >> 8;
+
+ is($exitcode, $test->{exitcode}, "trigger deferred expected exitcode");
+ if ($test->{exitcode} == 0) {
+ is($stderr, '', "trigger deferred expected stderr");
+ is($stdout, $test->{expected}, "trigger deferred expected stdout");
+ } else {
+ isnt($stderr, '', "trigger deferred expected stderr");
+ isnt($stdout, undef, "trigger deferred expected stdout");
+ }
+ }
+}
+
+test_trigdeferred();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list