From 1041e46f3931869a993dc0b7b1b7bce7f125e765 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 17 Nov 2013 13:04:57 -0600 Subject: [PATCH] Support single-line test definitions --- libexec/bats-preprocess | 5 +++-- test/bats.bats | 10 ++++++++++ test/fixtures/bats/single_line.bats | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/bats/single_line.bats 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 ); } <