Skip to content

Commit

Permalink
Fix in and not_in assertion methods
Browse files Browse the repository at this point in the history
Fixing the bug with $IFS being passed to subprocesses meant that the
arrays used within these methods became broken. The methods now specify
their own $IFS, which should hopefully stop them breaking because of
this in future.
  • Loading branch information
molovo committed Feb 15, 2017
1 parent 9357b32 commit 4549284
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion zunit
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,20 @@ function _zunit_assert_does_not_match() {
function _zunit_assert_in() {
local i found=0 value=$1
local -a array
local oldIFS=$IFS
IFS=$'\n'

array=(${(@)@:2})

echo $value
echo ${#array}
for i in ${(@f)array}; do
echo $i
[[ $i = $value ]] && found=1
done

IFS=$oldIFS

[[ $found -eq 1 ]] && return 0

echo "'$value' is not in (${(@f)array})"
Expand All @@ -134,12 +142,17 @@ function _zunit_assert_in() {
function _zunit_assert_not_in() {
local i found=0 value=$1
local -a array
local oldIFS=$IFS
IFS=$'\n'

array=(${(@)@:2})

for i in ${(@f)array}; do
[[ $i = $value ]] && found=1
done

IFS=$oldIFS

[[ $found -eq 0 ]] && return 0

echo "'$value' is in (${(@f)array})"
Expand Down Expand Up @@ -305,7 +318,7 @@ function run() {
output=$("${cmd[@]}" 2>&1)

# Get the process exit state
state="$?"
state=$?

# Store individual lines of output in an array
IFS=$'\n'
Expand Down

0 comments on commit 4549284

Please sign in to comment.