diff --git a/tests-system/run_tool_tests.py b/tests-system/run_tool_tests.py index 8a133f7..064125d 100644 --- a/tests-system/run_tool_tests.py +++ b/tests-system/run_tool_tests.py @@ -1,4 +1,5 @@ import sys +from posixpath import normpath from os import scandir, DirEntry, remove from os.path import basename, dirname, join from pathlib import Path @@ -31,6 +32,11 @@ def __init__(self, test_case_path: str): self._expected_lobster_output_file_name = \ self._get_expected_lobster_output_file_name() + @property + def test_case_path(self) -> str: + """Returns the path to the directory which contains the test case""" + return self._test_case_path + @property def expected_lobster_output_file_name(self) -> str: return self._expected_lobster_output_file_name @@ -185,18 +191,27 @@ def _compare_results(setup: TestSetup, completed_process: CompletedProcess): with open(expected, "r", encoding="UTF-8") as expected_lobster_file: try: with open(actual, "r", encoding="UTF-8") as actual_lobster_file: - # Note: we replace Windows-like slashes \\ with one / in order to be - # able to compare the actual output on all OS against the expected - # output on Linux - assert actual_lobster_file.read().replace("\\\\", "/") \ - == expected_lobster_file.read(), \ + # Before comparing the actual text with the expected text, we do the + # following replacements: + # a) Replace Windows-like slashes \\ with / in order to be able to + # compare the actual output on all OS against the expected output on + # Linux + # b) Replace the fixed string TEST_CASE_PATH with the absolute path to + # the current test case directory. This is necessary for tools like + # lobster-cpptest which write absolute paths into their *.lobster + # output files. + modified_actual = actual_lobster_file.read().replace("\\\\", "/") + modified_expected = expected_lobster_file.read().replace( + "TEST_CASE_PATH", setup.test_case_path + ) + assert modified_actual == modified_expected, \ "Actual *.lobster file differs from expectation!" except FileNotFoundError as ex: assert True, f"File {ex.filename} was not generated by the tool under test!" def _get_directories( - start_directory: str, + start_directory: Path, startswith: Optional[str] = None, ) -> Iterator[DirEntry]: """Returns DirEntry instances for each subdirectory found in the given start @@ -225,7 +240,7 @@ def _delete_generated_files(setup: TestSetup): remove(generated) -def _run_tests(directory: str, tool: str) -> int: +def _run_tests(directory: Path, tool: str) -> int: """Runs all system tests in the given folder for the specified tool. :param directory: the path to the directory containing all test cases @@ -264,7 +279,7 @@ def _get_tool(test_dir: str) -> str: to the tool name :param test_dir: The path containing the requirements-based tests """ - return join("../../../../../", basename(test_dir)) + return normpath(Path(join("../", basename(test_dir))).absolute()) if __name__ == "__main__":