Skip to content

Commit

Permalink
Fix generation of library files
Browse files Browse the repository at this point in the history
Ref. #266
  • Loading branch information
treiher committed Jul 23, 2020
1 parent 5ef7f95 commit 903b80d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 3 additions & 3 deletions rflx/generator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ def write_library_files(self, directory: Path) -> None:
for template_filename in const.LIBRARY_FILES:
self.__check_template_file(template_filename)

prefix = file_name(self.prefix)
filename = f"{prefix}-{template_filename}"
prefix = f"{self.prefix}." if self.prefix else ""
filename = f"{file_name(prefix)}{template_filename}"

with open(self.template_dir / Path(template_filename)) as template_file:
create_file(
Path(directory) / Path(filename),
self.__license_header()
+ "".join(
l.format(prefix=f"{self.prefix}.")
l.format(prefix=prefix)
for l in template_file
if " -- WORKAROUND" not in l
),
Expand Down
7 changes: 7 additions & 0 deletions tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def test_library_files(tmp_path: Path) -> None:
assert library_file.read() == expected_file.read(), filename


def test_library_files_no_prefix(tmp_path: Path) -> None:
generator = Generator("", reproducible=True)
generator.write_library_files(tmp_path)
for filename in const.LIBRARY_FILES:
assert (tmp_path / filename).exists()


def test_top_level_package(tmp_path: Path) -> None:
generator = Generator("RFLX", reproducible=True)
generator.write_top_level_package(tmp_path)
Expand Down
16 changes: 10 additions & 6 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ def assert_equal_code(spec_files: List[str]) -> None:
assert unit.adb == f.read(), filename


def assert_compilable_code(spec_files: List[str]) -> None:
def assert_compilable_code(spec_files: List[str], prefix: str = None) -> None:
parser = Parser()

for spec_file in spec_files:
parser.parse(Path(spec_file))

_assert_compilable_code(parser)
_assert_compilable_code(parser, prefix)


def assert_compilable_code_string(specification: str) -> None:
def assert_compilable_code_string(specification: str, prefix: str = None) -> None:
parser = Parser()
parser.parse_string(specification)

_assert_compilable_code(parser)
_assert_compilable_code(parser, prefix)


def _assert_compilable_code(parser: Parser) -> None:
def _assert_compilable_code(parser: Parser, prefix: str = None) -> None:
model = parser.create_model()

generator = Generator("RFLX")
generator = Generator(prefix if prefix else "RFLX")
generator.generate(model)

with TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -114,6 +114,10 @@ def test_feature_integeration() -> None:
assert_compilable_code([f"{TESTDIR}/feature_integration.rflx"])


def test_no_prefix() -> None:
assert_compilable_code([f"{SPECDIR}/tlv.rflx"], prefix="")


def test_type_name_equals_package_name() -> None:
spec = """
package Test is
Expand Down

0 comments on commit 903b80d

Please sign in to comment.