]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/test-lib.sh
test-lib: verbose mode for only tests matching a pattern
[thirdparty/git.git] / t / test-lib.sh
index 432248dfb87f1cdfcf0396e80152eb460d6748c8..95df832ed951b03ff4bdd1d84bbd989a29b04f08 100644 (file)
@@ -184,6 +184,9 @@ do
                help=t; shift ;;
        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
                verbose=t; shift ;;
+       --verbose-only=*)
+               verbose_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
+               shift ;;
        -q|--q|--qu|--qui|--quie|--quiet)
                # Ignore --quiet under a TAP::Harness. Saying how many tests
                # passed without the ok/not ok details is always an error.
@@ -342,6 +345,32 @@ match_pattern_list () {
        return 1
 }
 
+maybe_teardown_verbose () {
+       test -z "$verbose_only" && return
+       exec 4>/dev/null 3>/dev/null
+       verbose=
+}
+
+last_verbose=t
+maybe_setup_verbose () {
+       test -z "$verbose_only" && return
+       if match_pattern_list $test_count $verbose_only
+       then
+               exec 4>&2 3>&1
+               # Emit a delimiting blank line when going from
+               # non-verbose to verbose.  Within verbose mode the
+               # delimiter is printed by test_expect_*.  The choice
+               # of the initial $last_verbose is such that before
+               # test 1, we do not print it.
+               test -z "$last_verbose" && echo >&3 ""
+               verbose=t
+       else
+               exec 4>/dev/null 3>/dev/null
+               verbose=
+       fi
+       last_verbose=$verbose
+}
+
 test_eval_ () {
        # This is a separate function because some tests use
        # "return" to end a test_expect_success block early.
@@ -371,10 +400,12 @@ test_run_ () {
 
 test_start_ () {
        test_count=$(($test_count+1))
+       maybe_setup_verbose
 }
 
 test_finish_ () {
        echo >&3 ""
+       maybe_teardown_verbose
 }
 
 test_skip () {