summaryrefslogtreecommitdiffstats
path: root/tests/t-triggers
diff options
context:
space:
mode:
Diffstat (limited to 'tests/t-triggers')
-rw-r--r--tests/t-triggers/Makefile365
-rw-r--r--tests/t-triggers/pkg-trig-cmd/DEBIAN/control8
-rwxr-xr-xtests/t-triggers/pkg-trig-cmd/DEBIAN/postinst17
-rwxr-xr-xtests/t-triggers/pkg-trig-cmd/DEBIAN/postrm17
-rwxr-xr-xtests/t-triggers/pkg-trig-cmd/DEBIAN/preinst17
-rwxr-xr-xtests/t-triggers/pkg-trig-cmd/DEBIAN/prerm17
-rw-r--r--tests/t-triggers/pkg-trig-explicit/DEBIAN/control8
-rw-r--r--tests/t-triggers/pkg-trig-explicit/DEBIAN/triggers1
-rw-r--r--tests/t-triggers/pkg-trig-file/DEBIAN/control8
-rw-r--r--tests/t-triggers/pkg-trig-file/triggers/a-file1
-rw-r--r--tests/t-triggers/pkg-triggers-await/DEBIAN/control7
-rwxr-xr-xtests/t-triggers/pkg-triggers-await/DEBIAN/postinst13
-rw-r--r--tests/t-triggers/pkg-triggers-await/DEBIAN/triggers2
-rw-r--r--tests/t-triggers/pkg-triggers-noawait/DEBIAN/control8
-rwxr-xr-xtests/t-triggers/pkg-triggers-noawait/DEBIAN/postinst13
-rw-r--r--tests/t-triggers/pkg-triggers-noawait/DEBIAN/triggers2
-rw-r--r--tests/t-triggers/pkg-triggers/DEBIAN/control8
-rwxr-xr-xtests/t-triggers/pkg-triggers/DEBIAN/postinst13
-rw-r--r--tests/t-triggers/pkg-triggers/DEBIAN/triggers2
19 files changed, 527 insertions, 0 deletions
diff --git a/tests/t-triggers/Makefile b/tests/t-triggers/Makefile
new file mode 100644
index 0000000..48cd8b6
--- /dev/null
+++ b/tests/t-triggers/Makefile
@@ -0,0 +1,365 @@
+TESTS_DEB := pkg-triggers pkg-triggers-await pkg-triggers-noawait \
+ pkg-trig-file pkg-trig-explicit pkg-trig-cmd
+
+include ../Test.mk
+
+TEST_CASES += test-trigger-file
+TEST_CASES += test-trigger-explicit
+TEST_CASES += test-trigger-cmd
+TEST_CASES += test-trigger-await-file
+TEST_CASES += test-trigger-await-cmd
+TEST_CASES += test-trigger-noawait-file
+TEST_CASES += test-trigger-noawait-explicit
+TEST_CASES += test-trigger-noawait-cmd
+TEST_CASES += test-internal-db
+
+test-case: $(TEST_CASES)
+
+test-trigger-file test-trigger-await-file:
+ if [ "$@" = "test-trigger-file" ]; then \
+ $(DPKG_UNPACK) pkg-triggers.deb; \
+ else \
+ $(DPKG_UNPACK) pkg-triggers-await.deb; \
+ fi
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok" "$(DPKG_INSTDIR)/triggers/ok"
+ # When unpacked, triggers are not active
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_is_installed,pkg-trig-file)
+ $(call pkg_status_is,pkg-triggers,install ok unpacked)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending,)
+ ! test -f "$(DPKG_INSTDIR)/triggers/ok"
+ $(DPKG_CONFIGURE) --no-triggers pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ ! test -f "$(DPKG_INSTDIR)/triggers/ok"
+ # When installed, triggers can be activated
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending, /triggers)
+ $(call pkg_status_is,pkg-trig-file,install ok triggers-awaited)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ $(call pkg_is_installed,pkg-trig-file)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Try other ways to run the triggers
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-file,install ok triggers-awaited)
+ $(BEROOT) $(DPKG) --triggers-only --pending
+ $(call pkg_is_installed,pkg-trig-file)
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Again
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-file,install ok triggers-awaited)
+ $(DPKG_CONFIGURE) --pending
+ $(call pkg_is_installed,pkg-trig-file)
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Again, but we're unpacking instead of installing
+ $(DPKG_UNPACK) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-file,install ok unpacked)
+ $(DPKG_CONFIGURE) pkg-trig-file
+ # FIXME: Remove ifdef during dpkg 1.18.x cycle, after the apt
+ # workaround has been reverted.
+ifdef DPKG_HAS_CONFIGURE_WITH_IMPLICIT_TRIGGER_PENDING
+ $(call pkg_status_is,pkg-trig-file,install ok triggers-awaited)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+endif
+ $(call pkg_is_installed,pkg-trig-file)
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Cleanup
+ $(DPKG_PURGE) pkg-triggers
+ $(DPKG_PURGE) pkg-trig-file
+
+test-trigger-noawait-file:
+ $(DPKG_UNPACK) pkg-triggers-noawait.deb
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok" "$(DPKG_INSTDIR)/triggers/ok"
+ # When unpacked, triggers are not active
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_is_installed,pkg-trig-file)
+ $(call pkg_status_is,pkg-triggers,install ok unpacked)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending,)
+ ! test -f "$(DPKG_INSTDIR)/triggers/ok"
+ $(DPKG_CONFIGURE) --no-triggers pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ ! test -f "$(DPKG_INSTDIR)/triggers/ok"
+ # When installed, triggers can be activated
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending, /triggers)
+ $(call pkg_is_installed,pkg-trig-file)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Try other ways to run the triggers
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_is_installed,pkg-trig-file)
+ $(BEROOT) $(DPKG) --triggers-only --pending
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Again
+ $(DPKG_INSTALL) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_is_installed,pkg-trig-file)
+ $(DPKG_CONFIGURE) --pending
+ $(call pkg_is_installed,pkg-trig-file)
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Again, but we're unpacking instead of installing
+ $(DPKG_UNPACK) --no-triggers pkg-trig-file.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-file,install ok unpacked)
+ $(DPKG_CONFIGURE) --no-triggers pkg-trig-file
+ $(call pkg_is_installed,pkg-trig-file)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/triggers/ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/triggers/ok"
+ # Cleanup
+ $(DPKG_PURGE) pkg-triggers
+ $(DPKG_PURGE) pkg-trig-file
+
+test-trigger-explicit:
+ $(DPKG_UNPACK) pkg-triggers.deb
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok" "$(DPKG_INSTDIR)/triggers/ok"
+ # When unpacked, triggers are not active
+ $(DPKG_INSTALL) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(call pkg_status_is,pkg-triggers,install ok unpacked)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending,)
+ ! test -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(DPKG_CONFIGURE) --no-triggers pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ ! test -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # When installed, triggers can be activated
+ $(DPKG_INSTALL) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending, a-trigger)
+ $(call pkg_status_is,pkg-trig-explicit,install ok triggers-awaited)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ $(call pkg_is_installed,pkg-trig-explicit)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # Try other ways to run the triggers
+ $(DPKG_INSTALL) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-explicit,install ok triggers-awaited)
+ $(BEROOT) $(DPKG) --triggers-only --pending
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # Again
+ $(DPKG_INSTALL) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-explicit,install ok triggers-awaited)
+ $(DPKG_CONFIGURE) --pending
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # Again, but we're unpacking instead of installing
+ $(DPKG_UNPACK) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-explicit,install ok unpacked)
+ $(DPKG_CONFIGURE) pkg-trig-explicit
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # Verify the trigger is activated on each status change
+ $(DPKG_UNPACK) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-explicit,install ok unpacked)
+ $(call pkg_field_is,pkg-trig-explicit,Triggers-Awaited, pkg-triggers)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ $(call pkg_field_is,pkg-trig-explicit,Triggers-Awaited,)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(DPKG_CONFIGURE) --no-triggers pkg-trig-explicit
+ $(call pkg_status_is,pkg-trig-explicit,install ok triggers-awaited)
+ $(call pkg_field_is,pkg-trig-explicit,Triggers-Awaited, pkg-triggers)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(call pkg_is_installed,pkg-triggers)
+ # Cleanup
+ $(DPKG_PURGE) pkg-triggers
+ $(DPKG_PURGE) pkg-trig-explicit
+
+test-trigger-noawait-explicit:
+ $(DPKG_INSTALL) pkg-triggers-noawait.deb
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok" "$(DPKG_INSTDIR)/triggers/ok"
+ # When installed, triggers can be activated
+ $(DPKG_INSTALL) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending, a-trigger)
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # Again, but we're unpacking instead of installing
+ $(DPKG_UNPACK) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-explicit,install ok unpacked)
+ $(call pkg_field_is,pkg-trig-explicit,Triggers-Awaited,)
+ $(DPKG_CONFIGURE) --no-triggers pkg-trig-explicit
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(DPKG_CONFIGURE) --pending
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # Verify the trigger is activated on each status change
+ $(DPKG_UNPACK) --no-triggers pkg-trig-explicit.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-explicit,install ok unpacked)
+ $(call pkg_field_is,pkg-trig-explicit,Triggers-Awaited,)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(DPKG_CONFIGURE) --no-triggers pkg-trig-explicit
+ $(call pkg_is_installed,pkg-trig-explicit)
+ $(call pkg_field_is,pkg-trig-explicit,Triggers-Awaited,)
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ # Cleanup
+ $(DPKG_PURGE) pkg-triggers
+ $(DPKG_PURGE) pkg-trig-explicit
+
+test-trigger-cmd test-trigger-await-cmd:
+ if [ "$@" = "test-trigger-await-cmd" ]; then \
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-await"; \
+ fi
+ $(DPKG_UNPACK) pkg-triggers.deb
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok" "$(DPKG_INSTDIR)/triggers/ok"
+ # When unpacked, triggers are not active
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-postinst" "$(DPKG_INSTDIR)/trigger-preinst" "$(DPKG_INSTDIR)/trigger-postrm" "$(DPKG_INSTDIR)/trigger-prerm"
+ $(DPKG_INSTALL) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_is_installed,pkg-trig-cmd)
+ $(call pkg_status_is,pkg-triggers,install ok unpacked)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending,)
+ ! test -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(DPKG_CONFIGURE) --no-triggers pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ ! test -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # When installed, triggers can be activated
+ $(DPKG_INSTALL) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending, a-trigger)
+ $(call pkg_status_is,pkg-trig-cmd,install ok triggers-awaited)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ $(call pkg_is_installed,pkg-trig-cmd)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-postinst" "$(DPKG_INSTDIR)/trigger-preinst" "$(DPKG_INSTDIR)/trigger-postrm" "$(DPKG_INSTDIR)/trigger-prerm"
+ # Call dpkg-trigger in the preinst
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-preinst"
+ $(DPKG_UNPACK) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-cmd,install ok unpacked)
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited, pkg-triggers)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited,)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-preinst"
+ # Call dpkg-trigger in the postinst
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-postinst"
+ $(DPKG_CONFIGURE) --no-triggers pkg-trig-cmd
+ $(call pkg_status_is,pkg-trig-cmd,install ok triggers-awaited)
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ $(call pkg_is_installed,pkg-trig-cmd)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-postinst"
+ # Call dpkg-trigger in the prerm
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-prerm"
+ $(DPKG_UNPACK) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-cmd,install ok unpacked)
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited, pkg-triggers)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited,)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-prerm"
+ # Call dpkg-trigger in the postrm
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-postrm"
+ $(DPKG_UNPACK) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-cmd,install ok unpacked)
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited, pkg-triggers)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited,)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-postrm"
+ # Cleanup
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-await"
+ $(DPKG_PURGE) pkg-triggers
+ $(DPKG_PURGE) pkg-trig-cmd
+
+test-trigger-noawait-cmd:
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-noawait"
+ $(DPKG_UNPACK) pkg-triggers.deb
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok" "$(DPKG_INSTDIR)/triggers/ok"
+ # When unpacked, triggers are not active
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-postinst" "$(DPKG_INSTDIR)/trigger-preinst" "$(DPKG_INSTDIR)/trigger-postrm" "$(DPKG_INSTDIR)/trigger-prerm"
+ $(DPKG_INSTALL) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_is_installed,pkg-trig-cmd)
+ $(call pkg_status_is,pkg-triggers,install ok unpacked)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending,)
+ ! test -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(DPKG_CONFIGURE) --no-triggers pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ ! test -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ # When installed, triggers can be activated
+ $(DPKG_INSTALL) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_field_is,pkg-triggers,Triggers-Pending, a-trigger)
+ $(call pkg_is_installed,pkg-trig-cmd)
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited,)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-postinst" "$(DPKG_INSTDIR)/trigger-preinst" "$(DPKG_INSTDIR)/trigger-postrm" "$(DPKG_INSTDIR)/trigger-prerm"
+ # Call dpkg-trigger in the preinst
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-preinst"
+ $(DPKG_UNPACK) --no-triggers pkg-trig-cmd.deb
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(call pkg_status_is,pkg-trig-cmd,install ok unpacked)
+ $(call pkg_field_is,pkg-trig-cmd,Triggers-Awaited,)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-preinst"
+ # Call dpkg-trigger in the postinst
+ $(BEROOT) touch "$(DPKG_INSTDIR)/trigger-postinst"
+ $(DPKG_CONFIGURE) --no-triggers pkg-trig-cmd
+ $(call pkg_is_installed,pkg-trig-cmd)
+ $(call pkg_status_is,pkg-triggers,install ok triggers-pending)
+ $(BEROOT) $(DPKG) --triggers-only pkg-triggers
+ $(call pkg_is_installed,pkg-triggers)
+ test -f "$(DPKG_INSTDIR)/a-trigger-ok" && $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-postinst"
+ # Cleanup
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-noawait"
+ $(DPKG_PURGE) pkg-triggers
+ $(DPKG_PURGE) pkg-trig-cmd
+
+test-internal-db:
+ # test that installing triggers creates the corresponding files
+ $(DPKG_INSTALL) pkg-triggers.deb
+ $(call stdout_is,cat "$(DPKG_ADMINDIR)/triggers/a-trigger",pkg-triggers)
+ grep -q "^/triggers pkg-triggers$$" "$(DPKG_ADMINDIR)/triggers/File"
+ $(DPKG_INSTALL) pkg-triggers-noawait.deb
+ $(call stdout_is,cat "$(DPKG_ADMINDIR)/triggers/a-trigger",pkg-triggers/noawait)
+ grep -q "^/triggers pkg-triggers/noawait$$" "$(DPKG_ADMINDIR)/triggers/File"
+ # Test that removal cleans up the triggers files
+ $(DPKG_PURGE) pkg-triggers
+ ! test -e "$(DPKG_ADMINDIR)/triggers/a-trigger"
+ ! test -e "$(DPKG_ADMINDIR)/triggers/File"
+
+test-clean:
+ $(DPKG_PURGE) pkg-triggers pkg-trig-file pkg-trig-explicit pkg-trig-cmd
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/a-trigger-ok" "$(DPKG_INSTDIR)/triggers/ok"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-postinst" "$(DPKG_INSTDIR)/trigger-preinst" "$(DPKG_INSTDIR)/trigger-postrm" "$(DPKG_INSTDIR)/trigger-prerm"
+ $(BEROOT) rm -f "$(DPKG_INSTDIR)/trigger-noawait"
+
diff --git a/tests/t-triggers/pkg-trig-cmd/DEBIAN/control b/tests/t-triggers/pkg-trig-cmd/DEBIAN/control
new file mode 100644
index 0000000..196c8a8
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-cmd/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: pkg-trig-cmd
+Version: 0.0-1
+Section: test
+Priority: extra
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Architecture: all
+Description: test package - running dpkg-trigger in maintainer scripts
+
diff --git a/tests/t-triggers/pkg-trig-cmd/DEBIAN/postinst b/tests/t-triggers/pkg-trig-cmd/DEBIAN/postinst
new file mode 100755
index 0000000..3975be0
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-cmd/DEBIAN/postinst
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -e
+
+if [ -e "$DPKG_ROOT/trigger-$DPKG_MAINTSCRIPT_NAME" ]; then
+ if [ -e "$DPKG_ROOT/trigger-noawait" ]; then
+ echo "Executing 'dpkg-trigger --no-await a-trigger' from '$0 $1'"
+ dpkg-trigger --no-await a-trigger
+ elif [ -e "$DPKG_ROOT/trigger-await" ]; then
+ echo "Executing 'dpkg-trigger --await a-trigger' from '$0 $1'"
+ dpkg-trigger --await a-trigger
+ else
+ echo "Executing 'dpkg-trigger a-trigger' from '$0 $1'"
+ dpkg-trigger a-trigger
+ fi
+fi
+
diff --git a/tests/t-triggers/pkg-trig-cmd/DEBIAN/postrm b/tests/t-triggers/pkg-trig-cmd/DEBIAN/postrm
new file mode 100755
index 0000000..3975be0
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-cmd/DEBIAN/postrm
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -e
+
+if [ -e "$DPKG_ROOT/trigger-$DPKG_MAINTSCRIPT_NAME" ]; then
+ if [ -e "$DPKG_ROOT/trigger-noawait" ]; then
+ echo "Executing 'dpkg-trigger --no-await a-trigger' from '$0 $1'"
+ dpkg-trigger --no-await a-trigger
+ elif [ -e "$DPKG_ROOT/trigger-await" ]; then
+ echo "Executing 'dpkg-trigger --await a-trigger' from '$0 $1'"
+ dpkg-trigger --await a-trigger
+ else
+ echo "Executing 'dpkg-trigger a-trigger' from '$0 $1'"
+ dpkg-trigger a-trigger
+ fi
+fi
+
diff --git a/tests/t-triggers/pkg-trig-cmd/DEBIAN/preinst b/tests/t-triggers/pkg-trig-cmd/DEBIAN/preinst
new file mode 100755
index 0000000..3975be0
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-cmd/DEBIAN/preinst
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -e
+
+if [ -e "$DPKG_ROOT/trigger-$DPKG_MAINTSCRIPT_NAME" ]; then
+ if [ -e "$DPKG_ROOT/trigger-noawait" ]; then
+ echo "Executing 'dpkg-trigger --no-await a-trigger' from '$0 $1'"
+ dpkg-trigger --no-await a-trigger
+ elif [ -e "$DPKG_ROOT/trigger-await" ]; then
+ echo "Executing 'dpkg-trigger --await a-trigger' from '$0 $1'"
+ dpkg-trigger --await a-trigger
+ else
+ echo "Executing 'dpkg-trigger a-trigger' from '$0 $1'"
+ dpkg-trigger a-trigger
+ fi
+fi
+
diff --git a/tests/t-triggers/pkg-trig-cmd/DEBIAN/prerm b/tests/t-triggers/pkg-trig-cmd/DEBIAN/prerm
new file mode 100755
index 0000000..3975be0
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-cmd/DEBIAN/prerm
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -e
+
+if [ -e "$DPKG_ROOT/trigger-$DPKG_MAINTSCRIPT_NAME" ]; then
+ if [ -e "$DPKG_ROOT/trigger-noawait" ]; then
+ echo "Executing 'dpkg-trigger --no-await a-trigger' from '$0 $1'"
+ dpkg-trigger --no-await a-trigger
+ elif [ -e "$DPKG_ROOT/trigger-await" ]; then
+ echo "Executing 'dpkg-trigger --await a-trigger' from '$0 $1'"
+ dpkg-trigger --await a-trigger
+ else
+ echo "Executing 'dpkg-trigger a-trigger' from '$0 $1'"
+ dpkg-trigger a-trigger
+ fi
+fi
+
diff --git a/tests/t-triggers/pkg-trig-explicit/DEBIAN/control b/tests/t-triggers/pkg-trig-explicit/DEBIAN/control
new file mode 100644
index 0000000..8fdfeca
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-explicit/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: pkg-trig-explicit
+Version: 0.0-1
+Section: test
+Priority: extra
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Architecture: all
+Description: test package - activate trigger "a-trigger"
+
diff --git a/tests/t-triggers/pkg-trig-explicit/DEBIAN/triggers b/tests/t-triggers/pkg-trig-explicit/DEBIAN/triggers
new file mode 100644
index 0000000..cc71459
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-explicit/DEBIAN/triggers
@@ -0,0 +1 @@
+activate a-trigger
diff --git a/tests/t-triggers/pkg-trig-file/DEBIAN/control b/tests/t-triggers/pkg-trig-file/DEBIAN/control
new file mode 100644
index 0000000..ef3663a
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-file/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: pkg-trig-file
+Version: 0.0-1
+Section: test
+Priority: extra
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Architecture: all
+Description: test package - install a file in /triggers
+
diff --git a/tests/t-triggers/pkg-trig-file/triggers/a-file b/tests/t-triggers/pkg-trig-file/triggers/a-file
new file mode 100644
index 0000000..4dd1ef7
--- /dev/null
+++ b/tests/t-triggers/pkg-trig-file/triggers/a-file
@@ -0,0 +1 @@
+This is a file.
diff --git a/tests/t-triggers/pkg-triggers-await/DEBIAN/control b/tests/t-triggers/pkg-triggers-await/DEBIAN/control
new file mode 100644
index 0000000..dc27453
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers-await/DEBIAN/control
@@ -0,0 +1,7 @@
+Package: pkg-triggers
+Version: 0.0-1
+Section: test
+Priority: extra
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Architecture: all
+Description: test package - providing triggers
diff --git a/tests/t-triggers/pkg-triggers-await/DEBIAN/postinst b/tests/t-triggers/pkg-triggers-await/DEBIAN/postinst
new file mode 100755
index 0000000..5269ac4
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers-await/DEBIAN/postinst
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ "$1" = "triggered" ]; then
+ case " $2 " in
+ *" a-trigger "*)
+ touch "$DPKG_ROOT/a-trigger-ok"
+ ;;
+ *" /triggers "*)
+ touch "$DPKG_ROOT/triggers/ok"
+ ;;
+ esac
+fi
+
diff --git a/tests/t-triggers/pkg-triggers-await/DEBIAN/triggers b/tests/t-triggers/pkg-triggers-await/DEBIAN/triggers
new file mode 100644
index 0000000..9ce7f67
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers-await/DEBIAN/triggers
@@ -0,0 +1,2 @@
+interest-await a-trigger
+interest-await /triggers
diff --git a/tests/t-triggers/pkg-triggers-noawait/DEBIAN/control b/tests/t-triggers/pkg-triggers-noawait/DEBIAN/control
new file mode 100644
index 0000000..ff9d5d5
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers-noawait/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: pkg-triggers
+Version: 0.0-1
+Section: test
+Priority: extra
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Architecture: all
+Description: test package - providing triggers
+
diff --git a/tests/t-triggers/pkg-triggers-noawait/DEBIAN/postinst b/tests/t-triggers/pkg-triggers-noawait/DEBIAN/postinst
new file mode 100755
index 0000000..5269ac4
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers-noawait/DEBIAN/postinst
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ "$1" = "triggered" ]; then
+ case " $2 " in
+ *" a-trigger "*)
+ touch "$DPKG_ROOT/a-trigger-ok"
+ ;;
+ *" /triggers "*)
+ touch "$DPKG_ROOT/triggers/ok"
+ ;;
+ esac
+fi
+
diff --git a/tests/t-triggers/pkg-triggers-noawait/DEBIAN/triggers b/tests/t-triggers/pkg-triggers-noawait/DEBIAN/triggers
new file mode 100644
index 0000000..13d2512
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers-noawait/DEBIAN/triggers
@@ -0,0 +1,2 @@
+interest-noawait a-trigger
+interest-noawait /triggers
diff --git a/tests/t-triggers/pkg-triggers/DEBIAN/control b/tests/t-triggers/pkg-triggers/DEBIAN/control
new file mode 100644
index 0000000..ff9d5d5
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: pkg-triggers
+Version: 0.0-1
+Section: test
+Priority: extra
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Architecture: all
+Description: test package - providing triggers
+
diff --git a/tests/t-triggers/pkg-triggers/DEBIAN/postinst b/tests/t-triggers/pkg-triggers/DEBIAN/postinst
new file mode 100755
index 0000000..5269ac4
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers/DEBIAN/postinst
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ "$1" = "triggered" ]; then
+ case " $2 " in
+ *" a-trigger "*)
+ touch "$DPKG_ROOT/a-trigger-ok"
+ ;;
+ *" /triggers "*)
+ touch "$DPKG_ROOT/triggers/ok"
+ ;;
+ esac
+fi
+
diff --git a/tests/t-triggers/pkg-triggers/DEBIAN/triggers b/tests/t-triggers/pkg-triggers/DEBIAN/triggers
new file mode 100644
index 0000000..daa582c
--- /dev/null
+++ b/tests/t-triggers/pkg-triggers/DEBIAN/triggers
@@ -0,0 +1,2 @@
+interest a-trigger
+interest /triggers