1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-11-17 03:32:27 +01:00

saving $IFS in run() not altered for code using it

IFS was modified by run() becoming '\n' and so relying to its bash default
was failing tests.

Also some wrong tests corrected because was relying on this behavior to pass.

Fix #89
This commit is contained in:
Sylvain 2015-01-29 20:51:49 +01:00
parent 3b33a5ac6a
commit 1735a4fcd2
4 changed files with 27 additions and 3 deletions

View File

@ -48,7 +48,7 @@ load() {
} }
run() { run() {
local e E T local e E T oldIFS
[[ ! "$-" =~ e ]] || e=1 [[ ! "$-" =~ e ]] || e=1
[[ ! "$-" =~ E ]] || E=1 [[ ! "$-" =~ E ]] || E=1
[[ ! "$-" =~ T ]] || T=1 [[ ! "$-" =~ T ]] || T=1
@ -57,10 +57,12 @@ run() {
set +T set +T
output="$("$@" 2>&1)" output="$("$@" 2>&1)"
status="$?" status="$?"
oldIFS=$IFS
IFS=$'\n' lines=($output) IFS=$'\n' lines=($output)
[ -z "$e" ] || set -e [ -z "$e" ] || set -e
[ -z "$E" ] || set -E [ -z "$E" ] || set -E
[ -z "$T" ] || set -T [ -z "$T" ] || set -T
IFS=$oldIFS
} }
setup() { setup() {

View File

@ -37,7 +37,7 @@ fixtures bats
run bats "$FIXTURE_ROOT/passing.bats" run bats "$FIXTURE_ROOT/passing.bats"
[ $status -eq 0 ] [ $status -eq 0 ]
[ ${lines[0]} = "1..1" ] [ ${lines[0]} = "1..1" ]
[ ${lines[1]} = "ok 1 a passing test" ] [ "${lines[1]}" = "ok 1 a passing test" ]
} }
@test "summary passing tests" { @test "summary passing tests" {
@ -256,3 +256,9 @@ fixtures bats
[ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line.bats, line 9)" ] [ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line.bats, line 9)" ]
[ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ] [ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ]
} }
@test "testing IFS not modified by run" {
run bats "$FIXTURE_ROOT/loop_keep_IFS.bats"
[ $status -eq 0 ]
[ "${lines[1]}" = "ok 1 loop_func" ]
}

16
test/fixtures/bats/loop_keep_IFS.bats vendored Normal file
View File

@ -0,0 +1,16 @@
# see issue #89
loop_func() {
local search="none one two tree"
local d
for d in $search ; do
echo $d
done
}
@test "loop_func" {
run loop_func
[[ "${lines[3]}" == 'tree' ]]
run loop_func
[[ "${lines[2]}" == 'two' ]]
}

View File

@ -13,7 +13,7 @@ fixtures suite
run bats "$FIXTURE_ROOT/single" run bats "$FIXTURE_ROOT/single"
[ $status -eq 0 ] [ $status -eq 0 ]
[ ${lines[0]} = "1..1" ] [ ${lines[0]} = "1..1" ]
[ ${lines[1]} = "ok 1 a passing test" ] [ "${lines[1]}" = "ok 1 a passing test" ]
} }
@test "counting tests in a suite" { @test "counting tests in a suite" {