Permalink
Browse files
Implement source with argv array.
The 2 tests from the last commit now pass.
- Loading branch information...
Showing
with
24 additions
and
3 deletions.
-
+14
−1
core/cmd_exec.py
-
+9
−1
core/state.py
-
+1
−1
test/spec.sh
|
|
@@ -249,7 +249,20 @@ def _Source(self, argv): |
|
|
try:
|
|
|
line_reader = reader.FileLineReader(f, self.arena)
|
|
|
_, c_parser = parse_lib.MakeParser(line_reader, self.arena)
|
|
|
return self._EvalHelper(c_parser, path)
|
|
|
|
|
|
# A sourced module CAN have a new arguments array, but it always shares
|
|
|
# the same variable scope as the caller. The caller could be at either a
|
|
|
# global or a local scope.
|
|
|
source_argv = argv[1:]
|
|
|
if source_argv:
|
|
|
self.mem.PushSourceArgv(source_argv)
|
|
|
try:
|
|
|
status = self._EvalHelper(c_parser, path)
|
|
|
finally:
|
|
|
if source_argv:
|
|
|
self.mem.PopSourceArgv()
|
|
|
|
|
|
return status
|
|
|
|
|
|
except _ControlFlow as e:
|
|
|
if e.IsReturn():
|
|
|
|
|
|
@@ -466,14 +466,22 @@ def PopCall(self): |
|
|
self.var_stack.pop()
|
|
|
self.argv_stack.pop()
|
|
|
|
|
|
def PushSourceArgv(self, argv):
|
|
|
"""For 'source foo.sh 1 2 3."""
|
|
|
self.func_name_stack.append('source')
|
|
|
self.argv_stack.append(_ArgFrame(argv))
|
|
|
|
|
|
def PopSourceArgv(self):
|
|
|
self.func_name_stack.pop()
|
|
|
self.argv_stack.pop()
|
|
|
|
|
|
def PushTemp(self):
|
|
|
"""For the temporary scope in 'FOO=bar BAR=baz echo'."""
|
|
|
# We don't want the 'read' builtin to write to this frame!
|
|
|
self.var_stack.append(_StackFrame(readonly=True))
|
|
|
|
|
|
def PopTemp(self):
|
|
|
self.var_stack.pop()
|
|
|
#util.log('**** PopTemp()')
|
|
|
|
|
|
#
|
|
|
# Argv
|
|
|
|
|
|
@@ -268,7 +268,7 @@ if_() { |
|
|
}
|
|
|
|
|
|
builtins() {
|
|
|
sh-spec spec/builtins.test.sh --osh-failures-allowed 3 \
|
|
|
sh-spec spec/builtins.test.sh --osh-failures-allowed 1 \
|
|
|
${REF_SHELLS[@]} $OSH "$@"
|
|
|
}
|
|
|
|
|
|
|
0 comments on commit
cb9850f