Skip to content

Commit

Permalink
Fix non-reported exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Sep 4, 2023
1 parent ebacf1e commit c57cf38
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
17 changes: 10 additions & 7 deletions tested/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
from tested.main import run
from tested.testsuite import ExecutionMode, SupportedLanguage

exercise_dir = "/home/niko/Ontwikkeling/universal-judge/tests/exercises/echo-function"
exercise_dir = "/home/niko/Ontwikkeling/CG-Dodona/reeks09/rebussen oplossen/"

Check warning on line 16 in tested/manual.py

View check run for this annotation

Codecov / codecov/patch

tested/manual.py#L16

Added line #L16 was not covered by tests


def read_config() -> DodonaConfig:
"""Read the configuration from stdout"""
return DodonaConfig(
memory_limit=536870912,
time_limit=60,
programming_language=SupportedLanguage("haskell"),
programming_language=SupportedLanguage("bash"),
natural_language="nl",
resources=Path(exercise_dir, "evaluation"),
source=Path(exercise_dir, "solution/correct.hs"),
source=Path("test.sh"),
judge=Path("."),
workdir=Path("workdir"),
test_suite="one-language-literals.yaml",
test_suite="tests.yaml",
options=Options(
allow_fallback=False,
mode=ExecutionMode.PRECOMPILATION,
linter=False,
),
)
Expand All @@ -57,13 +55,18 @@ def read_config() -> DodonaConfig:
config.workdir.mkdir(exist_ok=True)

# Delete content in work dir
# noinspection PyTypeChecker
for root, dirs, files in os.walk(config.workdir):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d), ignore_errors=True)

# Copy existing files to workdir if needed.
if Path(exercise_dir, "workdir").is_dir():
shutil.copytree(

Check warning on line 66 in tested/manual.py

View check run for this annotation

Codecov / codecov/patch

tested/manual.py#L65-L66

Added lines #L65 - L66 were not covered by tests
Path(exercise_dir, "workdir"), config.workdir, dirs_exist_ok=True
)

start = time.time()
run(config, sys.stdout)
end = time.time()
Expand Down
18 changes: 15 additions & 3 deletions tested/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def get_used_features(self) -> FeatureSet:
FileOutput = FileOutputChannel | IgnoredChannel
ExceptionOutput = ExceptionOutputChannel | SpecialOutputChannel
ValueOutput = ValueOutputChannel | SpecialOutputChannel
ExitOutput = ExitCodeOutputChannel | IgnoredChannel
ExitOutput = ExitCodeOutputChannel | IgnoredChannel | EmptyChannel


@define
Expand All @@ -411,7 +411,8 @@ class Output(WithFeatures):
file: FileOutput = IgnoredChannel.IGNORED
exception: ExceptionOutput = EmptyChannel.NONE
result: ValueOutput = EmptyChannel.NONE
exit_code: ExitOutput = IgnoredChannel.IGNORED
# This default value is adjusted later, based on the position of the output.
exit_code: ExitOutput = EmptyChannel.NONE

def get_used_features(self) -> FeatureSet:
return combine_features(
Expand Down Expand Up @@ -583,6 +584,14 @@ class Context(WithFeatures, WithFunctions):
after: Code = field(factory=dict)
description: Optional[str] = None

def __attrs_post_init__(self):
# Fix the default value of the exit code outputs.
for non_last_testcase in self.testcases[:-1]:
if non_last_testcase.output.exit_code == EmptyChannel.NONE:
non_last_testcase.output.exit_code = IgnoredChannel.IGNORED
if (last_testcase := self.testcases[-1]).output.exit_code == EmptyChannel.NONE:
last_testcase.output.exit_code = ExitCodeOutputChannel()

@testcases.validator # type: ignore
def check_testcases(self, _, value: List[Testcase]):
# Check that only the first testcase has a main call.
Expand All @@ -592,7 +601,10 @@ def check_testcases(self, _, value: List[Testcase]):

# Check that only the last testcase has an exit code check.
for non_last_testcase in value[1:-1]:
if non_last_testcase.output.exit_code != IgnoredChannel.IGNORED:
if non_last_testcase.output.exit_code not in (
IgnoredChannel.IGNORED,
EmptyChannel.NONE,
):
raise ValueError("Only the last testcase may have an exit code check.")

def get_functions(self) -> Iterable[FunctionCall]:
Expand Down

0 comments on commit c57cf38

Please sign in to comment.