Skip to content

Commit

Permalink
Wrote test for line-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentBlanckaert committed Nov 15, 2024
1 parent 740e99d commit c949ded
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tested/dsl/ast_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def extract_comment(code: str) -> str:
comment = ""
tokens = tuple(tokenize.generate_tokens(io.StringIO(code).readline))
if len(tokens) and tokens[-3].type == tokenize.COMMENT:
comment = tokens[-3].string.lstrip('#').strip()
comment = tokens[-3].string.lstrip("#").strip()
return comment


Expand Down
3 changes: 0 additions & 3 deletions tested/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
from tested.testsuite import parse_test_suite


import time


def run(config: DodonaConfig, judge_output: IO):
"""
Run the TESTed judge.
Expand Down
2 changes: 1 addition & 1 deletion tests/exercises/global/evaluation/plan.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- tab: "Global variable"
testcases:
- expression: "GLOBAL_VAR"
- expression: "GLOBAL_VAR # The name of the global variable"
return: "GLOBAL"
description:
description: "Hallo"
Expand Down
29 changes: 29 additions & 0 deletions tests/test_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,35 @@ def test_global_variable_yaml(
assert updates.find_status_enum() == ["correct"]


@pytest.mark.parametrize(
"language, comment_start",
[
("bash", "#"),
("python", "#"),
("kotlin", "//"),
("csharp", "//"),
("java", "//"),
("c", "//"),
("javascript", "//"),
("haskell", "--"),
],
)
def test_global_variable_yaml(
language: str, comment_start: str, tmp_path: Path, pytestconfig: pytest.Config
):
conf = configuration(
pytestconfig, "global", language, tmp_path, "plan.yaml", "correct"
)
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
description = updates.find_next("start-testcase")

assert "description" in description and "description" in description["description"]
assert description["description"]["description"].endswith(
f"{comment_start} The name of the global variable"
)


@pytest.mark.parametrize("lang", EXCEPTION_LANGUAGES)
def test_generic_exception_wrong(
lang: str, tmp_path: Path, pytestconfig: pytest.Config
Expand Down

0 comments on commit c949ded

Please sign in to comment.