Skip to content

Commit

Permalink
[test/spec] Reproduce bugs reported by Crestwave.
Browse files Browse the repository at this point in the history
Addresses issue #291.
  • Loading branch information
Andy Chu committed May 1, 2019
1 parent c0f3299 commit 2c65cbe
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doc/osh-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ TODO: Add these
# This relates to comments being EOL or not
-->

(7) **Ambiguous Character Classes in Globs**

In short, don't use the ambiguous syntax `[[]` or `[]]` for a character class
consisting of a single left bracket or right bracket character.

Instead, use `[\[]` and `[\]]`.

TODO: Explanation.

## set builtin

### errexit
Expand Down
6 changes: 6 additions & 0 deletions native/libc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ def testRegexFirstGroupMatch(self):
self.assertRaises(
RuntimeError, libc.regex_first_group_match, r'*', 'abcd', 0)

def testRegexFirstGroupMatchError(self):
# Helping to debug issue #291
s = ''
if 1:
libc.regex_first_group_match("(['+-'])", s, 6)

def testRealpathFailOnNonexistentDirectory(self):
# This behaviour is actually inconsistent with GNU readlink,
# but matches behaviour of busybox readlink
Expand Down
67 changes: 67 additions & 0 deletions spec/bugs.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,72 @@ a=(1 2 3)
(( a = 42 ))
echo $a
## stdout: 42
## N-I dash/ash stdout-json: ""
## N-I dash/ash status: 2

#### Nested % and # operators (looks like a bug, reported by Crestwave)
var=$'\n'
argv.py "${var#?}"
argv.py "${var%''}"
argv.py "${var%"${var#?}"}"
var='a'
argv.py "${var#?}"
argv.py "${var%''}"
argv.py "${var%"${var#?}"}"
## STDOUT:
['']
['\n']
['\n']
['']
['a']
['a']
## END
## N-I dash STDOUT:
['\\n']
['$\\n']
['$']
['']
['a']
['a']
## END

#### # operator with single quoted arg (dash/ash and bash/mksh disagree, reported by Crestwave)
var=a
echo -${var#'a'}-
echo -"${var#'a'}"-
var="'a'"
echo -${var#'a'}-
echo -"${var#'a'}"-
## STDOUT:
--
--
-'a'-
-'a'-
## END
## OK dash/ash STDOUT:
--
-a-
-'a'-
--
## END

#### / operator with single quoted arg (causes syntax error in regex in OSH, reported by Crestwave)
var="++--''++--''"
echo no plus or minus "${var//[+-]}"
echo no plus or minus "${var//['+-']}"
## STDOUT:
no plus or minus ''''
no plus or minus ''''
## END
## status: 0
## OK osh STDOUT:
no plus or minus ''''
## END
## OK osh status: 1
## BUG ash STDOUT:
no plus or minus ''''
no plus or minus ++--++--
## END
## BUG ash status: 0
## N-I dash stdout-json: ""
## N-I dash status: 2
8 changes: 8 additions & 0 deletions test/parse-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ args-parse-builtin() {
# - Oil flags: invalid long flag, boolean argument, etc.
}

# aiding the transition
args-parse-more() {
set +o errexit
_error-case 'set -z'
_error-case 'shopt -s foo'
_error-case 'shopt -z'
}

args-parse-main() {
set +o errexit
bin/osh --ast-format x
Expand Down
3 changes: 2 additions & 1 deletion test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ osh-only() {

# Regress bugs
bugs() {
sh-spec spec/bugs.test.sh ${REF_SHELLS[@]} $OSH_LIST "$@"
sh-spec spec/bugs.test.sh ${REF_SHELLS[@]} $BUSYBOX_ASH $OSH_LIST "$@" \
--osh-failures-allowed 2
}

blog1() {
Expand Down

0 comments on commit 2c65cbe

Please sign in to comment.