From 4dc2e6b7beca34add3feef5c76cf6e3b53c1c736 Mon Sep 17 00:00:00 2001
From: Martin Pitt <martin.pitt@ubuntu.com>
Date: Mon, 17 May 2010 19:30:55 +0200
Subject: [PATCH] Add filtering test cases.

This checks the --path-include and --path-exclude options for package
installation.
---
 t-filtering/Makefile                               |  111 ++++++++++++++++++++
 t-filtering/pkg-somefiles/DEBIAN/control           |    8 ++
 2 files changed, 119 insertions(+), 0 deletions(-)
 create mode 100644 t-filtering/Makefile
 create mode 100644 t-filtering/pkg-somefiles/DEBIAN/control
 create mode 100644 t-filtering/pkg-somefiles/usr/lib/pkg-somefiles/run
 create mode 100644 t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/README
 create mode 100644 t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/copyright
 create mode 100644 t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/html/index.html
 create mode 100644 t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/html/topic1/1.html

diff --git a/t-filtering/Makefile b/t-filtering/Makefile
new file mode 100644
index 0000000..5088781
--- /dev/null
+++ b/t-filtering/Makefile
@@ -0,0 +1,111 @@
+TESTS_DEB := pkg-somefiles
+
+include ../Test.mk
+
+test-case: test-no-filter test-no-doc-sub test-no-doc-all test-no-doc-except-copyright \
+	   test-no-doc-except-copyright-subdir test-no-doc-except-copyright-and-readme \
+	   test-include-only test-same-include-exclude test-upgrade test-help
+
+test-clean:
+	$(DPKG_PURGE) pkg-somefiles
+
+# no filter, should have all files
+test-no-filter:
+	$(DPKG_INSTALL) pkg-somefiles.deb
+	test "`$(DPKG_QUERY) -L pkg-somefiles | wc -l`" = 14
+	$(DPKG_PURGE) pkg-somefiles
+
+# filter out /usr/share/doc/*/*; this keeps the actual
+# /usr/share/doc/pkg-somefiles dir around
+test-no-doc-sub:
+	$(DPKG_INSTALL) --path-exclude '/usr/share/doc/*/*' pkg-somefiles.deb
+	test -d /usr/share/doc/pkg-somefiles
+	test "`ls /usr/share/doc/pkg-somefiles`" = ""
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+
+# filter out /usr/share/doc/*
+test-no-doc-all:
+	$(DPKG_INSTALL) --path-exclude '/usr/share/doc/*' pkg-somefiles.deb
+	! test -d /usr/share/doc/pkg-somefiles
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+
+# filter out /usr/share/doc/*/* except copyright
+test-no-doc-except-copyright:
+	$(DPKG_INSTALL) --path-exclude '/usr/share/doc/*/*' --path-include '/usr/share/doc/*/copyright' pkg-somefiles.deb
+	test -f /usr/share/doc/pkg-somefiles/copyright
+	! test -f /usr/share/doc/pkg-somefiles/html/index.html
+	! test -f /usr/share/doc/pkg-somefiles/README
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+
+# prune the entire doc dir; this triggers the special case that
+# /usr/share/doc/pkg-somefiles is matched by the exclude, but still needs to be
+# created due to the following include
+test-no-doc-except-copyright-subdir:
+	$(DPKG_INSTALL) --path-exclude '/usr/share/doc/*' --path-include '/usr/share/doc/*/copyright' pkg-somefiles.deb
+	test -f /usr/share/doc/pkg-somefiles/copyright
+	! test -f /usr/share/doc/pkg-somefiles/html/index.html
+	! test -f /usr/share/doc/pkg-somefiles/README
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+
+# two includes which revert an exclude, second of which matches several subdirs
+# with one *
+test-no-doc-except-copyright-and-readme:
+	$(DPKG_INSTALL) --path-exclude '/usr/share/doc/*' --path-include '/usr/share/doc/*/copyright' --path-include '/usr*/READ*' pkg-somefiles.deb
+	test -f /usr/share/doc/pkg-somefiles/copyright
+	! test -f /usr/share/doc/pkg-somefiles/html/index.html
+	test -f /usr/share/doc/pkg-somefiles/README
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+
+# only includes, should be a no-op and have all files
+test-include-only:
+	$(DPKG_INSTALL) --path-include '/usr/*' --path-include '/usr/share/doc' --path-include '/usr/lib/*/*' pkg-somefiles.deb
+	test "`$(DPKG_QUERY) -L pkg-somefiles | wc -l`" = 14
+	test -f /usr/share/doc/pkg-somefiles/copyright
+	test -f /usr/share/doc/pkg-somefiles/html/index.html
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+
+# include the same things than exclude, should be a no-op and have all files
+test-same-include-exclude:
+	$(DPKG_INSTALL) --path-exclude '/usr/share/*' --path-include '/usr/share/*' pkg-somefiles.deb
+	test "`$(DPKG_QUERY) -L pkg-somefiles | wc -l`" = 14
+	test -f /usr/share/doc/pkg-somefiles/html/index.html
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+	
+	# now doubly so
+	$(DPKG_INSTALL) --path-exclude '/usr/share/*' --path-include '/usr/share/*' --path-exclude '/usr/share/*' --path-include '/usr/share/*' pkg-somefiles.deb
+	test "`$(DPKG_QUERY) -L pkg-somefiles | wc -l`" = 14
+	test -f /usr/share/doc/pkg-somefiles/html/index.html
+	test -f /usr/lib/pkg-somefiles/run
+	$(DPKG_PURGE) pkg-somefiles
+
+# files are removed/re-added on upgrades
+test-upgrade:
+	$(DPKG_INSTALL) pkg-somefiles.deb
+	test "`$(DPKG_QUERY) -L pkg-somefiles | wc -l`" = 14
+	test -f /usr/share/doc/pkg-somefiles/copyright
+	
+	$(DPKG_INSTALL) --path-exclude '/usr/share/doc/*' pkg-somefiles.deb
+	! test -d /usr/share/doc/pkg-somefiles
+	
+	$(DPKG_INSTALL) --path-exclude '/usr/share/doc/*' --path-include '/usr/share/doc/*/copyright' pkg-somefiles.deb
+	test -f /usr/share/doc/pkg-somefiles/copyright
+	! test -f /usr/share/doc/pkg-somefiles/README
+	
+	$(DPKG_INSTALL) pkg-somefiles.deb
+	test "`$(DPKG_QUERY) -L pkg-somefiles | wc -l`" = 14
+	test -f /usr/share/doc/pkg-somefiles/copyright
+	test -f /usr/share/doc/pkg-somefiles/README
+	$(DPKG_PURGE) pkg-somefiles
+
+
+# --help output explains the options
+test-help:
+	$(DPKG) --help | grep -q -- --path-include
+	$(DPKG) --help | grep -q -- --path-exclude
diff --git a/t-filtering/pkg-somefiles/DEBIAN/control b/t-filtering/pkg-somefiles/DEBIAN/control
new file mode 100644
index 0000000..2b24276
--- /dev/null
+++ b/t-filtering/pkg-somefiles/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: pkg-somefiles
+Version: 0
+Section: test
+Priority: extra
+Maintainer: Guillem Jover <guillem@debian.org>
+Architecture: all
+Description: test package - provide some files
+
diff --git a/t-filtering/pkg-somefiles/usr/lib/pkg-somefiles/run b/t-filtering/pkg-somefiles/usr/lib/pkg-somefiles/run
new file mode 100644
index 0000000..e69de29
diff --git a/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/README b/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/README
new file mode 100644
index 0000000..e69de29
diff --git a/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/copyright b/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/copyright
new file mode 100644
index 0000000..e69de29
diff --git a/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/html/index.html b/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/html/index.html
new file mode 100644
index 0000000..e69de29
diff --git a/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/html/topic1/1.html b/t-filtering/pkg-somefiles/usr/share/doc/pkg-somefiles/html/topic1/1.html
new file mode 100644
index 0000000..e69de29
-- 
1.7.0.4

