Commit 840a5eae authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: '-' means gpython should read program file from stdin

Reported by @jerome here:
slapos!862 (comment 121738)
parent 8564dfdd
...@@ -157,7 +157,7 @@ def pymain(argv, init=None): ...@@ -157,7 +157,7 @@ def pymain(argv, init=None):
reexec_argv += argv reexec_argv += argv
if run is None: if run is None:
# file # file
if len(argv) > 0: if len(argv) > 0 and argv[0] != '-':
sys.argv = argv sys.argv = argv
filepath = argv[0] filepath = argv[0]
...@@ -173,7 +173,7 @@ def pymain(argv, init=None): ...@@ -173,7 +173,7 @@ def pymain(argv, init=None):
# interactive console # interactive console
else: else:
sys.argv = [''] sys.argv = [''] if len(argv) == 0 else argv # e.g. ['-']
sys.path.insert(0, '') # cwd sys.path.insert(0, '') # cwd
def run(): def run():
......
...@@ -163,6 +163,10 @@ def test_pymain(): ...@@ -163,6 +163,10 @@ def test_pymain():
# interactive # interactive
_ = pyout([], stdin=b'import hello\n', cwd=testdata) _ = pyout([], stdin=b'import hello\n', cwd=testdata)
assert _ == b"hello\nworld\n['']\n" assert _ == b"hello\nworld\n['']\n"
_ = pyout(['-'], stdin=b'import hello\n', cwd=testdata)
assert _ == b"hello\nworld\n['-']\n"
_ = pyout(['-', 'zzz'], stdin=b'import hello\n', cwd=testdata)
assert _ == b"hello\nworld\n['-', 'zzz']\n"
# -c <command> # -c <command>
_ = pyout(['-c', 'import hello', 'abc', 'def'], cwd=testdata) _ = pyout(['-c', 'import hello', 'abc', 'def'], cwd=testdata)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment