Skip to content

Commit

Permalink
exceptions are expected in testing random programs, they should not b…
Browse files Browse the repository at this point in the history
…e re-raised in test()
  • Loading branch information
vadim0x60 committed Oct 16, 2023
1 parent 210e091 commit 794ca95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions programlib/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ def build(self, name):
return '', ''

def run(self, name, input_lines=[]):
child = self.spawn(name)
for line in input_lines:
child.sendline(line)
output = child.read()
child.close()
return output.decode(), child.exitstatus
try:
child = self.spawn(name)
for line in input_lines:
child.sendline(line)
output = child.read()
child.close()
return output.decode(), child.exitstatus
except pexpect.exceptions.TIMEOUT as e:
raise RuntimeError('Program did not receive expected input') from e
except pexpect.exceptions.EOF as e:
raise RuntimeError('Program exited unexpectedly') from e

def spawn(self, name):
child = pexpect.spawn(self.run_cmd.format(name=name))
Expand Down
2 changes: 1 addition & 1 deletion programlib/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test(self, test_cases, force=True):
test_run = TestRun(input_lines, expected_output_lines,
output_lines, self.exitstatus,
correctness(expected_output_lines, output_lines))
except AssertionError:
except (AssertionError, RuntimeError):
pass

if not test_run:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "programlib"
version = "8.0.0"
version = "8.0.1"
description = "Programs as Objects"
authors = ["Vadim Liventsev <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 794ca95

Please sign in to comment.