diff options
author | 2020-01-11 13:50:47 -0800 | |
---|---|---|
committer | 2020-01-11 13:50:47 -0800 | |
commit | 83f1c49ab6ed6ff0b04f32f5031e4838131302d1 (patch) | |
tree | 52217aacedb4ec1eacf6db1b892379e70ab831c3 | |
parent | Add test for importing numpy (diff) |
Fix #56: stdout and stderr outputs in wrong order
-rw-r--r-- | scripts/.profile | 2 | ||||
-rw-r--r-- | snekbox.cfg | 2 | ||||
-rw-r--r-- | snekbox/nsjail.py | 2 | ||||
-rw-r--r-- | tests/test_nsjail.py | 16 |
4 files changed, 19 insertions, 3 deletions
diff --git a/scripts/.profile b/scripts/.profile index 47ee141..73fbb28 100644 --- a/scripts/.profile +++ b/scripts/.profile @@ -17,5 +17,5 @@ nsjpy() { nsjail \ --config "${NSJAIL_CFG:-/snekbox/snekbox.cfg}" \ $nsj_args -- \ - /snekbox/.venv/bin/python3 -Iq -c "$@" + /snekbox/.venv/bin/python3 -Iqu -c "$@" } diff --git a/snekbox.cfg b/snekbox.cfg index 4cb58de..1d58ea5 100644 --- a/snekbox.cfg +++ b/snekbox.cfg @@ -93,5 +93,5 @@ iface_no_lo: true exec_bin { path: "/snekbox/.venv/bin/python3" - arg: "-Iq" + arg: "-Iqu" } diff --git a/snekbox/nsjail.py b/snekbox/nsjail.py index 83d3b8d..df69e7a 100644 --- a/snekbox/nsjail.py +++ b/snekbox/nsjail.py @@ -128,7 +128,7 @@ class NsJail: "--cgroup_pids_mount", str(CGROUP_PIDS_PARENT.parent), "--cgroup_pids_parent", CGROUP_PIDS_PARENT.name, "--", - self.python_binary, "-Iq", "-c", code + self.python_binary, "-Iqu", "-c", code ) msg = "Executing code..." diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py index f04d317..0b755b2 100644 --- a/tests/test_nsjail.py +++ b/tests/test_nsjail.py @@ -158,3 +158,19 @@ class NsJailTests(unittest.TestCase): self.assertEqual(result.returncode, 0) self.assertEqual(result.stdout, "") self.assertEqual(result.stderr, None) + + def test_output_order(self): + stdout_msg = "greetings from stdout!" + stderr_msg = "hello from stderr!" + code = dedent(f""" + print({stdout_msg!r}) + raise ValueError({stderr_msg!r}) + """).strip() + + result = self.nsjail.python3(code) + self.assertLess( + result.stdout.find(stdout_msg), + result.stdout.find(stderr_msg), + msg="stdout does not come before stderr" + ) + self.assertEqual(result.stderr, None) |