mirror of
https://github.com/sstephenson/bats.git
synced 2024-12-28 15:39:44 +01:00
Add bats_test_succeeds() function
This commit is contained in:
parent
03608115df
commit
4f9253e9d5
|
@ -28,6 +28,7 @@ fi
|
||||||
|
|
||||||
BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
|
BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
|
||||||
BATS_TEST_NAMES=()
|
BATS_TEST_NAMES=()
|
||||||
|
BATS_TEST_RESULTS=()
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
|
@ -267,12 +268,43 @@ bats_exit_trap() {
|
||||||
exit "$status"
|
exit "$status"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bats_test_succeeds() {
|
||||||
|
local name status index i ret
|
||||||
|
|
||||||
|
ret=0
|
||||||
|
|
||||||
|
for name in $@
|
||||||
|
do
|
||||||
|
index=''
|
||||||
|
i=0
|
||||||
|
while [ $i -lt ${#BATS_TEST_NAMES[@]} ; do
|
||||||
|
if [ "${BATS_TEST_NAMES[$i]}" = "test_$name" ] ; then
|
||||||
|
index=$i
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -z $index ] ; then
|
||||||
|
echo "Error: $name: this test name does not exist" >&2
|
||||||
|
else
|
||||||
|
status=${BATS_TEST_RESULTS[$index]}
|
||||||
|
if [ -z $status ] ; then
|
||||||
|
echo "Warning: $name: Cannot check status as test didn't run yet"
|
||||||
|
else
|
||||||
|
let ret+=$status
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
bats_perform_tests() {
|
bats_perform_tests() {
|
||||||
echo "1..$#"
|
echo "1..$#"
|
||||||
test_number=1
|
test_number=1
|
||||||
status=0
|
status=0
|
||||||
for test_name in "$@"; do
|
for test_name in "$@"; do
|
||||||
"$0" $BATS_EXTENDED_SYNTAX "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1
|
"$0" $BATS_EXTENDED_SYNTAX "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1
|
||||||
|
BATS_TEST_RESULTS[$test_number]=$status
|
||||||
let test_number+=1
|
let test_number+=1
|
||||||
done
|
done
|
||||||
exit "$status"
|
exit "$status"
|
||||||
|
|
|
@ -31,15 +31,19 @@ encode_name() {
|
||||||
|
|
||||||
tests=()
|
tests=()
|
||||||
index=0
|
index=0
|
||||||
pattern='^ *@test *([^ ].*) *\{ *(.*)$'
|
pattern='^ *@test(\[([^ ])[^ ]*\])? *([^ ].*) *\{ *(.*)$'
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
let index+=1
|
let index+=1
|
||||||
if [[ "$line" =~ $pattern ]]; then
|
if [[ "$line" =~ $pattern ]]; then
|
||||||
quoted_name="${BASH_REMATCH[1]}"
|
quoted_name="${BASH_REMATCH[3]}"
|
||||||
body="${BASH_REMATCH[2]}"
|
if [ -n "${BASH_REMATCH[2]}" ; then
|
||||||
name="$(eval echo "$quoted_name")"
|
encoded_name="test_${BASH_REMATCH[2]}"
|
||||||
encoded_name="$(encode_name "$name")"
|
else
|
||||||
|
name="$(eval echo "$quoted_name")"
|
||||||
|
encoded_name="$(encode_name "$name")"
|
||||||
|
fi
|
||||||
|
body="${BASH_REMATCH[4]}"
|
||||||
tests["${#tests[@]}"]="$encoded_name"
|
tests["${#tests[@]}"]="$encoded_name"
|
||||||
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
|
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user