Source-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: run t...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/2ada057b23a9
branches:  trunk
changeset: 431302:2ada057b23a9
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Mon May 11 19:13:10 2020 +0000

description:
regress/infra-unittests: run tests in a temporary directory

This isolates the tests from the test infrastructure and allows the test
infrastructure to create arbitrary files for its own purpose without
affecting any of the tests.

diffstat:

 regress/infra-unittests/check-portability.sh |   62 +++----
 regress/infra-unittests/extract.sh           |   49 ++---
 regress/infra-unittests/subst.sh             |  214 +++++++++++++-------------
 regress/infra-unittests/test.subr            |   60 ++++---
 4 files changed, 190 insertions(+), 195 deletions(-)

diffs (truncated from 1071 to 300 lines):

diff -r 116c16c81b7a -r 2ada057b23a9 regress/infra-unittests/check-portability.sh
--- a/regress/infra-unittests/check-portability.sh      Mon May 11 19:08:59 2020 +0000
+++ b/regress/infra-unittests/check-portability.sh      Mon May 11 19:13:10 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: check-portability.sh,v 1.4 2020/05/05 06:11:29 rillig Exp $
+# $NetBSD: check-portability.sh,v 1.5 2020/05/11 19:13:10 rillig Exp $
 #
 # Test cases for mk/check/check-portability.*.
 #
@@ -29,21 +29,10 @@
        && exitcode=0 || exitcode=$?
 }
 
-test_case_set_up() {
-       rm -rf "$tmpdir/work"
-       mkdir "$tmpdir/work"
-       cd "$tmpdir/work"
-}
-
-# TODO: remove the "work/" from the tests.
-# The $tmpdir must be a bit structured:
-# $tmpdir/pkgsrc       these files override the actual pkgsrc files
-# $tmpdir/work         current working directory
-
 
 if test_case_begin "test ... = ..."; then
 
-       create_file_lines 'work/file' \
+       create_file_lines 'file' \
                'if [ "$var" = value ]; then' \
                '  ...' \
                'elif test "$var" = value ]; then' \
@@ -52,7 +41,7 @@
 
        check_portability_awk 'file'
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -61,7 +50,7 @@
 
 if test_case_begin 'test ... == ...'; then
 
-       create_file_lines 'work/file' \
+       create_file_lines 'file' \
                'if [ "$var" == value ]; then' \
                '  ...' \
                'elif test "$var" == value ]; then' \
@@ -93,7 +82,7 @@
 ===========================================================================
 
 EOF
-       assert_that 'out' --file-equals 'expected'
+       assert_that "$tmpdir/out" --file-equals 'expected'
        assert_that $exitcode --equals 1
 
        test_case_end
@@ -102,18 +91,18 @@
 
 if test_case_begin 'configure patched, configure.in bad'; then
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ configure 2020-05-04'
-       create_file_lines 'work/configure' \
+       create_file_lines 'configure' \
                '#! /bin/sh' \
                'good'
-       create_file_lines 'work/configure.in' \
+       create_file_lines 'configure.in' \
                'test a == b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that "out" --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -125,17 +114,17 @@
        # As of 2020-05-05, Makefile.am is not checked at all since only
        # very few packages actually use that file during the build.
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ Makefile.in 2020-05-05'
-       create_file_lines 'work/Makefile.in' \
+       create_file_lines 'Makefile.in' \
                'test a = b'
-       create_file_lines 'work/Makefile.am' \
+       create_file_lines 'Makefile.am' \
                'test a == b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that "out" --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -148,15 +137,15 @@
        # developers and are not used during the actual build, except
        # if the package rebuilds everything using the GNU autotools.
 
-       create_file_lines 'work/configure.ac' \
+       create_file_lines 'configure.ac' \
                'test a == b'
-       create_file_lines 'work/Makefile.am' \
+       create_file_lines 'Makefile.am' \
                'test a == b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that "out" --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -165,9 +154,9 @@
 
 if test_case_begin 'configure patched and still bad'; then
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ configure 2020-05-04'
-       create_file_lines 'work/configure' \
+       create_file_lines 'configure' \
                '#! /bin/sh' \
                'test a == b'
 
@@ -196,7 +185,7 @@
 ===========================================================================
 
 EOF
-       assert_that 'out' --file-equals 'expected'
+       assert_that "$tmpdir/out" --file-equals 'expected'
        assert_that $exitcode --equals 1
 
        test_case_end
@@ -208,16 +197,16 @@
        # Ensure that the filename matching for patched files
        # does not treat special characters as shell metacharacters.
 
-       create_file_lines 'work/patches/patch-aa' \
+       create_file_lines 'patches/patch-aa' \
                '+++ [[[[(`" 2020-05-04'
-       create_file_lines 'work/+++ [[[[(`"' \
+       create_file_lines '+++ [[[[(`"' \
                '#! /bin/sh' \
                'test a = b'
 
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=yes'
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -233,9 +222,10 @@
                '#! /bin/sh' \
                'test a = b'
 
-       check_portability_sh
+       check_portability_sh \
+               CHECK_PORTABILITY_EXPERIMENTAL=no
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
@@ -250,7 +240,7 @@
        check_portability_sh \
                'CHECK_PORTABILITY_EXPERIMENTAL=no'
 
-       assert_that 'out' --file-is-empty
+       assert_that "$tmpdir/out" --file-is-empty
        assert_that $exitcode --equals 0
 
        test_case_end
diff -r 116c16c81b7a -r 2ada057b23a9 regress/infra-unittests/extract.sh
--- a/regress/infra-unittests/extract.sh        Mon May 11 19:08:59 2020 +0000
+++ b/regress/infra-unittests/extract.sh        Mon May 11 19:13:10 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: extract.sh,v 1.4 2020/04/26 12:46:33 rillig Exp $
+# $NetBSD: extract.sh,v 1.5 2020/05/11 19:13:10 rillig Exp $
 #
 # Test cases for mk/extract/extract.
 #
@@ -9,11 +9,6 @@
 . "./test.subr"
 
 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
 }
@@ -33,17 +28,15 @@
        create_file_lines "other/file"          "content"
        create_file_lines "other/contrib/file"  "content"
 
-       tar cf "archive.tar" "contrib" "other"
+       tar cf "$tmpdir/archive.tar" "contrib" "other"
        rm -r "contrib" "other"
 
-       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib"
-
-       find . -print | sort > "extracted"
+       sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "contrib"
 
-       assert_that "extracted" --file-is-lines \
+       find . -print | sort > "$tmpdir/extracted"
+
+       assert_that "$tmpdir/extracted" --file-is-lines \
                "." \
-               "./archive.tar" \
-               "./extracted" \
                "./other" \
                "./other/file"
 
@@ -61,18 +54,16 @@
        create_file_lines "other/file"          "content"
        create_file_lines "other/contrib/file"  "content"
 
-       tar cf "archive.tar" "contrib" "other"
+       tar cf "$tmpdir/archive.tar" "contrib" "other"
        rm -r "contrib" "other"
 
-       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib/*"
+       sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "contrib/*"
 
-       find . -print | sort > "extracted"
+       find . -print | sort > "$tmpdir/extracted"
 
-       assert_that "extracted" --file-is-lines \
+       assert_that "$tmpdir/extracted" --file-is-lines \
                "." \
-               "./archive.tar" \
                "./contrib" \
-               "./extracted" \
                "./other" \
                "./other/contrib" \
                "./other/file"
@@ -84,22 +75,26 @@
 
        # Ensure that the exclusion pattern "*" is not expanded by the
        # shell but passed as-is to the extractor.
+       #
+       # If the pattern were expanded, it would expand to 'expanded'
+       # and would thus not exclude anything from the actual archive,
+       # which means that all files in the archive would be extracted.
 
        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"
+       tar cf "$tmpdir/archive.tar" "contrib" "other"
        rm -r "contrib" "other"
 
-       sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "*"
-
-       find . -print | sort > "extracted"
+       > 'expanded'
+       sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "*"
+       rm 'expanded'
 
-       assert_that "extracted" --file-is-lines \
-               "." \
-               "./archive.tar" \
-               "./extracted"
+       find . -print | sort > "$tmpdir/extracted"
+
+       assert_that "$tmpdir/extracted" --file-is-lines \
+               "."
 
        test_case_end
 fi
diff -r 116c16c81b7a -r 2ada057b23a9 regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh  Mon May 11 19:08:59 2020 +0000
+++ b/regress/infra-unittests/subst.sh  Mon May 11 19:13:10 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: subst.sh,v 1.33 2020/05/09 17:10:38 rillig Exp $
+# $NetBSD: subst.sh,v 1.34 2020/05/11 19:13:10 rillig Exp $
 #
 # Tests for mk/subst.mk.
 #



Home | Main Index | Thread Index | Old Index