Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

saving $IFS in run() not altered for code using it - fix #89 #90

Merged
merged 2 commits into from
Feb 25, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libexec/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ load() {
}

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

setup() {
Expand Down
8 changes: 7 additions & 1 deletion test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fixtures bats
run bats "$FIXTURE_ROOT/passing.bats"
[ $status -eq 0 ]
[ ${lines[0]} = "1..1" ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you quote ${lines[0]} on this line as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want me to quote it too? I only quoted string compare with a space inside it.

bats/test$ grep -RHn '[^"] = "[^" ]\+' 
bats.bats:33:  [ $output = "1..0" ]
bats.bats:39:  [ ${lines[0]} = "1..1" ]
suite.bats:9:  [ $output = "1..0" ]
suite.bats:15:  [ ${lines[0]} = "1..1" ]
suite.bats:32:  [ ${lines[0]} = "1..3" ]
suite.bats:41:  [ ${lines[0]} = "1..3" ]
suite.bats:48:  [ ${lines[0]} = "1..3" ]

but nothing with a space on the right side of the compare

bats/test$ grep -RHn '[^"] = "[^" ]\+ ' #  <= there's a space here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All strings (unless you're absolutely sure it will be a single number or word) should be quoted, especially in conditional expressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Just that it' was not "part" of the modification I made. I'm modifying it. no more pingpong about it. 👍

[ ${lines[1]} = "ok 1 a passing test" ]
[ "${lines[1]}" = "ok 1 a passing test" ]
}

@test "summary passing tests" {
Expand Down Expand Up @@ -256,3 +256,9 @@ fixtures bats
[ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line.bats, line 9)" ]
[ "${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 changes: 16 additions & 0 deletions test/fixtures/bats/loop_keep_IFS.bats
Original file line number Diff line number Diff line change
@@ -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' ]]
}
2 changes: 1 addition & 1 deletion test/suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fixtures suite
run bats "$FIXTURE_ROOT/single"
[ $status -eq 0 ]
[ ${lines[0]} = "1..1" ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote here as well. Basically all arbitrary string values should be quoted.

[ ${lines[1]} = "ok 1 a passing test" ]
[ "${lines[1]}" = "ok 1 a passing test" ]
}

@test "counting tests in a suite" {
Expand Down