aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Dave MacLachlan <dmaclach@google.com>2015-11-06 20:12:43 +0000
committerGravatar Florian Weikert <fwe@google.com>2015-11-06 22:53:56 +0000
commit69a3f3621ea5c96edab39fde29fa1eb76d83006c (patch)
tree1f6b8296e562407968b56d28c99e4291d9eecd6b /src
parent7c1639d2948a49231f0af715330b4056d3d82fdd (diff)
Fixes up bash stack walking on Mac OS. There are cases where BASH_SOURCE is a sparse array with holes. This appears to be due to the sub shell launching of the tests. By using FUNCNAME as our count of stack frames, and "ignoring" the holes, we get much better stack output on the Mac. Previously we were just erroring out.
RELNOTES:none -- MOS_MIGRATED_REVID=107255705
Diffstat (limited to 'src')
-rw-r--r--src/test/shell/unittest.bash13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash
index ace16fd4ee..0800ff32c6 100644
--- a/src/test/shell/unittest.bash
+++ b/src/test/shell/unittest.bash
@@ -215,15 +215,16 @@ __show_stack() {
local trace_found=0
# Skip over active calls within this module:
- while [ "$i" -lt "${#BASH_SOURCE[@]}" -a "${BASH_SOURCE[$i]-}" = "${BASH_SOURCE[0]}" ]; do
- i=$(($i + 1))
+ while (( i < ${#FUNCNAME[@]} )) && [[ ${BASH_SOURCE[i]:-} == ${BASH_SOURCE[0]} ]]; do
+ (( i++ ))
done
# Show all calls until the next one within this module (typically run_suite):
- while [ "$i" -lt "${#BASH_SOURCE[@]}" -a "${BASH_SOURCE[$i]-}" != "${BASH_SOURCE[0]}" ]; do
- # There's a bug in bash that explains the strange offsets.
- echo "${BASH_SOURCE[$i]}:${BASH_LINENO[$i - 1]}: in call to ${FUNCNAME[$i - 1]}" >&2
- i=$(($i + 1))
+ while (( i < ${#FUNCNAME[@]} )) && [[ ${BASH_SOURCE[i]:-} != ${BASH_SOURCE[0]} ]]; do
+ # Read online docs for BASH_LINENO to understand the strange offset.
+ # Undefined can occur in the BASH_SOURCE stack apparently when one exits from a subshell
+ echo "${BASH_SOURCE[i]:-"Unknown"}:${BASH_LINENO[i - 1]:-"Unknown"}: in call to ${FUNCNAME[i]:-"Unknown"}" >&2
+ (( i++ ))
trace_found=1
done