Commit bd43fd9c authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Multi-line repl test

Tricky since we need to open a pseudotty to get the repl behavior.
(Piping in a program to stdin goes through a different code path.)
parent eed1d413
......@@ -455,7 +455,7 @@ static int main(int argc, char** argv) {
main_module = createModule(boxString("__main__"), "<string>");
rtncode = (RunModule(module, 1) != 0);
} else {
main_module = createModule(boxString("__main__"), fn ? fn : "<string>");
main_module = createModule(boxString("__main__"), fn ? fn : "<stdin>");
rtncode = 0;
if (fn != NULL) {
rtncode = RunMainFromImporter(fn);
......
......@@ -61,7 +61,7 @@ void printTraceback(Box* b) {
for (; tb && tb != None; tb = static_cast<BoxedTraceback*>(tb->tb_next)) {
auto& line = tb->line;
fprintf(stderr, " File \"%s\", line %d, in %s:\n", line.file->c_str(), line.line, line.func->c_str());
fprintf(stderr, " File \"%s\", line %d, in %s\n", line.file->c_str(), line.line, line.func->c_str());
if (line.line < 0)
continue;
......
import os
import pty
import subprocess
import sys
def test(s, expected_code=0):
pid, fd = pty.fork()
if pid == 0:
os.execl(sys.executable, sys.executable, '-S')
written = 0
# The same fd is used for reading and writing, so I'm not sure how to signal that it's closed
# to the child but still have it be readable by the parent.
s += '\nimport os\nos._exit(0)\n'
while written < len(s):
written += os.write(fd, s[written:])
_, wcode = os.waitpid(pid, 0)
print
r = os.read(fd, 10240)
lines = r.split('\n')
while not (lines[0].startswith('Python') or lines[0].startswith('Pyston')):
lines.pop(0)
if lines[0].startswith('Python'):
lines.pop(0)
lines.pop(0)
# Filter out syntax error location lines and make carets consistent:
lines = [l.replace('>>> ', '>> ') for l in lines if l.strip() != '^']
print '\n'.join(lines)
assert os.WIFEXITED(wcode), wcode
code = os.WEXITSTATUS(wcode)
assert code == expected_code, "Expected %d, got %d" % (expected_code, code)
test("1")
test("1/0")
test("import sys; sys.exit(2)", 2)
test("import sys\nsys.exit(2)", 2)
test("import sys; sys.exit(\n2)", 2)
test("class C(object):\n a=1\nprint C().a", 0)
test("class C(object):\n a=1\n\nprint C().a", 0)
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