From 005898ca93f344a6e859b3dbb3b5eb53366add46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Fertyk?= Date: Mon, 11 Dec 2023 21:43:37 +0100 Subject: [PATCH] Setup Hello World exercise --- .github/workflows/lint.yml | 20 +++++++++ .github/workflows/test.yml | 12 ++---- bin/verify-exercises | 42 +++++++++++-------- config.json | 18 ++++++-- .../hello-world/.docs/instructions.md | 16 +++++++ .../practice/hello-world/.meta/config.json | 22 ++++++++++ .../practice/hello-world/.meta/example.gd | 2 + .../practice/hello-world/.meta/tests.toml | 13 ++++++ exercises/practice/hello-world/hello_world.gd | 2 + .../practice/hello-world/hello_world_test.gd | 2 + 10 files changed, 120 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 exercises/practice/hello-world/.docs/instructions.md create mode 100644 exercises/practice/hello-world/.meta/config.json create mode 100644 exercises/practice/hello-world/.meta/example.gd create mode 100644 exercises/practice/hello-world/.meta/tests.toml create mode 100644 exercises/practice/hello-world/hello_world.gd create mode 100644 exercises/practice/hello-world/hello_world_test.gd diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..9217f50 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +name: GDScript / Lint + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: Setup gdtoolkit + uses: Scony/godot-gdscript-toolkit@09af1747fd66629af601b1f14d1ac24203358686 + + - name: Lint + run: gdlint exercises diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8f5b1a..8ae56a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ # Requires scripts: # - bin/test -name: / Test +name: GDScript / Test on: push: @@ -23,17 +23,13 @@ on: jobs: ci: - runs-on: + runs-on: ubuntu-22.04 + container: + image: exercism/gdscript-test-runner steps: - name: Checkout repository uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - name: Use - uses: - - - name: Install project dependencies - run: - - name: Verify all exercises run: bin/verify-exercises diff --git a/bin/verify-exercises b/bin/verify-exercises index 8d31328..18e83e2 100755 --- a/bin/verify-exercises +++ b/bin/verify-exercises @@ -1,28 +1,34 @@ #!/usr/bin/env bash -# Synopsis: -# Test the track's exercises. -# -# At a minimum, this file must check if the example/exemplar solution of each -# Practice/Concept Exercise passes the exercise's tests. -# -# To check this, you usually have to (temporarily) replace the exercise's solution files -# with its exemplar/example files. -# -# If your track uses skipped tests, make sure to (temporarily) enable these tests -# before running the tests. -# -# The path to the solution/example/exemplar files can be found in the exercise's -# .meta/config.json file, or possibly inferred from the exercise's directory name. +temp_dir_base=$(mktemp -d) +echo $(godot --version) -# Example: -# ./bin/test +run_test() { + slug=$(basename $1) + temp_dir=${temp_dir_base}/${slug} + 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)" + 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} + 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 + # Check status + test_status="$(jq -r '.status' $temp_dir/results.json)" + if [ "$test_status" != "pass" ]; then + echo "Tests for $slug have failed:" + 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 echo "Checking $(basename "${concept_exercise_dir}") exercise..." - # TODO: run command to verify that the exemplar solution passes the tests + run_test $concept_exercise_dir fi done @@ -30,6 +36,6 @@ done for practice_exercise_dir in ./exercises/practice/*/; do if [ -d $practice_exercise_dir ]; then echo "Checking $(basename "${practice_exercise_dir}") exercise..." - # TODO: run command to verify that the example solution passes the tests + run_test $practice_exercise_dir fi done diff --git a/config.json b/config.json index dfce2a0..272b2f2 100644 --- a/config.json +++ b/config.json @@ -4,17 +4,20 @@ "active": false, "status": { "concept_exercises": false, - "test_runner": false, + "test_runner": true, "representer": false, "analyzer": false }, "blurb": "TODO: add blurb", "version": 3, "online_editor": { - "indent_style": "space", + "indent_style": "tab", "indent_size": 4, "highlightjs_language": "gdscript" }, + "test_runner": { + "average_run_time": 10 + }, "files": { "solution": ["%{snake_slug}.gd"], "test": ["%{snake_slug}_test.gd"], @@ -23,7 +26,16 @@ }, "exercises": { "concept": [], - "practice": [] + "practice": [ + { + "uuid": "1adfc420-46f2-4d5b-93a3-165ede1fcd9f", + "slug": "hello-world", + "name": "Hello World", + "practices": [], + "prerequisites": [], + "difficulty": 1 + } + ] }, "concepts": [], "key_features": [], diff --git a/exercises/practice/hello-world/.docs/instructions.md b/exercises/practice/hello-world/.docs/instructions.md new file mode 100644 index 0000000..c9570e4 --- /dev/null +++ b/exercises/practice/hello-world/.docs/instructions.md @@ -0,0 +1,16 @@ +# Instructions + +The classical introductory exercise. +Just say "Hello, World!". + +["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment. + +The objectives are simple: + +- Modify the provided code so that it produces the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program diff --git a/exercises/practice/hello-world/.meta/config.json b/exercises/practice/hello-world/.meta/config.json new file mode 100644 index 0000000..0a09605 --- /dev/null +++ b/exercises/practice/hello-world/.meta/config.json @@ -0,0 +1,22 @@ +{ + "authors": [ + "pfertyk" + ], + "contributors": [ + "BNAndras" + ], + "files": { + "solution": [ + "hello_world.gd" + ], + "test": [ + "hello_world_test.gd" + ], + "example": [ + ".meta/example.gd" + ] + }, + "blurb": "The classical introductory exercise. Just say \"Hello, World!\".", + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/exercises/practice/hello-world/.meta/example.gd b/exercises/practice/hello-world/.meta/example.gd new file mode 100644 index 0000000..ac88163 --- /dev/null +++ b/exercises/practice/hello-world/.meta/example.gd @@ -0,0 +1,2 @@ +func hello(): + return "Hello, World!" diff --git a/exercises/practice/hello-world/.meta/tests.toml b/exercises/practice/hello-world/.meta/tests.toml new file mode 100644 index 0000000..73466d6 --- /dev/null +++ b/exercises/practice/hello-world/.meta/tests.toml @@ -0,0 +1,13 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[af9ffe10-dc13-42d8-a742-e7bdafac449d] +description = "Say Hi!" diff --git a/exercises/practice/hello-world/hello_world.gd b/exercises/practice/hello-world/hello_world.gd new file mode 100644 index 0000000..1338b51 --- /dev/null +++ b/exercises/practice/hello-world/hello_world.gd @@ -0,0 +1,2 @@ +func hello(): + return "Goodbye, Mars!" diff --git a/exercises/practice/hello-world/hello_world_test.gd b/exercises/practice/hello-world/hello_world_test.gd new file mode 100644 index 0000000..5655ada --- /dev/null +++ b/exercises/practice/hello-world/hello_world_test.gd @@ -0,0 +1,2 @@ +func test_hello_world(solution_script): + return ["Hello, World!", solution_script.hello()]