Skip to content

Commit

Permalink
[spec/xtrace] OSH passes 2 more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Jan 13, 2021
1 parent 46b587c commit b59da91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions core/dev.py
Expand Up @@ -196,6 +196,8 @@ def __init__(self,
self.word_ev = word_ev
self.f = f # can be stderr, the --debug-file, etc.

self.X_indent = ''

# PS4 value -> compound_word. PS4 is scoped.
self.parse_cache = {} # type: Dict[str, compound_word]

Expand All @@ -208,6 +210,9 @@ def _EvalPS4(self):
BASH_XTRACEFD exists.
"""
# Change this to be the default? Users can change it to '+ ' I guess?
ps4 = '${X_indent}${X_punct}${X_tag} '

ps4 = '+ ' # default
val = self.mem.GetValue('PS4')
if val.tag_() == value_e.Str:
Expand Down
29 changes: 17 additions & 12 deletions spec/xtrace.test.sh
Expand Up @@ -147,6 +147,14 @@ echo two
+ local 'PS4=- '
- echo func
+ echo two
## END
## OK osh STDERR:
+ echo one
+ f
+ local PS4='- '
- echo func
+ echo two
## END
## OK dash STDERR:
# dash loses information about spaces! There is a trailing space, but you
# can't see it.
Expand All @@ -155,19 +163,14 @@ echo two
+ local PS4=-
- echo func
+ echo two
## END
## OK mksh STDERR:
# local gets turned into typeset
+ echo one
+ f
+ typeset 'PS4=- '
- echo func
+ echo two
## BUG osh STDERR:
# local gets turned into typeset
+ echo one
+ f
- echo func
+ echo two
## END

#### xtrace with variables in PS4
Expand All @@ -180,27 +183,29 @@ echo two
## STDOUT:
one
two
## END

## STDERR:
+:x=1
+1:echo one
+1:x=2
+2:echo two
## END

## OK mksh STDERR:
# mksh has trailing spaces
+:x=1
+1:echo one
+1:x=2
+2:echo two
## OK dash STDERR:
# dash evaluates it earlier
## END

## OK osh/dash STDERR:
# the PS4 string is evaluated AFTER the variable is set. That's OK
+1:x=1
+1:echo one
+2:x=2
+2:echo two
## OK osh STDERR:
# dash evaluates it earlier
+1:echo one
+2:echo two
## END

#### PS4 with unterminated ${
Expand Down
2 changes: 1 addition & 1 deletion test/spec.sh
Expand Up @@ -617,7 +617,7 @@ sh-options() {
}

xtrace() {
sh-spec spec/xtrace.test.sh --osh-failures-allowed 3 \
sh-spec spec/xtrace.test.sh --osh-failures-allowed 1 \
${REF_SHELLS[@]} $OSH_LIST "$@"
}

Expand Down

0 comments on commit b59da91

Please sign in to comment.