From f17b62b1d1c6bdd11a3fc233b23040f13cf067b4 Mon Sep 17 00:00:00 2001 From: Johannes Bechberger Date: Mon, 31 Oct 2016 20:08:01 +0100 Subject: [PATCH] Improve .java test type --- README.mdwn | 2 +- mjtest/test/syntax_tests.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.mdwn b/README.mdwn index d985d14..14a47e4 100644 --- a/README.mdwn +++ b/README.mdwn @@ -39,7 +39,7 @@ Test types for the syntax mode .java - If javac accepts the syntax (and semantic) of the file then the MiniJava compiler + If javac accepts the syntax of the file then the MiniJava compiler should accept its syntax too. diff --git a/mjtest/test/syntax_tests.py b/mjtest/test/syntax_tests.py index 6947b1c..ca4d88b 100644 --- a/mjtest/test/syntax_tests.py +++ b/mjtest/test/syntax_tests.py @@ -32,22 +32,28 @@ class JavaCompileTest(BasicSyntaxTest): """ FILE_ENDINGS = [".java"] + SYNTAX_TEST = True def __init__(self, env: Environment, type: str, file: str): super().__init__(env, type, file) tmp_dir = self.env.create_tmpdir() _, self.javac_err, self.javac_rtcode = \ - self.env.run_command("javac", path.relpath(file), "-d", tmp_dir) + self.env.run_command("javac", path.relpath(file), "-d", tmp_dir, "-verbose") + self.javac_err = self.javac_err.decode() # type: str shutil.rmtree(tmp_dir, ignore_errors=True) - self._should_succeed = self.javac_rtcode == 0 + self._should_succeed = self._is_file_syntactically_correct() if self.SYNTAX_TEST else self.javac_rtcode == 0 - def short_name(self) -> str: - return path.basename(self.file) + def _is_file_syntactically_correct(self): + return self.javac_rtcode == 0 or "META-INF" in self.javac_err + + def _is_file_semantically_correct(self): + return self.javac_rtcode == 0 def run(self) -> BasicTestResult: ret = super().run() - ret.add_additional_text("javac error output", self.javac_err.decode()) + ret.add_additional_text("javac (verbose) error output", self.javac_err) ret.add_additional_text_line("javac return code", str(self.javac_rtcode)) + ret.add_additional_text_line("Is syntax correct? ", str(self._is_file_syntactically_correct())) return ret TestCase.TEST_CASE_CLASSES[TestMode.syntax].append(JavaCompileTest) -- GitLab