Skip to content

Commit

Permalink
[spec/word-split] Add failing test case for IFS bug #2141
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy C committed Nov 26, 2024
1 parent 23fcf8f commit ea5db50
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
12 changes: 10 additions & 2 deletions devtools/refactor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,17 @@ test-files() {
#

singleton-list() {
egrep -n '\(List\[[^]]+\] [a-z]+\)' */*.asdl
egrep -n '\(List\[[^]]+\] [a-z_]+\)' */*.asdl
echo
egrep -n '\(Dict\[[^]]+\] [a-z_]+\)' */*.asdl
}

singleton-primitive() {
egrep -n '\(str [a-z_]+\)' */*.asdl
echo

egrep -n '\(int [a-z_]+\)' */*.asdl
echo
egrep -n '\(Dict\[[^]]+\] [a-z]+\)' */*.asdl
}

task-five "$@"
39 changes: 38 additions & 1 deletion spec/word-split.test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## compare_shells: bash dash mksh
## oils_failures_allowed: 8
## oils_failures_allowed: 9

# NOTE on bash bug: After setting IFS to array, it never splits anymore? Even
# if you assign IFS again.
Expand Down Expand Up @@ -419,3 +419,40 @@ noglob
['[\\]_']
## END


#### Empty IFS bug #2141 (from pnut)

res=0
sum() {
# implement callee-save calling convention using `set`
# here, we save the value of $res after the function parameters
set $@ $res # $1 $2 $3 are now set
res=$(($1 + $2))
echo "$1 + $2 = $res"
res=$3 # restore the value of $res
}

unset IFS
sum 12 30 # outputs "12 + 30 = 42"

IFS=' '
sum 12 30 # outputs "12 + 30 = 42"

IFS=
sum 12 30 # outputs "1230 + 0 = 1230"

# I added this
IFS=''
sum 12 30

set -u
IFS=
sum 12 30 # fails with "fatal: Undefined variable '2'" on res=$(($1 + $2))

## STDOUT:
12 + 30 = 42
12 + 30 = 42
12 + 30 = 42
12 + 30 = 42
12 + 30 = 42
## END

0 comments on commit ea5db50

Please sign in to comment.