Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject absolute paths into "expected output" files #157

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions tests-system/run_tool_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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__":
Expand Down
Loading