summaryrefslogtreecommitdiff
path: root/t/test-lib.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2020-04-10 17:18:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-04-10 17:30:40 (GMT)
commit662f9cf1548cf069cb819e9e95f224657015fcf9 (patch)
tree473a27581ab8d7a297496ddca05bd3be1f8d35af /t/test-lib.sh
parent6081d3898fe5e33e739cc0771f6df102b30b1db6 (diff)
downloadgit-662f9cf1548cf069cb819e9e95f224657015fcf9.zip
git-662f9cf1548cf069cb819e9e95f224657015fcf9.tar.gz
git-662f9cf1548cf069cb819e9e95f224657015fcf9.tar.bz2
tests: when run in Bash, annotate test failures with file name/line number
When a test fails, it is nice to see where the corresponding code lives in the worktree. Sadly, it seems that only Bash allows us to infer this information. Let's do it when we detect that we're running in a Bash. This will come in handy in the next commit, where we teach the GitHub Actions workflow to annotate failed test runs with this information. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/test-lib.sh')
-rw-r--r--t/test-lib.sh14
1 files changed, 13 insertions, 1 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9fe390b..936c348 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -642,6 +642,18 @@ die () {
fi
}
+file_lineno () {
+ test -z "$GIT_TEST_FRAMEWORK_SELFTEST" && test -n "$BASH" || return 0
+ local i
+ for i in ${!BASH_SOURCE[*]}
+ do
+ case $i,"${BASH_SOURCE[$i]##*/}" in
+ 0,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:$LINENO: ${1+$1: }"; return;;
+ *,t[0-9]*.sh) echo "t/${BASH_SOURCE[$i]}:${BASH_LINENO[$(($i-1))]}: ${1+$1: }"; return;;
+ esac
+ done
+}
+
GIT_EXIT_OK=
trap 'die' EXIT
# Disable '-x' tracing, because with some shells, notably dash, it
@@ -687,7 +699,7 @@ test_failure_ () {
write_junit_xml_testcase "$1" " $junit_insert"
fi
test_failure=$(($test_failure + 1))
- say_color error "not ok $test_count - $1"
+ say_color error "$(file_lineno error)not ok $test_count - $1"
shift
printf '%s\n' "$*" | sed -e 's/^/# /'
test "$immediate" = "" || { finalize_junit_xml; GIT_EXIT_OK=t; exit 1; }