-
Notifications
You must be signed in to change notification settings - Fork 513
Print failed statement in backtrace #57
Conversation
if [ $index -eq 1 ]; then | ||
line="$BATS_LINE_NUMBER" | ||
echo -n "# (" | ||
echo "# (command" | ||
echo "# \`$(sed -e "${line}!d" -e "${line}s:^[ \t]\+::" -e "${line}q" "${filename}")'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GNU sed appears to accept +
here without specifying the extended regex option, but it's non-portable and doesn't work on BSD/OS X sed.
Replace with something like:
sed -e "${line}!d" -e "${line}s:^[ \t][ \t]*::" -e "${line}q" "${filename}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll fix that.
Can we stick with the error output format implemented in #15? |
Update tests accordingly.
Tested on GNU `sed --posix`. From `info sed`: `\+' As `*', but matches one or more. It is a GNU extension. `\CHAR' Matches CHAR, where CHAR is one of `$', `*', `.', `[', `\', or `^'. Note that the only C-like backslash sequences that you can portably assume to be interpreted are `\n' and `\\'; in particular `\t' is not portable, and matches a `t' under most implementations of `sed', rather than a tab character.
ping @sstephenson ^^ |
Too useful to keep it unmerged :) |
Hi @ahippo. Please just push the new commits to your print-failed-command branch. GitHub will automatically update this pull request. No need to rewrite the branch or open a second PR. |
Done. |
Thanks for your work. This is now merged into master, with some riffing, and a caveat: Bats will display the outermost failing command rather than the innermost failing command. The outermost command—in other words, the line in the test case function itself—is likely more descriptive than the innermost command, which is often a helper function nested several calls deep. Consider this example from rbenv's tests. Here's the innermost failing command:
And here's the outermost failing command:
The outermost command captures the intent of the test, while the innermost command is an implementation detail. |
Thank you very much for merging the pull request! For the example from rbenv's tests your change from innermost to outermost failing command seems very natural. |
Update tests accordingly.
Please, note that it's quite similar to pull request #15