Commit f17b62b1 authored by Johannes Bechberger's avatar Johannes Bechberger
Browse files

Improve .java test type

parent fbdfc829
......@@ -39,7 +39,7 @@ Test types for the syntax mode
<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>
......@@ -32,22 +32,28 @@ class JavaCompileTest(BasicSyntaxTest):
FILE_ENDINGS = [".java"]
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
Supports Markdown
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