Commit f17b62b1 authored by Johannes Bechberger's avatar Johannes Bechberger

Improve .java test type

parent fbdfc829
...@@ -39,7 +39,7 @@ Test types for the syntax mode ...@@ -39,7 +39,7 @@ Test types for the syntax mode
</tr> </tr>
<tr> <tr>
<td><code>.java</code> <td><code>.java</code>
<td>If <code>javac</code> accepts the syntax (and semantic) of the file then the MiniJava compiler <td>If <code>javac</code> accepts the syntax of the file then the MiniJava compiler
should accept its syntax too.</td> should accept its syntax too.</td>
</tr> </tr>
</table> </table>
...@@ -32,22 +32,28 @@ class JavaCompileTest(BasicSyntaxTest): ...@@ -32,22 +32,28 @@ class JavaCompileTest(BasicSyntaxTest):
""" """
FILE_ENDINGS = [".java"] FILE_ENDINGS = [".java"]
def __init__(self, env: Environment, type: str, file: str): def __init__(self, env: Environment, type: str, file: str):
super().__init__(env, type, file) super().__init__(env, type, file)
tmp_dir = self.env.create_tmpdir() tmp_dir = self.env.create_tmpdir()
_, self.javac_err, self.javac_rtcode = \ _, 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) 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: def _is_file_syntactically_correct(self):
return path.basename(self.file) 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: def run(self) -> BasicTestResult:
ret = super().run() 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("javac return code", str(self.javac_rtcode))
ret.add_additional_text_line("Is syntax correct? ", str(self._is_file_syntactically_correct()))
return ret return ret
TestCase.TEST_CASE_CLASSES[TestMode.syntax].append(JavaCompileTest) TestCase.TEST_CASE_CLASSES[TestMode.syntax].append(JavaCompileTest)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment