Commit 70ac960b authored by Johannes Bechberger's avatar Johannes Bechberger

Start implementing the `--compile-firm` mode

parent eb0f021b
...@@ -23,6 +23,8 @@ class TestMode: ...@@ -23,6 +23,8 @@ class TestMode:
semantic = "semantic" semantic = "semantic"
comile_firm = "compile-firm"
exec = "exec" exec = "exec"
USE_TESTS_OF_OTHER = { USE_TESTS_OF_OTHER = {
...@@ -30,7 +32,7 @@ class TestMode: ...@@ -30,7 +32,7 @@ class TestMode:
} }
""" All 'success' tests of the n.th mode can used as 'success' tests for the n-1.th mode""" """ All 'success' tests of the n.th mode can used as 'success' tests for the n-1.th mode"""
TEST_MODES = [TestMode.lexer, TestMode.syntax, TestMode.ast, TestMode.semantic, TestMode.exec] TEST_MODES = [TestMode.lexer, TestMode.syntax, TestMode.ast, TestMode.semantic, TestMode.comile_firm, TestMode.exec]
class Environment: class Environment:
...@@ -118,7 +120,8 @@ class Environment: ...@@ -118,7 +120,8 @@ class Environment:
TestMode.lexer: "--lextest", TestMode.lexer: "--lextest",
TestMode.syntax: "--parsetest", TestMode.syntax: "--parsetest",
TestMode.ast: "--print-ast", TestMode.ast: "--print-ast",
TestMode.semantic: "--check" TestMode.semantic: "--check",
TestMode.comile_firm: "--compile-firm"
}[mode] }[mode]
cmd = [self.mj_run_cmd, mode_flag] + list(args) cmd = [self.mj_run_cmd, mode_flag] + list(args)
return execute(cmd, timeout=self.timeout) return execute(cmd, timeout=self.timeout)
......
import logging
import os
import shutil
from os import path
import sys
from mjtest.environment import TestMode, Environment
from mjtest.test.syntax_tests import BasicSyntaxTest
from mjtest.test.tests import TestCase, BasicDiffTestResult, BasicTestResult
_LOG = logging.getLogger("exec_tests")
class JavaExecTest(BasicSyntaxTest):
"""
The MiniJava compiler should behave the same as javac
"""
FILE_ENDINGS = [".java"]
OUTPUT_FILE_ENDING = ".out"
MODE = TestMode.comile_firm
def __init__(self, env: Environment, type: str, file: str, preprocessed_file: str):
super().__init__(env, type, file, preprocessed_file)
self._expected_output_file = file + self.OUTPUT_FILE_ENDING
self._has_expected_output_file = path.exists(self._expected_output_file)
self._should_succeed = True
def run(self) -> BasicDiffTestResult:
base_filename = path.basename(self.file).split(".")[0]
tmp_dir = self.env.create_tmpdir()
shutil.copy(self.preprocessed_file, path.join(tmp_dir, base_filename + ".java"))
cwd = os.getcwd()
os.chdir(tmp_dir)
exp_out = None
if not self._has_expected_output_file:
_, _, javac_rtcode = \
self.env.run_command("javac", base_filename + ".java")
if javac_rtcode != 0:
_LOG.error("File \"{}\" isn't valid Java".format(self.preprocessed_file))
raise InterruptedError()
exp_out, _, _ = \
self.env.run_command("java", base_filename)
if self._has_expected_output_file and self.type == self.MODE and self.env.mode == self.MODE:
with open(self._expected_output_file, "r") as f:
exp_out = f.read()
_, err, rtcode = self.env.run_mj_command(self.MODE, base_filename + ".java")
out, _, _ = self.env.run_command(base_filename)
os.chdir(cwd)
if self.type == self.MODE and self.env.mode == self.MODE:
return BasicDiffTestResult(self, rtcode, out.decode(), err.decode(), exp_out)
return BasicTestResult(self, rtcode, out.decode(), err.decode())
TestCase.TEST_CASE_CLASSES[TestMode.comile_firm].append(JavaExecTest)
\ No newline at end of file
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