mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 03:32:27 +01:00
Print test file path and line number after a failing test
This commit is contained in:
parent
1be500e4ff
commit
bc72b85871
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
set -E
|
||||||
|
set -T
|
||||||
|
|
||||||
BATS_COUNT_ONLY=""
|
BATS_COUNT_ONLY=""
|
||||||
if [ "$1" = "-c" ]; then
|
if [ "$1" = "-c" ]; then
|
||||||
|
@ -32,13 +34,19 @@ load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
local e
|
local e E T
|
||||||
[[ ! "$-" =~ e ]] || e=1
|
[[ ! "$-" =~ e ]] || e=1
|
||||||
|
[[ ! "$-" =~ E ]] || E=1
|
||||||
|
[[ ! "$-" =~ T ]] || T=1
|
||||||
set +e
|
set +e
|
||||||
|
set +E
|
||||||
|
set +T
|
||||||
output="$("$@" 2>&1)"
|
output="$("$@" 2>&1)"
|
||||||
status="$?"
|
status="$?"
|
||||||
IFS=$'\n' lines=($output)
|
IFS=$'\n' lines=($output)
|
||||||
[ -z "$e" ] || set -e
|
[ -z "$e" ] || set -e
|
||||||
|
[ -z "$E" ] || set -E
|
||||||
|
[ -z "$T" ] || set -T
|
||||||
}
|
}
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
@ -51,7 +59,6 @@ teardown() {
|
||||||
|
|
||||||
bats_test_info() {
|
bats_test_info() {
|
||||||
BATS_TEST_DESCRIPTION="$1"
|
BATS_TEST_DESCRIPTION="$1"
|
||||||
BATS_LINE_NUMBER="$2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_test_function() {
|
bats_test_function() {
|
||||||
|
@ -59,8 +66,19 @@ bats_test_function() {
|
||||||
BATS_TEST_NAMES["${#BATS_TEST_NAMES[@]}"]="$test_name"
|
BATS_TEST_NAMES["${#BATS_TEST_NAMES[@]}"]="$test_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bats_debug_trap() {
|
||||||
|
if [ "$BASH_SOURCE" != "$1" ]; then
|
||||||
|
BATS_LINE_NUMBER="$BATS_LINE_NUMBER_"
|
||||||
|
BATS_LINE_NUMBER_="$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
bats_error_trap() {
|
||||||
|
trap - debug
|
||||||
|
}
|
||||||
|
|
||||||
bats_teardown_trap() {
|
bats_teardown_trap() {
|
||||||
trap bats_exit_trap err exit
|
trap bats_exit_trap exit
|
||||||
teardown >>"$BATS_OUT" 2>&1
|
teardown >>"$BATS_OUT" 2>&1
|
||||||
bats_exit_trap
|
bats_exit_trap
|
||||||
}
|
}
|
||||||
|
@ -71,7 +89,8 @@ bats_exit_trap() {
|
||||||
|
|
||||||
if [ -z "$BATS_TEST_COMPLETED" ]; then
|
if [ -z "$BATS_TEST_COMPLETED" ]; then
|
||||||
echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
|
echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
|
||||||
sed -e "s/^/ /" < "$BATS_OUT" >&3
|
echo "# $BATS_TEST_FILENAME:$BATS_LINE_NUMBER" >&3
|
||||||
|
sed -e "s/^/# /" < "$BATS_OUT" >&3
|
||||||
status=1
|
status=1
|
||||||
else
|
else
|
||||||
echo "ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
|
echo "ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
|
||||||
|
@ -103,7 +122,10 @@ bats_perform_test() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BATS_TEST_COMPLETED=""
|
BATS_TEST_COMPLETED=""
|
||||||
trap bats_teardown_trap err exit
|
BATS_ERROR_LINE=""
|
||||||
|
trap "bats_debug_trap \"\$BASH_SOURCE\" \$LINENO" debug
|
||||||
|
trap "bats_error_trap" err
|
||||||
|
trap "bats_teardown_trap" exit
|
||||||
{ setup
|
{ setup
|
||||||
"$BATS_TEST_NAME"
|
"$BATS_TEST_NAME"
|
||||||
} >>"$BATS_OUT" 2>&1
|
} >>"$BATS_OUT" 2>&1
|
||||||
|
|
|
@ -39,6 +39,7 @@ fixtures bats
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
[ ${lines[0]} = "1..1" ]
|
[ ${lines[0]} = "1..1" ]
|
||||||
[ ${lines[1]} = "not ok 1 a failing test" ]
|
[ ${lines[1]} = "not ok 1 a failing test" ]
|
||||||
|
[ ${lines[2]} = "# $FIXTURE_ROOT/failing.bats:4" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "one failing and one passing test" {
|
@test "one failing and one passing test" {
|
||||||
|
@ -46,7 +47,8 @@ fixtures bats
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
[ ${lines[0]} = "1..2" ]
|
[ ${lines[0]} = "1..2" ]
|
||||||
[ ${lines[1]} = "not ok 1 a failing test" ]
|
[ ${lines[1]} = "not ok 1 a failing test" ]
|
||||||
[ ${lines[2]} = "ok 2 a passing test" ]
|
[ ${lines[2]} = "# $FIXTURE_ROOT/failing_and_passing.bats:2" ]
|
||||||
|
[ ${lines[3]} = "ok 2 a passing test" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "test environments are isolated" {
|
@test "test environments are isolated" {
|
||||||
|
@ -83,9 +85,9 @@ fixtures bats
|
||||||
@test "output is discarded for passing tests and printed for failing tests" {
|
@test "output is discarded for passing tests and printed for failing tests" {
|
||||||
run bats "$FIXTURE_ROOT/output.bats"
|
run bats "$FIXTURE_ROOT/output.bats"
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
[ "${lines[4]}" = " failure stdout 1" ]
|
[ "${lines[5]}" = "# failure stdout 1" ]
|
||||||
[ "${lines[5]}" = " failure stdout 2" ]
|
[ "${lines[6]}" = "# failure stdout 2" ]
|
||||||
[ "${lines[7]}" = " failure stderr" ]
|
[ "${lines[9]}" = "# failure stderr" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "-c prints the number of tests" {
|
@test "-c prints the number of tests" {
|
||||||
|
|
2
test/fixtures/bats/failing.bats
vendored
2
test/fixtures/bats/failing.bats
vendored
|
@ -1,3 +1,5 @@
|
||||||
@test "a failing test" {
|
@test "a failing test" {
|
||||||
|
true
|
||||||
|
true
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user