diff --git a/libexec/bats-preprocess b/libexec/bats-preprocess index d88b2f1..04297ed 100755 --- a/libexec/bats-preprocess +++ b/libexec/bats-preprocess @@ -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 diff --git a/test/bats.bats b/test/bats.bats index 37d55c2..7ec577a 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -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)" ] +} diff --git a/test/fixtures/bats/single_line.bats b/test/fixtures/bats/single_line.bats new file mode 100644 index 0000000..fc342d9 --- /dev/null +++ b/test/fixtures/bats/single_line.bats @@ -0,0 +1,9 @@ +@test "empty" { } + +@test "passing" { true; } + +@test "input redirection" { diff - <( echo hello ); } <