View
@@ -12,6 +12,7 @@
from core.id_kind import Id
from core.alloc import Pool
from core import word
from core import test_lib
from osh import ast_ as ast
from osh import parse_lib
@@ -23,12 +24,10 @@
# TODO: Use parse_lib instead
def InitCommandParser(code_str):
pool = Pool()
arena = pool.NewArena()
arena.PushSource('<unit test>')
arena = test_lib.MakeArena('<cmd_parse_test.py>')
line_reader, lexer = parse_lib.InitLexer(code_str, arena=arena)
w_parser = WordParser(lexer, line_reader)
c_parser = CommandParser(w_parser, lexer, line_reader)
c_parser = CommandParser(w_parser, lexer, line_reader, arena=arena)
return arena, c_parser # arena is returned for printing errors
@@ -1287,6 +1286,19 @@ def testForLoopName(self):
for = in a
""")
def testHereDocCommandSub(self):
# Originall from spec/09-here-doc.sh.
err = _assertParseCommandListError(self, """\
for x in 1 2 $(cat <<EOF
THREE
EOF); do
echo for word $x
done
""")
def testForLoopEof(self):
err = _assertParseCommandListError(self, "for x in 1 2 $(")
if __name__ == '__main__':
unittest.main()
View
@@ -5,8 +5,10 @@
import unittest
from core import alloc
from core.id_kind import Id, Kind, LookupKind
from core.lexer import CompileAll, Lexer, LineLexer, FindLongestMatch
from core import test_lib
from core.test_lib import TokensEqual
from osh import parse_lib
@@ -15,7 +17,8 @@
def _InitLexer(s):
_, lexer = parse_lib.InitLexer(s)
arena = test_lib.MakeArena('<lex_test.py>')
_, lexer = parse_lib.InitLexer(s, arena=arena)
return lexer
@@ -183,13 +186,13 @@ def testLookAhead(self):
# Lines always end with '\n'
l = LineLexer(LEXER_DEF, '')
self.assertTokensEqual(
ast.token(Id.Eof_Real, ''), l.LookAhead(LexMode.OUTER))
ast.token(Id.Unknown_Tok, ''), l.LookAhead(LexMode.OUTER))
l = LineLexer(LEXER_DEF, 'foo')
self.assertTokensEqual(
ast.token(Id.Lit_Chars, 'foo'), l.Read(LexMode.OUTER))
self.assertTokensEqual(
ast.token(Id.Eof_Real, ''), l.LookAhead(LexMode.OUTER))
ast.token(Id.Unknown_Tok, ''), l.LookAhead(LexMode.OUTER))
l = LineLexer(LEXER_DEF, 'foo bar')
self.assertTokensEqual(
View
@@ -54,15 +54,15 @@ def MakeParser(line_reader, arena):
#
# NOTE: It probably needs to take a VirtualLineReader for $PS1, $PS2, ...
# values.
def MakeParserForCompletion(code_str):
def MakeParserForCompletion(code_str, arena=None):
"""Parser for partial lines."""
# NOTE: We don't need to use a arena here? Or we need a "scratch arena" that
# doesn't interfere with the rest of the program.
line_reader = reader.StringLineReader(code_str)
line_lexer = lexer.LineLexer(lex.LEXER_DEF, '') # AtEnd() is true
line_lexer = lexer.LineLexer(lex.LEXER_DEF, '', arena=arena) # AtEnd() is true
lx = lexer.Lexer(line_lexer, line_reader)
w_parser = word_parse.WordParser(lx, line_reader)
c_parser = cmd_parse.CommandParser(w_parser, lx, line_reader)
c_parser = cmd_parse.CommandParser(w_parser, lx, line_reader, arena=arena)
return w_parser, c_parser
View
@@ -978,7 +978,6 @@ def _ReadCompoundWord(self, eof_type=Id.Undefined_Tok, lex_mode=LexMode.OUTER,
word.parts.append(part)
if self.token_type == Id.Lit_VarLike:
#print('@', self.lexer.LookAhead())
#print('@', self.cursor)
#print('@', self.cur_token)
View
File renamed without changes.
View
@@ -33,7 +33,7 @@ echo 'to stderr'
### exec builtin with here doc
# This has in a separate file because both code and data can be read from
# stdin.
$SH spec/exec-here-doc.sh
$SH spec/builtins-exec-here-doc-helper.sh
# stdout-json: "x=one\ny=two\nDONE\n"
### cd and $PWD
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
@@ -250,6 +250,14 @@ EOF
# stdout: 0
# N-I dash stdout: 127
### Here Doc in if condition
if cat <<EOF; then
here doc in IF CONDITION
EOF
echo THEN executed
fi
# stdout-json: "here doc in IF CONDITION\nTHEN executed\n"
### Multiple here docs in pipeline
# SKIPPED: hangs with osh on Debian
# The second instance reads its stdin from the pipe, and fd 5 from a here doc.
@@ -270,4 +278,3 @@ read_from_fd.py 0 5 5<<EOF5
fd5
EOF5
# stdout-json: "0: 3: fd3\n5: fd5\n"
View
@@ -100,16 +100,24 @@ readonly_() {
_compare gold/readonly.sh
}
complex-here-docs() {
_compare gold/complex-here-docs.sh
}
all() {
readonly_
# This one differs by timestamp
version-text
readonly_
count
one-spec-test
html-summary
configure
no-op
gen-module-init
glob
complex-here-docs
# This one takes a little long, but it's realistic.
wild
View
@@ -337,7 +337,7 @@ here-doc() {
# - On Debian, the whole process hangs.
# Is this due to Python 3.2 vs 3.4? Either way osh doesn't implement the
# functionality, so it's probably best to just implement it.
sh-spec spec/here-doc.test.sh --osh-failures-allowed 2 --range 0-27 \
sh-spec spec/here-doc.test.sh --osh-failures-allowed 2 --range 0-28 \
${REF_SHELLS[@]} $OSH "$@"
}