summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2020-03-25 07:47:10 +0000
committerrillig <rillig@pkgsrc.org>2020-03-25 07:47:10 +0000
commit310b19180ae01797c24b6b6fffb0144c48b65d9f (patch)
treef2b6c1b74576eb9ee828e42886b84f7321150ba1 /regress
parent7dff94fec0ca91496542455e3321f65012b0779b (diff)
downloadpkgsrc-310b19180ae01797c24b6b6fffb0144c48b65d9f.tar.gz
regress/infra-unittests: add test for not extracting certain files
Diffstat (limited to 'regress')
-rw-r--r--regress/infra-unittests/extract.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/regress/infra-unittests/extract.sh b/regress/infra-unittests/extract.sh
new file mode 100644
index 00000000000..8e7c3563fd8
--- /dev/null
+++ b/regress/infra-unittests/extract.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+#
+# Tests for mk/subst.mk.
+#
+set -eu
+
+. "./test.subr"
+
+# XXX: The mocked pkgsrc directory should be somewhere else.
+rm -r "$tmpdir/pkgsrc"
+
+# XXX: This definition should be available everywhere.
+pkgsrcdir="`cd "$real_pkgsrcdir" && exec pwd`"
+
+if test_case_begin "exclude directory"; then
+
+ # Demonstrates that excluding a directory name also excludes that
+ # directory further down in the hierarchy.
+ #
+ # For example, with BSD tar and GNU tar it is not possible to exclude
+ # only the top-level "contrib" directory but still extract other
+ # contrib directories.
+ #
+ # Experienced in lang/gcc*, which has contrib/ and java-lib/contrib/.
+
+ cd "$tmpdir"
+ mkdir "contrib"
+ echo "file" > "contrib/file"
+ mkdir "other"
+ echo "file" > "other/file"
+ mkdir "other/contrib"
+ echo "file" > "other/contrib/file"
+
+ tar cf "archive.tar" "contrib" "other"
+ rm -r "contrib" "other"
+
+ sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib"
+
+ find . -print | LC_ALL=C sort > "extracted"
+
+ assert_that "extracted" --file-is-lines \
+ "." \
+ "./archive.tar" \
+ "./extracted" \
+ "./other" \
+ "./other/file"
+
+ test_case_end
+fi