From 9de0c1d27efcd848befe23fbf3eb9ff4fcb26118 Mon Sep 17 00:00:00 2001 From: Niko Strijbol Date: Mon, 27 Nov 2023 15:24:34 +0100 Subject: [PATCH] Don't use .sh extension for Bash submission --- tested/languages/bash/config.py | 7 +++++++ tested/languages/bash/generators.py | 5 +++-- tested/languages/config.py | 7 +++++++ tested/languages/conventionalize.py | 2 +- tested/languages/javascript/generators.py | 5 +++-- tests/test_stacktrace_cleaners.py | 6 +++--- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tested/languages/bash/config.py b/tested/languages/bash/config.py index e419c638..3cb40588 100644 --- a/tested/languages/bash/config.py +++ b/tested/languages/bash/config.py @@ -16,6 +16,7 @@ Conventionable, NamingConventions, submission_file, + submission_name, ) from tested.serialisation import Statement, Value @@ -50,6 +51,12 @@ def supported_constructs(self) -> set[Construct]: Construct.GLOBAL_VARIABLES, } + def is_source_file(self, file: Path) -> bool: + return file.suffix == "" + + def submission_file(self) -> str: + return submission_name(self) + def compilation(self, files: list[str]) -> CallbackResult: submission = submission_file(self) main_file = list(filter(lambda x: x == submission, files)) diff --git a/tested/languages/bash/generators.py b/tested/languages/bash/generators.py index 6c206c29..a1dfb5f0 100644 --- a/tested/languages/bash/generators.py +++ b/tested/languages/bash/generators.py @@ -2,6 +2,7 @@ from collections.abc import Callable from tested.datatypes import AdvancedStringTypes, BasicStringTypes +from tested.languages.conventionalize import submission_file from tested.languages.preparation import ( PreparedContext, PreparedExecutionUnit, @@ -200,7 +201,7 @@ def convert_execution_unit(pu: PreparedExecutionUnit) -> str: # Import the submission if there is no main call. if not ctx.context.has_main_testcase(): - result += f"{indent}source {pu.submission_name}.sh\n" + result += f"{indent}source {submission_file(pu.language)}\n" # Generate code for each testcase tc: PreparedTestcase @@ -210,7 +211,7 @@ def convert_execution_unit(pu: PreparedExecutionUnit) -> str: # Prepare command arguments if needed. if tc.testcase.is_main_testcase(): assert isinstance(tc.input, MainInput) - result += f"{indent}bash {pu.submission_name}.sh " + result += f"{indent}bash {submission_file(pu.language)} " result += " ".join(shlex.quote(s) for s in tc.input.arguments) + "\n" else: assert isinstance(tc.input, PreparedTestcaseStatement) diff --git a/tested/languages/config.py b/tested/languages/config.py index 64fb79f1..0bc5b1b6 100644 --- a/tested/languages/config.py +++ b/tested/languages/config.py @@ -19,6 +19,7 @@ Conventionable, NamingConventions, conventionalize_namespace, + submission_name, ) from tested.serialisation import FunctionCall, Statement, Value @@ -200,6 +201,12 @@ def with_extension(self, file_name: str) -> str: """ return f"{file_name}.{self.file_extension()}" + def submission_file(self) -> str: + """ + :return: The name of the submission. + """ + return self.with_extension(submission_name(self)) + @abstractmethod def initial_dependencies(self) -> list[str]: """ diff --git a/tested/languages/conventionalize.py b/tested/languages/conventionalize.py index a874137e..339bb2dc 100644 --- a/tested/languages/conventionalize.py +++ b/tested/languages/conventionalize.py @@ -425,7 +425,7 @@ def submission_file(language: "Language") -> str: """ :return: The file name of a submission. """ - return language.with_extension(submission_name(language)) + return language.submission_file() def selector_name(language: "Language") -> str: diff --git a/tested/languages/javascript/generators.py b/tested/languages/javascript/generators.py index af1dc8c3..2b44856d 100644 --- a/tested/languages/javascript/generators.py +++ b/tested/languages/javascript/generators.py @@ -11,6 +11,7 @@ BasicSequenceTypes, BasicStringTypes, ) +from tested.languages.conventionalize import submission_file from tested.languages.preparation import ( PreparedContext, PreparedExecutionUnit, @@ -132,8 +133,8 @@ def _generate_internal_context(ctx: PreparedContext, pu: PreparedExecutionUnit) # Import the submission if there is no main call. if not ctx.context.has_main_testcase(): result += f""" - delete require.cache[require.resolve("./{pu.submission_name}.js")]; - const {pu.submission_name} = require("./{pu.submission_name}.js"); + delete require.cache[require.resolve("./{submission_file(pu.language)}")]; + const {pu.submission_name} = require("./{submission_file(pu.language)}"); """ # Generate code for each testcase diff --git a/tests/test_stacktrace_cleaners.py b/tests/test_stacktrace_cleaners.py index 96c7aa41..6c9228e7 100644 --- a/tests/test_stacktrace_cleaners.py +++ b/tests/test_stacktrace_cleaners.py @@ -203,7 +203,7 @@ def test_java_runtime_error(): def test_bash_runtime_error(): - original = "submission.sh: rule 1: d: opdracht niet gevonden\n" + original = "submission: rule 1: d: opdracht niet gevonden\n" language_config = get_language("test", "bash") expected = ":1: d: opdracht niet gevonden\n" actual = language_config.cleanup_stacktrace(original) @@ -212,8 +212,8 @@ def test_bash_runtime_error(): def test_bash_compilation_error(): original = """ - submission.sh: rule 1: syntaxfout nabij onverwacht symbool '(' - submission.sh: rule 1: `def isISBN10(code):' + submission: rule 1: syntaxfout nabij onverwacht symbool '(' + submission: rule 1: `def isISBN10(code):' """ language_config = get_language("test", "bash") expected = """