Permalink
Browse files
Fix bug with && and errexit.
Still need to handle && and || precedence.
Unrelated:
- Revive some early spec tests 03-glob as gold test
- Spec tests for pattern substitution
- Tests involving char classes
- More tests for glob patterns
Loading branch information...
@@ -713,6 +713,11 @@ def _Dispatch(self, node, fork_external):
status = self ._ExecuteList(node.children)
elif node.tag == command_e.AndOr:
# TODO : We have to fix && || precedence. See case #13 in
# dbracket.test.sh.
check_errexit = False # only check last condition
# print(node.children)
left, right = node.children
@@ -726,9 +731,11 @@ def _Dispatch(self, node, fork_external):
if node.op_id == Id.Op_DPipe:
if status != 0 :
status = self ._Execute(right)
check_errexit = True # status from last clause
elif node.op_id == Id.Op_DAmp:
if status == 0 :
status = self ._Execute(right)
check_errexit = True # status from last clause
else :
raise AssertionError
@@ -29,6 +29,14 @@ def testFnmatch(self):
(' \\\\ ' , ' \\ ' , 1 ),
# What is another error? Invalid escape is OK?
(' \\ ' , ' \\ ' , 0 ), # no pattern is valid
(' [[:alpha:]]' , ' a' , 1 ),
(' [^[:alpha:]]' , ' a' , 0 ), # negate
(' [[:alpha:]]' , ' aa' , 0 ), # exact match fails
# Combining char class and a literal character
(' [[:alpha:]7]' , ' 7' , 1 ),
(' [[:alpha:]][[:alpha:]]' , ' az' , 1 ),
]
for pat, s, expected in cases:
@@ -4,15 +4,15 @@
# ./03-glob.sh <function name>
# Evaluates to command and arg
tests /echo.s[h-j]
spec /echo.s[h-j]
# Negation
tests /echo.s[! i-z]
tests /echo.s[! i]
spec /echo.s[! i-z]
spec /echo.s[! i]
tests /echo.*
spec /echo.*
tests /echo.s?
spec /echo.s?
# NOTE: bash also has extglob
# http://mywiki.wooledge.org/glob
@@ -23,4 +23,4 @@ tests/echo.s?
# globstar -- ** for directories
echo classes
tests /echo.s[[:alpha:]]
spec /echo.s[[:alpha:]]
@@ -205,6 +205,19 @@ echo ok && echo hi | grep nonexistent
# stdout: ok
# status: 1
# ## errexit test && -- from gen-module-init
set -o errexit
test " $mod " = readline && echo " #endif"
echo status=$?
# stdout: status=1
# ## errexit test && and fail
set -o errexit
test -n X && false
echo status=$?
# stdout-json: ""
# status: 1
# ## errexit with !
set -o errexit
echo one
@@ -32,6 +32,35 @@ echo ${v/c*/XX}
# N-I dash status: 2
# N-I dash stdout-json: ""
# ## Global Pattern replacement with /
s=xx_xx_xx
echo ${s/ xx?/ yy_} ${s// xx?/ yy_}
# stdout: yy_xx_xx yy_yy_xx
# N-I dash status: 2
# N-I dash stdout-json: ""
# ## Left Anchored Pattern replacement with #
s=xx_xx_xx
echo ${s/ ?xx/ _yy} ${s/# ?xx/ _yy}
# stdout: xx_yy_xx xx_xx_xx
# N-I dash status: 2
# N-I dash stdout-json: ""
# ## Right Anchored Pattern replacement with %
s=xx_xx_xx
echo ${s/ ?xx/ _yy} ${s/% ?xx/ _yy}
# stdout: xx_yy_xx xx_xx_yy
# N-I dash status: 2
# N-I dash stdout-json: ""
# ## Replace char class
s=xx_xx_xx
echo ${s// [[:alpha:]]/ y} ${s// [^[:alpha:]]/ -}
# stdout: yy_yy_yy xx-xx-xx
# N-I mksh stdout: xx_xx_xx xx_xx_xx
# N-I dash status: 2
# N-I dash stdout-json: ""
# ## Pattern replacement ${v/} is not valid
v=abcde
echo -${v/ } -
@@ -53,3 +53,8 @@ v=aabbccdd
echo ${v##* b}
# stdout: ccdd
# ## Strip char class
v=abc
echo ${v% [[:alpha:]]}
# stdout: ab
# N-I mksh stdout: abc
@@ -88,6 +88,10 @@ startup-benchmark() {
_compare benchmarks/startup.sh compare-strace
}
03-glob () {
_compare spec/03-glob.sh
}
all () {
version-text
count
@@ -98,6 +102,7 @@ all() {
gen-module-init
wild
startup-benchmark
03-glob
}
" $@ "
@@ -349,12 +349,12 @@ var-op-test() {
}
var-op-other () {
sh-spec spec/var-op-other.test.sh --osh-failures-allowed 6 \
sh-spec spec/var-op-other.test.sh --osh-failures-allowed 10 \
${REF_SHELLS[@]} $OSH " $@ "
}
var-op-strip () {
sh-spec spec/var-op-strip.test.sh --osh-failures-allowed 4 \
sh-spec spec/var-op-strip.test.sh --osh-failures-allowed 5 \
${REF_SHELLS[@]} $OSH " $@ "
}
Toggle all file notes
0 comments on commit
730e7f9