diff options
author | rillig <rillig@pkgsrc.org> | 2020-05-09 17:41:08 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-05-09 17:41:08 +0000 |
commit | fef020ff5edd539b60546128cd5b8fa70831360f (patch) | |
tree | 826b6a023164f9f8bd2eee14ed5b745c3d447020 /regress | |
parent | 84445bffb1258589ae62d0fa1dfaef3905ededf4 (diff) | |
download | pkgsrc-fef020ff5edd539b60546128cd5b8fa70831360f.tar.gz |
regress/infra-unittests: parse command line options [-kv] [-f filter]
Diffstat (limited to 'regress')
-rw-r--r-- | regress/infra-unittests/test.subr | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/regress/infra-unittests/test.subr b/regress/infra-unittests/test.subr index 218a222c567..b4b55f36ad7 100644 --- a/regress/infra-unittests/test.subr +++ b/regress/infra-unittests/test.subr @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: test.subr,v 1.12 2020/05/01 14:14:12 rillig Exp $ +# $NetBSD: test.subr,v 1.13 2020/05/09 17:41:08 rillig Exp $ # # This file defines utilities for testing Makefile fragments and shell # programs from the pkgsrc infrastructure. While testing one part of the @@ -105,24 +105,33 @@ # assert_fail $format $args... # Marks the current test as failed but continues to execute it. # -# -# Misc -# -# cleanup -# If this variable is yes (the default), clean up the temporary -# directory after the test has run successfully. -# set -eu -: "${cleanup:=yes}" +cleanup='yes' : "${make:=bmake}" -: "${if_verbose=:}" -tmpdir="${TMP:-/tmp}/infra-unittests-$$" +if_verbose=':' +tmpdir="${TMPDIR:-/tmp}/infra-unittests-$$" mocked_pkgsrcdir="$tmpdir/pkgsrc" +test_case_filter='.*' + rm -rf "$tmpdir" mkdir -p "$mocked_pkgsrcdir" +while getopts 'kvf:' opt; do + case "$opt" in + (f) test_case_filter="$OPTARG";; + (k) cleanup='no';; + (v) if_verbose='';; + (*) printf '%s\n' 1>&2 \ + "usage: $0 [-kv] [-f filter]" \ + ' -f regex only run matching test cases' \ + ' -k keep the temporary files' \ + ' -v verbose mode' + exit 1;; + esac +done + pkgsrcdir="" for relative_pkgsrcdir in . .. ../.. ../../..; do if [ -f "$relative_pkgsrcdir/mk/bsd.pkg.mk" ]; then @@ -145,6 +154,9 @@ test_case_ended=0 test_case_begin() { test_case_name="$1" + [ "$(expr "$test_case_name" : "$test_case_filter")" -gt 0 ] \ + || return 1 + test_case_begun="`expr "$test_case_begun" + 1`" verbose_printf 'running test case "%s"\n' "$test_case_name" |