mirror of
https://github.com/sstephenson/bats.git
synced 2024-12-25 14:09:43 +01:00
Support single-line test definitions
This commit is contained in:
parent
08374f7269
commit
1041e46f39
|
@ -31,16 +31,17 @@ encode_name() {
|
|||
|
||||
tests=()
|
||||
index=0
|
||||
pattern='^ *@test *([^ ].*) *\{ *$'
|
||||
pattern='^ *@test *([^ ].*) *\{ *(.*)$'
|
||||
|
||||
while IFS= read -r line; do
|
||||
let index+=1
|
||||
if [[ "$line" =~ $pattern ]]; then
|
||||
quoted_name="${BASH_REMATCH[1]}"
|
||||
body="${BASH_REMATCH[2]}"
|
||||
name="$(eval echo "$quoted_name")"
|
||||
encoded_name="$(encode_name "$name")"
|
||||
tests["${#tests[@]}"]="$encoded_name"
|
||||
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}"
|
||||
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
|
||||
else
|
||||
printf "%s\n" "$line"
|
||||
fi
|
||||
|
|
|
@ -186,3 +186,13 @@ fixtures bats
|
|||
[ "${lines[0]}" = "This isn't TAP!" ]
|
||||
[ "${lines[1]}" = "Good day to you" ]
|
||||
}
|
||||
|
||||
@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)" ]
|
||||
}
|
||||
|
|
9
test/fixtures/bats/single_line.bats
vendored
Normal file
9
test/fixtures/bats/single_line.bats
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
@test "empty" { }
|
||||
|
||||
@test "passing" { true; }
|
||||
|
||||
@test "input redirection" { diff - <( echo hello ); } <<EOS
|
||||
hello
|
||||
EOS
|
||||
|
||||
@test "failing" { false; }
|
Loading…
Reference in New Issue
Block a user