Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

report $output content when test fails #8

Closed
wants to merge 1 commit into from

Conversation

jhrcz
Copy link

@jhrcz jhrcz commented Apr 26, 2013

in some cases, its not easy to find why test failed. i saw one sollution with custom assert_equal. but its useful to have the content of $output printent out when test fails.

i'm not sure that this is the 100perc correct place, but this worked fine for me and i was able to fix my tests then.

@@ -37,6 +37,7 @@ run() {
set +e
output="$("$@" 2>&1)"
status="$?"
echo "$output" | sed -e 's/^/ #output#/' > "$BATS_OUT"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this just helped me too, thanks :)

I don't think the sed is necessary, though -- the way I see it, run should behave the same as just invoking the command normally (except that a non-zero exit doesn't fail the test, and that the status and output are captured)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although perhaps it should append to $BATS_OUT so that it doesn't overwrite the rest of the test case's output.

@sstephenson
Copy link
Owner

Thanks for the patch, but I don't think Bats should print $output by default—it could be quite large.

Bats will now tell you the test filename and line number that triggers the failure, which should help you when debugging failing tests: bc72b85

@hdgarrood
Copy link

Ah sweet -- that's really helpful. Thanks!

@ztombol ztombol mentioned this pull request Dec 13, 2016
18 tasks
ntnn pushed a commit to ntnn/bats that referenced this pull request Oct 9, 2017
Fix macOS/Bash 3.2 breakage; eliminate subshells from exec-test, preprocess
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants