Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ Exercism exercises in GDScript.

## Testing

To set up for testing, clone https://github.com/exercism/gdscript-test-runner and move its contents to `/opt/test-runner`.
To set up for testing, clone https://github.com/exercism/gdscript-test-runner and move its contents to `/opt/exercism/gdscript/test-runner`:

```sh
git clone https://github.com/exercism/gdscript-test-runner.git
sudo mkdir -p /opt/exercism/gdscript/
sudo mv gdscript-test-runner/ /opt/exercism/gdscript/test-runner/
```

To test the exercises, run `./bin/verify-exercises`.
This command will iterate over all exercises and check to see if their exemplar/example implementation passes all the tests.
Expand Down
29 changes: 14 additions & 15 deletions bin/verify-exercises
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
#!/usr/bin/env bash

temp_dir_base=$(mktemp -d)
echo $(godot --version)
godot --version

run_test() {
slug=$(basename $1)
slug=$(basename "$1")
temp_dir=${temp_dir_base}/${slug}
mkdir -p ${temp_dir}
mkdir -p "${temp_dir}"
# Copy relevant files to the temp directory (replace solution with example)
solution_file_name="$(jq -r '.files.solution[0]' $1/.meta/config.json)"
Copy link
Member

Choose a reason for hiding this comment

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

Why are you not using the config.json? That's more reliable.

Copy link
Contributor Author

@codingthat codingthat Jul 5, 2025

Choose a reason for hiding this comment

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

For consistency with the preexisting test_runner.gd that this script indirectly calls:

	solution_script_path = gdscript_path + ".gd"
	test_suite_script_path = gdscript_path + "_test.gd"

Since that's already being assumed there, this seemed the most straightforward way to remove jq from this spot. As it currently is (and already had been before this PR), following config.json here but not in the test runner would make the test runner fail if an exercise deviated from this convention.

I see that the behavior in test_runner.gd is implied by the spec, because test_runner.gd normally wouldn't have access to config.json (especially if a tmp dir is used that doesn't contain it).

For consistency with other tracks, we could ditch bash entirely in favor of GDScript for verify-exercises — then we can have JSON parsing for free here. (That's what the Python track seems to do.)

Copy link
Member

Choose a reason for hiding this comment

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

Assumptions are precursors to bugs ;) But if that assumption is already baked in... 🤷

For consistency with other tracks, we could ditch bash entirely in favor of GDScript for verify-exercises — then we can have JSON parsing for free here. (That's what the Python track seems to do.)

If that's not too much work, it would be a nice improvement.

Copy link
Contributor Author

@codingthat codingthat Jul 5, 2025

Choose a reason for hiding this comment

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

@meatball133 I can do this but are you OK with that, or was there some reason verify-exercises needed to be a bash script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For consistency with other tracks, we could ditch bash entirely in favor of GDScript for verify-exercises — then we can have JSON parsing for free here. (That's what the Python track seems to do.)

If that's not too much work, it would be a nice improvement.

OK, it's converted ✔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still depends on exercism/gdscript-test-runner#54 to pass though.

test_file="$1/$(jq -r '.files.test[0]' $1/.meta/config.json)"
example_file="$1/$(jq -r '.files.example[0]' $1/.meta/config.json)"
cp ${test_file} ${temp_dir}
solution_file_name="$slug.gd"
test_file="${slug}_test.gd"
example_file=".meta/example.gd"
cp "${test_file}" "${temp_dir}"
cp ${example_file} "${temp_dir}/${solution_file_name}"
# Run the tests
(cd /opt/test-runner && bin/run.sh $slug $temp_dir $temp_dir) || exit 1
(cd /opt/exercism/gdscript/test-runner && bin/run.sh "$slug" "$temp_dir" "$temp_dir") || exit 1
# Check status
test_status="$(jq -r '.status' $temp_dir/results.json)"
if [ "$test_status" != "pass" ]; then
if [[ $(cat "$temp_dir"/results.json) =~ ' "status": "fail",' ]]; then
echo "Tests for $slug have failed:"
cat $temp_dir/results.json
cat "$temp_dir"/results.json
exit 1
fi
}

# Verify the Concept Exercises
for concept_exercise_dir in ./exercises/concept/*/; do
if [ -d $concept_exercise_dir ]; then
if [ -d "$concept_exercise_dir" ]; then
echo "Checking $(basename "${concept_exercise_dir}") exercise..."
run_test $concept_exercise_dir
run_test "$concept_exercise_dir"
fi
done

# Verify the Practice Exercises
for practice_exercise_dir in ./exercises/practice/*/; do
if [ -d $practice_exercise_dir ]; then
if [ -d "$practice_exercise_dir" ]; then
echo "Checking $(basename "${practice_exercise_dir}") exercise..."
run_test $practice_exercise_dir
run_test "$practice_exercise_dir"
fi
done
Loading