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

fix: not loading same component multiple times #176

Merged
merged 1 commit into from
Jan 31, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/selfextract.nim
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,12 @@ proc handleConfigLoad*(inpath: string) =

if not alreadyCached or replace:
let
lines = newEmbedded.splitLines()
useLine = "use " & module & " from \"" & base & "\""
withUse = newEmbedded & "\n" & useLine
withUse = if useLine in lines:
newEmbedded
else:
newEmbedded & "\n" & useLine
newEmbedded = withUse.strip()

if chalkConfig.loadConfig.getParamsViaStdin():
Expand Down
12 changes: 8 additions & 4 deletions tests/chalk/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,14 @@ def delete(self, artifact: Path) -> ChalkProgram:
log_level="error",
)

def dump(self, path: Path) -> ChalkProgram:
assert not path.is_file()
result = self.run(command="dump", params=[str(path)])
assert path.is_file()
def dump(self, path: Optional[Path] = None) -> ChalkProgram:
args: list[str] = []
if path is not None:
assert not path.is_file()
args = [str(path)]
result = self.run(command="dump", params=args)
if path is not None:
assert path.is_file()
return result

def load(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ def test_load_url(
)


def test_load_duplicate(
chalk_copy: Chalk,
server_chalkdust: str,
):
"""
even if same component is loaded multiple times, it should be referenced once
"""
for _ in range(4):
chalk_copy.load(
f"{server_chalkdust}/debug.c4m",
)
config = chalk_copy.dump()
assert len(config.text.splitlines()) == 1


# tests for configs that are found in the chalk search path
# these configs are NOT loaded directly into the binary
# as these configs are global across the system,
Expand Down