1
0
mirror of https://github.com/sstephenson/bats.git synced 2026-02-25 17:28:11 +01:00

Merge remote-tracking branch 'ahippo/print-failed-command' into print-failed-command

Conflicts:
	libexec/bats-exec-test
This commit is contained in:
Sam Stephenson
2014-08-12 12:17:51 -05:00
4 changed files with 81 additions and 37 deletions

View File

@@ -118,13 +118,23 @@ bats_capture_stack_trace() {
bats_print_stack_trace() {
local frame
local filename
local lineno
local index=1
local count="${#@}"
local failed_line
for frame in "$@"; do
if [ $index -eq $count ]; then
filename="$BATS_TEST_FILENAME"
else
filename="$(bats_frame_filename "$frame")"
fi
lineno="$(bats_frame_lineno "$frame")"
if [ $index -eq 1 ]; then
failed_line="$(bats_extract_line "$filename" "$lineno")"
echo -n "# ("
else
echo -n "# "
@@ -136,9 +146,10 @@ bats_print_stack_trace() {
fi
if [ $index -eq $count ]; then
echo "in test file $BATS_TEST_FILENAME, line $lineno)"
local failed_command="$(bats_strip_string "$failed_line")"
echo "in test file $filename, line $lineno)"
echo "# \`${failed_command}' failed"
else
local filename="$(bats_frame_filename "$frame")"
echo "in file $filename, line $lineno,"
fi
@@ -171,6 +182,17 @@ bats_frame_filename() {
fi
}
bats_extract_line() {
local filename="$1"
local lineno="$2"
sed -n "${lineno}p" "$filename"
}
bats_strip_string() {
local string="$1"
printf "%s" "$string" | sed -e "s/^[ "$'\t'"]*//" -e "s/[ "$'\t'"]*$//"
}
bats_debug_trap() {
if [ "$BASH_SOURCE" != "$1" ]; then
bats_capture_stack_trace