Commit 7430f261 authored by Johannes Bechberger's avatar Johannes Bechberger

Improve handling of non zero exit codes

parent e1b0b619
...@@ -6,6 +6,7 @@ import sys ...@@ -6,6 +6,7 @@ import sys
from mjtest.environment import TestMode, Environment from mjtest.environment import TestMode, Environment
from mjtest.test.syntax_tests import BasicSyntaxTest from mjtest.test.syntax_tests import BasicSyntaxTest
from mjtest.test.tests import TestCase, BasicDiffTestResult, BasicTestResult from mjtest.test.tests import TestCase, BasicDiffTestResult, BasicTestResult
from mjtest.util.shell import SigKill
_LOG = logging.getLogger("exec_tests") _LOG = logging.getLogger("exec_tests")
...@@ -54,6 +55,9 @@ class JavaExecTest(BasicSyntaxTest): ...@@ -54,6 +55,9 @@ class JavaExecTest(BasicSyntaxTest):
if self.type == self.MODE and self.env.mode == self.MODE: if self.type == self.MODE and self.env.mode == self.MODE:
return BasicDiffTestResult(self, rtcode, out, err.decode(), exp_out) return BasicDiffTestResult(self, rtcode, out, err.decode(), exp_out)
return BasicTestResult(self, rtcode, out.decode(), err.decode()) return BasicTestResult(self, rtcode, out.decode(), err.decode())
except SigKill as sig:
os.chdir(cwd)
return BasicTestResult(self, sig.retcode, "", exp_out, sig.name)
except: except:
os.chdir(cwd) os.chdir(cwd)
raise raise
......
...@@ -362,7 +362,8 @@ Return code: {} ...@@ -362,7 +362,8 @@ Return code: {}
class BasicDiffTestResult(BasicTestResult): class BasicDiffTestResult(BasicTestResult):
def __init__(self, test_case: TestCase, error_code: int, output: str, error_output: str, expected_output: str): def __init__(self, test_case: TestCase, error_code: int, output: str, error_output: str, expected_output: str,
short_error_message: str = None):
super().__init__(test_case, error_code, output, error_output) super().__init__(test_case, error_code, output, error_output)
self.expected_output = expected_output self.expected_output = expected_output
self._is_output_correct = self.expected_output.strip() == self.output.strip() self._is_output_correct = self.expected_output.strip() == self.output.strip()
...@@ -371,6 +372,7 @@ class BasicDiffTestResult(BasicTestResult): ...@@ -371,6 +372,7 @@ class BasicDiffTestResult(BasicTestResult):
elif self.succeeded() and self.test_case.should_succeed(): elif self.succeeded() and self.test_case.should_succeed():
self.add_additional_text("Diff[expected output, actual output]", self._output_diff()) self.add_additional_text("Diff[expected output, actual output]", self._output_diff())
self.add_additional_text("Expected output", self.expected_output) self.add_additional_text("Expected output", self.expected_output)
self.short_error_message = short_error_message
#self.add_additional_text("Actual output", self.output) #self.add_additional_text("Actual output", self.output)
def is_correct(self): def is_correct(self):
...@@ -389,6 +391,8 @@ class BasicDiffTestResult(BasicTestResult): ...@@ -389,6 +391,8 @@ class BasicDiffTestResult(BasicTestResult):
if self.is_correct(): if self.is_correct():
return "correct" return "correct"
else: else:
if self.short_error_message:
return self.short_error_message
if not self.succeeded() and not self.test_case.should_succeed() and not self._contains_error_str: if not self.succeeded() and not self.test_case.should_succeed() and not self._contains_error_str:
return "the error output doesn't contain the word \"error\"" return "the error output doesn't contain the word \"error\""
if self.succeeded() and self.test_case.should_succeed(): if self.succeeded() and self.test_case.should_succeed():
......
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