1
0
mirror of https://github.com/sstephenson/bats.git synced 2026-02-26 09:48:10 +01:00

Print failed statement in backtrace

Update tests accordingly.
This commit is contained in:
Andrey Mazo
2014-06-28 23:16:32 +04:00
parent 64adaa02c3
commit bbaf0f50df
2 changed files with 52 additions and 26 deletions

View File

@@ -43,26 +43,29 @@ fixtures bats
@test "one failing test" {
run bats "$FIXTURE_ROOT/failing.bats"
[ $status -eq 1 ]
[ ${lines[0]} = "1..1" ]
[ ${lines[1]} = "not ok 1 a failing test" ]
[ ${lines[2]} = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]
[ "${lines[0]}" = '1..1' ]
[ "${lines[1]}" = 'not ok 1 a failing test' ]
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]
[ "${lines[3]}" = "# \`false' failed" ]
}
@test "one failing and one passing test" {
run bats "$FIXTURE_ROOT/failing_and_passing.bats"
[ $status -eq 1 ]
[ ${lines[0]} = "1..2" ]
[ ${lines[1]} = "not ok 1 a failing test" ]
[ ${lines[2]} = "# (in test file $FIXTURE_ROOT/failing_and_passing.bats, line 2)" ]
[ ${lines[3]} = "ok 2 a passing test" ]
[ "${lines[0]}" = '1..2' ]
[ "${lines[1]}" = 'not ok 1 a failing test' ]
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing_and_passing.bats, line 2)" ]
[ "${lines[3]}" = "# \`false' failed" ]
[ "${lines[4]}" = 'ok 2 a passing test' ]
}
@test "failing helper function logs the test case's line number" {
run bats "$FIXTURE_ROOT/failing_helper.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = "not ok 1 failing helper function" ]
[ "${lines[1]}" = 'not ok 1 failing helper function' ]
[ "${lines[2]}" = "# (from function \`failing_helper' in file $FIXTURE_ROOT/test_helper.bash, line 6," ]
[ "${lines[3]}" = "# in test file $FIXTURE_ROOT/failing_helper.bats, line 5)" ]
[ "${lines[4]}" = "# \`false' failed" ]
}
@test "test environments are isolated" {
@@ -89,22 +92,25 @@ fixtures bats
@test "setup failure" {
run bats "$FIXTURE_ROOT/failing_setup.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = "not ok 1 truth" ]
[ "${lines[1]}" = 'not ok 1 truth' ]
[ "${lines[2]}" = "# (from function \`setup' in test file $FIXTURE_ROOT/failing_setup.bats, line 2)" ]
[ "${lines[3]}" = "# \`false' failed" ]
}
@test "passing test with teardown failure" {
PASS=1 run bats "$FIXTURE_ROOT/failing_teardown.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = "not ok 1 truth" ]
[ "${lines[1]}" = 'not ok 1 truth' ]
[ "${lines[2]}" = "# (from function \`teardown' in test file $FIXTURE_ROOT/failing_teardown.bats, line 2)" ]
[ "${lines[3]}" = "# \`false' failed" ]
}
@test "failing test with teardown failure" {
PASS=0 run bats "$FIXTURE_ROOT/failing_teardown.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = "not ok 1 truth" ]
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing_teardown.bats, line 6)" ]
[ "${lines[1]}" = 'not ok 1 truth' ]
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing_teardown.bats, line 6)" ]
[ "${lines[3]}" = $'# `[ "$PASS" = "1" ]\' failed' ]
}
@test "load sources scripts relative to the current test file" {
@@ -130,9 +136,9 @@ fixtures bats
@test "output is discarded for passing tests and printed for failing tests" {
run bats "$FIXTURE_ROOT/output.bats"
[ $status -eq 1 ]
[ "${lines[5]}" = "# failure stdout 1" ]
[ "${lines[6]}" = "# failure stdout 2" ]
[ "${lines[9]}" = "# failure stderr" ]
[ "${lines[6]}" = '# failure stdout 1' ]
[ "${lines[7]}" = '# failure stdout 2' ]
[ "${lines[11]}" = '# failure stderr' ]
}
@test "-c prints the number of tests" {
@@ -172,10 +178,10 @@ fixtures bats
@test "extended syntax" {
run bats-exec-test -x "$FIXTURE_ROOT/failing_and_passing.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = "begin 1 a failing test" ]
[ "${lines[2]}" = "not ok 1 a failing test" ]
[ "${lines[4]}" = "begin 2 a passing test" ]
[ "${lines[5]}" = "ok 2 a passing test" ]
[ "${lines[1]}" = 'begin 1 a failing test' ]
[ "${lines[2]}" = 'not ok 1 a failing test' ]
[ "${lines[5]}" = 'begin 2 a passing test' ]
[ "${lines[6]}" = 'ok 2 a passing test' ]
}
@test "pretty and tap formats" {
@@ -200,9 +206,10 @@ fixtures bats
@test "single-line tests" {
run bats "$FIXTURE_ROOT/single_line.bats"
[ $status -eq 1 ]
[ "${lines[1]}" = "ok 1 empty" ]
[ "${lines[2]}" = "ok 2 passing" ]
[ "${lines[3]}" = "ok 3 input redirection" ]
[ "${lines[4]}" = "not ok 4 failing" ]
[ "${lines[5]}" = "# (in test file $FIXTURE_ROOT/single_line.bats, line 9)" ]
[ "${lines[1]}" = 'ok 1 empty' ]
[ "${lines[2]}" = 'ok 2 passing' ]
[ "${lines[3]}" = 'ok 3 input redirection' ]
[ "${lines[4]}" = 'not ok 4 failing' ]
[ "${lines[5]}" = "# (in test file $FIXTURE_ROOT/single_line.bats, line 9)" ]
[ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ]
}