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

Don't use .sh extension for Bash submission #468

Merged
merged 1 commit into from
Nov 27, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tested/languages/bash/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Conventionable,
NamingConventions,
submission_file,
submission_name,
)
from tested.serialisation import Statement, Value

Expand Down Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions tested/languages/bash/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tested/languages/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Conventionable,
NamingConventions,
conventionalize_namespace,
submission_name,
)
from tested.serialisation import FunctionCall, Statement, Value

Expand Down Expand Up @@ -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]:
"""
Expand Down
2 changes: 1 addition & 1 deletion tested/languages/conventionalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tested/languages/javascript/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
BasicSequenceTypes,
BasicStringTypes,
)
from tested.languages.conventionalize import submission_file
from tested.languages.preparation import (
PreparedContext,
PreparedExecutionUnit,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_stacktrace_cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<code>:1: d: opdracht niet gevonden\n"
actual = language_config.cleanup_stacktrace(original)
Expand All @@ -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 = """
Expand Down
Loading