mirror of
https://github.com/sstephenson/bats.git
synced 2024-12-26 14:39:46 +01:00
Extended syntax: "begin" line before each test is run
This commit is contained in:
parent
7849374964
commit
8873aab79f
|
@ -1,9 +1,15 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
count_only=""
|
count_only_flag=""
|
||||||
if [ "$1" = "-c" ]; then
|
if [ "$1" = "-c" ]; then
|
||||||
count_only=1
|
count_only_flag=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
extended_syntax_flag=""
|
||||||
|
if [ "$1" = "-x" ]; then
|
||||||
|
extended_syntax_flag="-x"
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -14,7 +20,7 @@ for filename in "$@"; do
|
||||||
count=$(($count + $(bats-exec-test -c "$filename")))
|
count=$(($count + $(bats-exec-test -c "$filename")))
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$count_only" ]; then
|
if [ -n "$count_only_flag" ]; then
|
||||||
echo "$count"
|
echo "$count"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
@ -28,9 +34,13 @@ for filename in "$@"; do
|
||||||
IFS= read -r # 1..n
|
IFS= read -r # 1..n
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
case "$line" in
|
case "$line" in
|
||||||
"ok "* | "not ok "* )
|
"begin "* )
|
||||||
index=$(($index + 1))
|
index=$(($index + 1))
|
||||||
echo "${line/ $index / $(($offset + $index)) }"
|
echo "${line/ $index / $(($offset + $index)) }"
|
||||||
|
;;
|
||||||
|
"ok "* | "not ok "* )
|
||||||
|
[ -n "$extended_syntax_flag" ] || index=$(($index + 1))
|
||||||
|
echo "${line/ $index / $(($offset + $index)) }"
|
||||||
[ "${line:0:6}" != "not ok" ] || status=1
|
[ "${line:0:6}" != "not ok" ] || status=1
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
|
@ -38,7 +48,7 @@ for filename in "$@"; do
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
} < <( bats-exec-test "$filename" )
|
} < <( bats-exec-test $extended_syntax_flag "$filename" )
|
||||||
offset=$(($offset + $index))
|
offset=$(($offset + $index))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,12 @@ if [ "$1" = "-c" ]; then
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
BATS_EXTENDED_SYNTAX=""
|
||||||
|
if [ "$1" = "-x" ]; then
|
||||||
|
BATS_EXTENDED_SYNTAX="$1"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
BATS_TEST_FILENAME="$1"
|
BATS_TEST_FILENAME="$1"
|
||||||
if [ -z "$BATS_TEST_FILENAME" ]; then
|
if [ -z "$BATS_TEST_FILENAME" ]; then
|
||||||
echo "usage: bats-exec <filename>" >&2
|
echo "usage: bats-exec <filename>" >&2
|
||||||
|
@ -65,6 +71,9 @@ skip() {
|
||||||
|
|
||||||
bats_test_begin() {
|
bats_test_begin() {
|
||||||
BATS_TEST_DESCRIPTION="$1"
|
BATS_TEST_DESCRIPTION="$1"
|
||||||
|
if [ -n "$BATS_EXTENDED_SYNTAX" ]; then
|
||||||
|
echo "begin $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
|
||||||
|
fi
|
||||||
setup
|
setup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +131,7 @@ bats_perform_tests() {
|
||||||
test_number=1
|
test_number=1
|
||||||
status=0
|
status=0
|
||||||
for test_name in "$@"; do
|
for test_name in "$@"; do
|
||||||
"$0" "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1
|
"$0" $BATS_EXTENDED_SYNTAX "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1
|
||||||
test_number=$(($test_number + 1))
|
test_number=$(($test_number + 1))
|
||||||
done
|
done
|
||||||
exit "$status"
|
exit "$status"
|
||||||
|
|
|
@ -129,3 +129,12 @@ fixtures bats
|
||||||
[ "${lines[1]}" = "ok 1 # skip a skipped test" ]
|
[ "${lines[1]}" = "ok 1 # skip a skipped test" ]
|
||||||
[ "${lines[2]}" = "ok 2 # skip (a reason) a skipped test with a reason" ]
|
[ "${lines[2]}" = "ok 2 # skip (a reason) a skipped test with a reason" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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" ]
|
||||||
|
}
|
||||||
|
|
|
@ -50,3 +50,15 @@ fixtures suite
|
||||||
echo "$output" | grep "^ok . more truth"
|
echo "$output" | grep "^ok . more truth"
|
||||||
echo "$output" | grep "^ok . quasi-truth"
|
echo "$output" | grep "^ok . quasi-truth"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "extended syntax in suite" {
|
||||||
|
FLUNK=1 run bats-exec-suite -x "$FIXTURE_ROOT/multiple/"*.bats
|
||||||
|
[ $status -eq 1 ]
|
||||||
|
[ "${lines[0]}" = "1..3" ]
|
||||||
|
[ "${lines[1]}" = "begin 1 truth" ]
|
||||||
|
[ "${lines[2]}" = "ok 1 truth" ]
|
||||||
|
[ "${lines[3]}" = "begin 2 more truth" ]
|
||||||
|
[ "${lines[4]}" = "ok 2 more truth" ]
|
||||||
|
[ "${lines[5]}" = "begin 3 quasi-truth" ]
|
||||||
|
[ "${lines[6]}" = "not ok 3 quasi-truth" ]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user