From 4416893415e4ebe332e161a0b9571216b9c71760 Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Thu, 31 May 2018 14:44:38 +0200 Subject: more tests --- tests/test_snekbox.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/test_snekbox.py') diff --git a/tests/test_snekbox.py b/tests/test_snekbox.py index 8ebd0c0..ab45bdf 100644 --- a/tests/test_snekbox.py +++ b/tests/test_snekbox.py @@ -11,3 +11,28 @@ class SnekTests(unittest.TestCase): def test_nsjail(self): result = snek.python3('print("test")') self.assertEquals(result.strip(), 'test') + + def test_memory_error(self): + code = ('x = "*"\n' + 'while True:\n' + ' x = x * 99\n') + + result = snek.python3(code) + self.assertEquals(result.strip(), 'MemoryError') + + def test_timeout(self): + code = ('x = "*"\n' + 'while True:\n' + ' try:\n' + ' x = x * 99\n' + ' except:\n' + ' continue\n') + + result = snek.python3(code) + self.assertEquals(result.strip(), 'timed out or memory limit exceeded') + + def test_kill(self): + code = ('import subprocess\n' + 'print(subprocess.check_output("kill -9 6", shell=True).decode())') + result = snek.python3(code) + self.assertIn('returned non-zero exit status 1.', result.strip()) -- cgit v1.2.3