1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

tests: utils.sh six stacktrace

Changes:

- BASH_SOURCE index was one off.
- The first line of stacktrace was pure confusion displaying executed
  script together with innermost line number (which was either 125 when
  STACKTRACE or 229 when skip was called.)
- We can safely ignore innermost call, as stack trace is always produced
  by stacktrace function.
- It is safer to test for array length, instead of testing FUNCNAME is
  main - if main function were introduced.
- Bashishm is safe to use as this function as a whole is relying on bash.
This commit is contained in:
Marian Csontos 2017-07-14 19:51:59 +02:00 committed by Zdenek Kabelac
parent 34504855a7
commit 1c95cf8c6f

View File

@ -109,11 +109,14 @@ grep1_() {
stacktrace() {
trap - ERR
local i=0
# i=1 - ignoring innermost frame - it is always stacktrace function
local i=1 n=${#BASH_LINENO[*]}
# n-=1 - ignoring last frame as well - it is not interesting
let n-=1
echo "## - $0:${BASH_LINENO[0]}"
while FUNC=${FUNCNAME[$i]}; test "$FUNC" != "main"; do
echo "## $i ${FUNC}() called from ${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}"
echo "## - $0:${BASH_LINENO[$((n-1))]}"
while [[ $i -lt $n ]]; do
echo "## $i ${FUNCNAME[$i]}() called from ${BASH_SOURCE[$((i+1))]}:${BASH_LINENO[$i]}"
i=$(( i + 1 ))
done
}