pkgsrc-Changes archive

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

CVS commit: pkgsrc/regress/infra-unittests



Module Name:    pkgsrc
Committed By:   rillig
Date:           Fri Mar 27 21:41:33 UTC 2020

Modified Files:
        pkgsrc/regress/infra-unittests: extract.sh test.subr

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 pkgsrc/regress/infra-unittests/extract.sh
cvs rdiff -u -r1.7 -r1.8 pkgsrc/regress/infra-unittests/test.subr

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/regress/infra-unittests/extract.sh
diff -u pkgsrc/regress/infra-unittests/extract.sh:1.1 pkgsrc/regress/infra-unittests/extract.sh:1.2
--- pkgsrc/regress/infra-unittests/extract.sh:1.1       Wed Mar 25 07:47:10 2020
+++ pkgsrc/regress/infra-unittests/extract.sh   Fri Mar 27 21:41:33 2020
@@ -6,13 +6,20 @@ set -eu
 
 . "./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,27 +30,81 @@ if test_case_begin "exclude directory"; 
        #
        # 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 \
+               "." \
+               "./archive.tar" \
+               "./extracted" \
+               "./other" \
+               "./other/file"
+
+       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.

Index: pkgsrc/regress/infra-unittests/test.subr
diff -u pkgsrc/regress/infra-unittests/test.subr:1.7 pkgsrc/regress/infra-unittests/test.subr:1.8
--- pkgsrc/regress/infra-unittests/test.subr:1.7        Sun Mar 22 12:15:59 2020
+++ pkgsrc/regress/infra-unittests/test.subr    Fri Mar 27 21:41:33 2020
@@ -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 @@ EOF
 
 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