Skip to content

Commit

Permalink
Ensure stdin ends with a newline
Browse files Browse the repository at this point in the history
This is needed for the here-doc to display correctly.
  • Loading branch information
niknetniko committed Dec 20, 2023
1 parent 042890e commit eeb408d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion tested/dsl/translate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ class ReturnOracle:
)


def _ensure_trailing_newline(text: str) -> str:
if text[-1] != "\n":
return text + "\n"
else:
return text

Check warning on line 97 in tested/dsl/translate_parser.py

View check run for this annotation

Codecov / codecov/patch

tested/dsl/translate_parser.py#L97

Added line #L97 was not covered by tests


def _parse_yaml_value(loader: yaml.Loader, node: yaml.Node) -> Any:
if isinstance(node, yaml.MappingNode):
result = loader.construct_mapping(node)
Expand Down Expand Up @@ -442,7 +449,7 @@ def _convert_testcase(testcase: YamlDict, context: DslContext) -> Testcase:
else:
if "stdin" in testcase:
assert isinstance(testcase["stdin"], str)
stdin = TextData(data=testcase["stdin"])
stdin = TextData(data=_ensure_trailing_newline(testcase["stdin"]))
else:
stdin = EmptyChannel.NONE
arguments = testcase.get("arguments", [])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dsl_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_parse_one_tab_ctx():
assert len(context.testcases) == 1
tc = context.testcases[0]
assert tc.is_main_testcase()
assert tc.input.stdin.data == "Input string"
assert tc.input.stdin.data == "Input string\n"
assert tc.input.arguments == ["--arg", "argument"]
assert tc.output.stderr.data == "Error string"
assert tc.output.stdout.data == "Output string"
Expand Down

0 comments on commit eeb408d

Please sign in to comment.