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

Issue 266: Fix generation of library files #271

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
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
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