pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/regress/infra-unittests regress/infra-unittests: add m...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0d98aeffa662
branches:  trunk
changeset: 414469:0d98aeffa662
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Mar 27 21:41:33 2020 +0000

description:
regress/infra-unittests: add more tests for mk/extract/extract

These tests demonstrate that it is not easy to exclude only one top-level
directory from being extracted, using the example of lang/gcc*, which has
a top-level directory contrib/ that contains shell programs with
non-portable code, but the same archive also contains libjava/contrib, and
that should still be extracted.

diffstat:

 regress/infra-unittests/extract.sh |  83 ++++++++++++++++++++++++++++++++-----
 regress/infra-unittests/test.subr  |   6 +-
 2 files changed, 76 insertions(+), 13 deletions(-)

diffs (144 lines):

diff -r 84e4e4415cd6 -r 0d98aeffa662 regress/infra-unittests/extract.sh
--- a/regress/infra-unittests/extract.sh        Fri Mar 27 20:58:12 2020 +0000
+++ b/regress/infra-unittests/extract.sh        Fri Mar 27 21:41:33 2020 +0000
@@ -6,13 +6,20 @@
 
 . "./test.subr"
 
-# XXX: The mocked pkgsrc directory should be somewhere else.
-rm -r "$tmpdir/pkgsrc"
+test_case_set_up() {
+       # XXX: The mocked pkgsrc directory should be somewhere else.
+       rm -rf "$tmpdir/pkgsrc" "$tmpdir/expected"
+
+       cd "$tmpdir"
+
+       LC_ALL=C
+       export LC_ALL
+}
 
 # XXX: This definition should be available everywhere.
 pkgsrcdir="`cd "$real_pkgsrcdir" && exec pwd`"
 
-if test_case_begin "exclude directory"; then
+if test_case_begin "exclude directory by basename"; then
 
        # Demonstrates that excluding a directory name also excludes that
        # directory further down in the hierarchy.
@@ -23,20 +30,16 @@
        #
        # 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"
+       create_file_lines "contrib/file"        "content"
+       create_file_lines "other/file"          "content"
+       create_file_lines "other/contrib/file"  "content"
 
        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"
+       find . -print | sort > "extracted"
 
        assert_that "extracted" --file-is-lines \
                "." \
@@ -47,3 +50,61 @@
 
        test_case_end
 fi
+
+if test_case_begin "try to exclude directory by pattern with slash"; then
+
+       # Having exclusion patterns with slash does not work at all for
+       # the default tar extractor. The patterns are matched against
+       # the basename of the file to be extracted, and that basename
+       # obviously cannot contain a slash.
+
+       create_file_lines "contrib/file"        "content"
+       create_file_lines "other/file"          "content"
+       create_file_lines "other/contrib/file"  "content"
+
+       tar cf "archive.tar" "contrib" "other"
+       rm -r "contrib" "other"
+
+       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib/*"
+
+       find . -print | sort > "extracted"
+
+       assert_that "extracted" --file-is-lines \
+               "." \
+               "./archive.tar" \
+               "./contrib" \
+               "./extracted" \
+               "./other" \
+               "./other/contrib" \
+               "./other/file"
+
+       test_case_end
+fi
+
+if test_case_begin "exclude asterisk"; then
+
+       # Ensure that the exclusion pattern "*" is not expanded by the
+       # shell but passed as-is to the extractor.
+
+       create_file_lines "contrib/file"        "content"
+       create_file_lines "other/file"          "content"
+       create_file_lines "other/contrib/file"  "content"
+
+       tar cf "archive.tar" "contrib" "other"
+       rm -r "contrib" "other"
+
+       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "*"
+
+       find . -print | sort > "extracted"
+
+       assert_that "extracted" --file-is-lines \
+               "." \
+               "./archive.tar" \
+               "./extracted"
+
+       test_case_end
+fi
+
+# TODO: test -x on an archiver that doesn't support it.
+
+# TODO: add test for extracting only a few files.
diff -r 84e4e4415cd6 -r 0d98aeffa662 regress/infra-unittests/test.subr
--- a/regress/infra-unittests/test.subr Fri Mar 27 20:58:12 2020 +0000
+++ b/regress/infra-unittests/test.subr Fri Mar 27 21:41:33 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: test.subr,v 1.7 2020/03/22 12:15:59 rillig Exp $
+# $NetBSD: test.subr,v 1.8 2020/03/27 21:41:33 rillig Exp $
 set -eu
 
 # This file defines utilities for testing Makefile fragments in a mocked
@@ -162,16 +162,18 @@
 
 create_file() {
        assert_that "$#" --equals 1
+       mkdir -p "$(dirname "$tmpdir/$1")"
        cat > "$tmpdir/$1"
 }
 
 create_file_lines() {
+       mkdir -p "$(dirname "$tmpdir/$1")"
        _cfl_filename="$1"; shift
        printf '%s\n' "$@" > "$tmpdir/$_cfl_filename"
 }
 
 create_pkgsrc_file() {
-       mkdir -p "$mocked_pkgsrcdir/$(dirname "$1")"
+       mkdir -p "$(dirname "$mocked_pkgsrcdir/$1")"
        cat > "$mocked_pkgsrcdir/$1"
 }
 



Home | Main Index | Thread Index | Old Index