Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ RUN wget https://github.com/godotengine/godot/releases/download/4.4.1-stable/God
mv Godot_v4.4.1-stable_linux.x86_64 /usr/bin/godot && \
rm Godot_v4.4.1-stable_linux.x86_64.zip

WORKDIR /opt/test-runner
WORKDIR /opt/exercism/gdscript/test-runner
COPY . .
ENTRYPOINT ["/opt/test-runner/bin/run.sh"]
ENTRYPOINT ["/opt/exercism/gdscript/test-runner/bin/run.sh"]
8 changes: 4 additions & 4 deletions bin/run-tests-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ docker run \
--rm \
--network none \
--read-only \
--mount type=bind,src="${PWD}/tests",dst=/opt/test-runner/tests \
--mount type=bind,src="${PWD}/tests",dst=/opt/exercism/gdscript/test-runner/tests \
--mount type=tmpfs,dst=/tmp \
--volume "${PWD}/bin/run-tests.sh:/opt/test-runner/bin/run-tests.sh" \
--workdir /opt/test-runner \
--entrypoint /opt/test-runner/bin/run-tests.sh \
--volume "${PWD}/bin/run-tests.sh:/opt/exercism/gdscript/test-runner/bin/run-tests.sh" \
--workdir /opt/exercism/gdscript/test-runner \
--entrypoint /opt/exercism/gdscript/test-runner/bin/run-tests.sh \
exercism/test-runner
31 changes: 9 additions & 22 deletions bin/test-local-gdscript-solution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,25 @@ missing_gd_msg="Normally, the exercise subdirectory created by the exercism down
general_help_msg="Please see https://exercism.org/docs/tracks/gdscript/installation for details."
if [ ! -f "${slug//-/_}_test.gd" ]; then
echo "Missing test file: ${slug//-/_}_test.gd"
echo $missing_gd_msg
echo $general_help_msg
echo "$missing_gd_msg"
echo "$general_help_msg"
exit 1
fi
if [ ! -f "${slug//-/_}.gd" ]; then
echo "Missing solution file: ${slug//-/_}.gd"
echo $missing_gd_msg
echo $general_help_msg
echo "$missing_gd_msg"
echo "$general_help_msg"
exit 1
fi
if [ ! -f "/opt/exercism/gdscript/test-runner/bin/run.sh" ]; then
echo "Missing test runner file: /opt/exercism/gdscript/test-runner/bin/run.sh"
echo $general_help_msg
if [ ! -f "/opt/exercism/gdscript/test-runner/bin/test_runner.gd" ]; then
echo "Missing test runner file: /opt/exercism/gdscript/test-runner/bin/test_runner.gd"
echo "$general_help_msg"
exit 1
fi

solution_dir="$(pwd)"
output_dir="${solution_dir}/.test-output"
results_file="${output_dir}/results.json"
mkdir -p "${output_dir}"

(cd /opt/exercism/gdscript/test-runner && bin/run.sh "$slug" "$solution_dir" "$output_dir") || {
(cd /opt/exercism/gdscript/test-runner && godot --headless -s bin/test_runner.gd -- "${slug}" "${solution_dir}") || {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to use {} maybe use them consistently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! My bad, fixed. ✔

echo "Test runner script failed."
exit 1
}

test_status="$(jq -r '.status' "${results_file}")"
if [ "$test_status" != "pass" ]; then
echo "Tests for $slug have failed:"
cat "${results_file}"
exit 1
else
echo
echo "Tests for $slug passed!"
fi
}
17 changes: 11 additions & 6 deletions bin/test_runner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,26 @@ func parse_args() -> Error:
global variables, based on the given args:
* `solution_script_path`
* `test_suite_script_path`
* `output_dir_path`
* `output_dir_path` (optional for local test runner, required for standard JSON test runner behaviour)
"""
var args = OS.get_cmdline_user_args()

if len(args) != 3:
# This script still conforms to [1] but allows 2 arguments for a local test
# runner with non-JSON output to eliminate dependence on 'jq'
#
# [1] https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md#execution
if len(args) not in [2,3]:
push_error(
"The scrips needs exactly 3 arguments, was called with %s: %s" % [
"The script needs exactly 2 or exactly 3 arguments, was called with %s: %s" % [
len(args), str(args)
]
)
return ERR_INVALID_PARAMETER

var slug = args[0]
var solution_dir_path = args[1]
output_dir_path = args[2]
if len(args) == 3:
output_dir_path = args[2]

# Test folders use dashes, but test files use underscores
var gdscript_path = solution_dir_path.path_join(slug.replace("-", "_"))
Expand Down Expand Up @@ -127,7 +132,7 @@ func load_solution_script() -> Error:
"message": "The solution file could not be parsed.",
"tests": [],
}
file_utils.write_results_file(results, output_dir_path)
file_utils.output_results(results, output_dir_path)
return ERR_PARSE_ERROR

return OK
Expand Down Expand Up @@ -170,4 +175,4 @@ func run_tests() -> void:
results["status"] = "fail"
break

file_utils.write_results_file(results, output_dir_path)
file_utils.output_results(results, output_dir_path)
31 changes: 31 additions & 0 deletions bin/utils/file_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,37 @@ func load_script(script_path: String) -> Object:
return script


func output_results(results: Dictionary, output_dir_path: String) -> Error:
"""
If output_dir_path is empty, outputs friendly-formatted test results to
stdout.

Otherwise, writes JSON results to results.json in the given path.
"""
if output_dir_path == "":
return print_friendly_results(results)
else:
return write_results_file(results, output_dir_path)


func print_friendly_results(results: Dictionary) -> Error:
"""
Prints rich results to stdout.
"""
var rich_results = [""]
if results.status == "pass":
rich_results.push_back("[color=yellow]Exercise passed! Nicely done![/color]")
else:
rich_results.push_back("Exercise has at least one failed test:")
for test in results.tests:
if test.status == "pass":
rich_results.push_back(" %s [color=yellow]passed ✔[/color]" % test.name)
else:
rich_results.push_back(" %s [color=pink]failed: %s[/color]" % [test.name, test.message])
print_rich("\n".join(rich_results))
return OK


func write_results_file(results: Dictionary, output_dir_path: String) -> Error:
"""
Saves a dictionary as a `results.json` file in the output directory. The file
Expand Down