From 037062ca3a1d0d1075107df2345dcfa6e746a011 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 12:36:21 +0000 Subject: [PATCH 01/16] Appease shellcheck --- README.md | 8 +------- bin/run-tests.sh | 44 ++++++++++++++++++++++---------------------- bin/run.sh | 40 +++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index e875f60..56c65c8 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,7 @@ # Exercism Test Runner Template -This repository is a [template repository](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-template-repository) for creating [test runners][test-runners] for [Exercism][exercism] tracks. - ## Using the Test Runner Template -1. Ensure that your track has not already implemented a test runner. If there is, there will be a `https://github.com/exercism/-test-runner` repository (i.e. if your track's slug is `python`, the test runner repo would be `https://github.com/exercism/python-test-runner`) -2. Follow [GitHub's documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template) for creating a repository from a template repository - - Name your new repository based on your language track's slug (i.e. if your track is for Python, your test runner repo name is `python-test-runner`) -3. Remove this [Exercism Test Runner Template](#exercism-test-runner-template) section from the `README.md` file 4. Build the test runner, conforming to the [Test Runner interface specification](https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md). - Update the files to match your track's needs. At the very least, you'll need to update `bin/run.sh`, `Dockerfile` and the test solutions in the `tests` directory - Tip: look for `TODO:` comments to point you towards code that need updating @@ -15,7 +9,7 @@ This repository is a [template repository](https://help.github.com/en/github/cre Once you're happy with your test runner, [open an issue on the exercism/exercism](https://github.com/exercism/exercism/issues/new?assignees=&labels=&template=new-test-runner.md&title=%5BNew+Test+Runner%5D+) to request an official test runner repository for your track. -# Exercism TRACK_NAME_HERE Test Runner +# Exercism Gleam Test Runner The Docker image to automatically run tests on TRACK_NAME_HERE solutions submitted to [Exercism]. diff --git a/bin/run-tests.sh b/bin/run-tests.sh index ac7c9f2..d2a3cd0 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -15,28 +15,28 @@ exit_code=0 # Iterate over all test directories for test_dir in tests/*; do - test_dir_name=$(basename "${test_dir}") - test_dir_path=$(realpath "${test_dir}") - results_file_path="${test_dir_path}/results.json" - expected_results_file_path="${test_dir_path}/expected_results.json" - - bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" - - # OPTIONAL: Normalize the results file - # If the results.json file contains information that changes between - # different test runs (e.g. timing information or paths), you should normalize - # the results file to allow the diff comparison below to work as expected - # sed -i -E \ - # -e 's/Elapsed time: [0-9]+\.[0-9]+ seconds//g' \ - # -e "s~${test_dir_path}~/solution~g" \ - # "${results_file_path}" - - echo "${test_dir_name}: comparing results.json to expected_results.json" - diff "${results_file_path}" "${expected_results_file_path}" - - if [ $? -ne 0 ]; then - exit_code=1 - fi + test_dir_name=$(basename "${test_dir}") + test_dir_path=$(realpath "${test_dir}") + results_file_path="${test_dir_path}/results.json" + expected_results_file_path="${test_dir_path}/expected_results.json" + + bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" + + # OPTIONAL: Normalize the results file + # If the results.json file contains information that changes between + # different test runs (e.g. timing information or paths), you should normalize + # the results file to allow the diff comparison below to work as expected + # sed -i -E \ + # -e 's/Elapsed time: [0-9]+\.[0-9]+ seconds//g' \ + # -e "s~${test_dir_path}~/solution~g" \ + # "${results_file_path}" + + echo "${test_dir_name}: comparing results.json to expected_results.json" + + if ! diff "${results_file_path}" "${expected_results_file_path}" + then + exit_code=1 + fi done exit ${exit_code} diff --git a/bin/run.sh b/bin/run.sh index f1e8b78..61d18ec 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -17,8 +17,8 @@ # If any required arguments is missing, print the usage and exit if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then - echo "usage: ./bin/run.sh exercise-slug path/to/solution/folder/ path/to/output/directory/" - exit 1 + echo "usage: ./bin/run.sh exercise-slug path/to/solution/folder/ path/to/output/directory/" + exit 1 fi slug="$1" @@ -33,28 +33,26 @@ echo "${slug}: testing..." # Run the tests for the provided implementation file and redirect stdout and # stderr to capture it -test_output=$(false) -# TODO: substitute "false" with the actual command to run the test: -# test_output=$(command_to_run_tests 2>&1) - # Write the results.json file based on the exit code of the command that was # just executed that tested the implementation file -if [ $? -eq 0 ]; then - jq -n '{version: 1, status: "pass"}' > ${results_file} +# TODO: run test here +if test_output=$(false) +then + # OPTIONAL: Sanitize the output + # In some cases, the test output might be overly verbose, in which case stripping + # the unneeded information can be very helpful to the student + # sanitized_test_output=$(printf "${test_output}" | sed -n '/Test results:/,$p') + + # OPTIONAL: Manually add colors to the output to help scanning the output for errors + # If the test output does not contain colors to help identify failing (or passing) + # tests, it can be helpful to manually add colors to the output + # colorized_test_output=$(echo "${test_output}" \ + # | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \ + # | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$') + + jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > "${results_file}" else - # OPTIONAL: Sanitize the output - # In some cases, the test output might be overly verbose, in which case stripping - # the unneeded information can be very helpful to the student - # sanitized_test_output=$(printf "${test_output}" | sed -n '/Test results:/,$p') - - # OPTIONAL: Manually add colors to the output to help scanning the output for errors - # If the test output does not contain colors to help identify failing (or passing) - # tests, it can be helpful to manually add colors to the output - # colorized_test_output=$(echo "${test_output}" \ - # | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \ - # | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$') - - jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > ${results_file} + jq -n '{version: 1, status: "pass"}' > "${results_file}" fi echo "${slug}: done" From 47b472d35af919cc81f3b1943ae5576ddf9e4a9d Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 13:09:39 +0000 Subject: [PATCH 02/16] Syntax error test case --- .gitignore | 7 +++++++ bin/run-tests.sh | 14 ++++++++++++++ bin/run.sh | 16 +++++++++++++++- tests/example-syntax-error/expected_results.json | 5 ----- tests/syntax-error/expected_results.json | 5 +++++ tests/syntax-error/gleam.toml | 8 ++++++++ tests/syntax-error/manifest.toml | 11 +++++++++++ tests/syntax-error/src/syntax_error.gleam | 5 +++++ tests/syntax-error/test/syntax_error_test.gleam | 12 ++++++++++++ 9 files changed, 77 insertions(+), 6 deletions(-) delete mode 100644 tests/example-syntax-error/expected_results.json create mode 100644 tests/syntax-error/expected_results.json create mode 100644 tests/syntax-error/gleam.toml create mode 100644 tests/syntax-error/manifest.toml create mode 100644 tests/syntax-error/src/syntax_error.gleam create mode 100644 tests/syntax-error/test/syntax_error_test.gleam diff --git a/.gitignore b/.gitignore index 20b2deb..ff76e58 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ tests/*/results.json +tests/*/*.beam +tests/*/*.ez +tests/*/build +tests/*/erl_crash.dump +tests/*/.gitignore +tests/*/.github +tests/*/README.md diff --git a/bin/run-tests.sh b/bin/run-tests.sh index d2a3cd0..2d8d86e 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -15,6 +15,12 @@ exit_code=0 # Iterate over all test directories for test_dir in tests/*; do + # TODO: remove + # Skip if the test_dir starts with example + case "${test_dir}" in + tests/example*) continue ;; + esac + test_dir_name=$(basename "${test_dir}") test_dir_path=$(realpath "${test_dir}") results_file_path="${test_dir_path}/results.json" @@ -39,4 +45,12 @@ for test_dir in tests/*; do fi done +echo +if [ "${exit_code}" -eq 0 ] +then + echo "All tests passed!" +else + echo "Some tests failed!" +fi + exit ${exit_code} diff --git a/bin/run.sh b/bin/run.sh index 61d18ec..1d24575 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -29,6 +29,21 @@ results_file="${output_dir}/results.json" # Create the output directory if it doesn't exist mkdir -p "${output_dir}" +# Compile the project +echo "${slug}: compiling..." + +cd "${solution_dir}" || exit 1 + +# Reset the build directory +gleam clean + +if ! output=$(gleam build 2>&1) +then + jq -n --arg output "${output}" '{version: 1, status: "error", message: $output}' > "${results_file}" + echo "Compilation contained error, see ${output_dir}/results.json" + exit 0 +fi + echo "${slug}: testing..." # Run the tests for the provided implementation file and redirect stdout and @@ -49,7 +64,6 @@ then # colorized_test_output=$(echo "${test_output}" \ # | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \ # | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$') - jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > "${results_file}" else jq -n '{version: 1, status: "pass"}' > "${results_file}" diff --git a/tests/example-syntax-error/expected_results.json b/tests/example-syntax-error/expected_results.json deleted file mode 100644 index 9ef8b6f..0000000 --- a/tests/example-syntax-error/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "TODO: replace with correct output" -} diff --git a/tests/syntax-error/expected_results.json b/tests/syntax-error/expected_results.json new file mode 100644 index 0000000..6906ed2 --- /dev/null +++ b/tests/syntax-error/expected_results.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "status": "error", + "message": "Downloading packages\n Downloaded 2 packages in 0.01s\n Compiling gleam_stdlib\n Compiling gleeunit\n Compiling syntax_error\nerror: Syntax error\n ┌─ ./src/syntax_error.gleam:5:1\n │\n5 │ }\n │ ^ I was not expecting this.\n\nExpected one of: \"]\"" +} diff --git a/tests/syntax-error/gleam.toml b/tests/syntax-error/gleam.toml new file mode 100644 index 0000000..ee84508 --- /dev/null +++ b/tests/syntax-error/gleam.toml @@ -0,0 +1,8 @@ +name = "syntax_error" +version = "0.1.0" + +[dependencies] +gleam_stdlib = "~> 0.24" + +[dev-dependencies] +gleeunit = "~> 0.6" diff --git a/tests/syntax-error/manifest.toml b/tests/syntax-error/manifest.toml new file mode 100644 index 0000000..ac9fc1e --- /dev/null +++ b/tests/syntax-error/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.24.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "BD0E75F3153375218E9EC380930E3621036CADCF4246AA55B193BDABFD06D5CE" }, + { name = "gleeunit", version = "0.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "6F88395CAC9363EBE3D632E62C2C6EF731BBFB0A8D31E5E7287BC400002F15B2" }, +] + +[requirements] +gleam_stdlib = "~> 0.24" +gleeunit = "~> 0.6" diff --git a/tests/syntax-error/src/syntax_error.gleam b/tests/syntax-error/src/syntax_error.gleam new file mode 100644 index 0000000..72de2aa --- /dev/null +++ b/tests/syntax-error/src/syntax_error.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() { + [ +} diff --git a/tests/syntax-error/test/syntax_error_test.gleam b/tests/syntax-error/test/syntax_error_test.gleam new file mode 100644 index 0000000..3831e7a --- /dev/null +++ b/tests/syntax-error/test/syntax_error_test.gleam @@ -0,0 +1,12 @@ +import gleeunit +import gleeunit/should + +pub fn main() { + gleeunit.main() +} + +// gleeunit test functions end in `_test` +pub fn hello_world_test() { + 1 + |> should.equal(1) +} From c0b2dd248f9fb3a63d7bbfa56436b4efdea41668 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 13:18:18 +0000 Subject: [PATCH 03/16] Success test --- bin/run-tests.sh | 12 ++++--- bin/run.sh | 6 ++-- .../expected_results.json | 0 tests/success/gleam.toml | 16 +++++++++ tests/success/manifest.toml | 11 +++++++ tests/success/src/success.gleam | 5 +++ tests/success/test/success_test.gleam | 33 +++++++++++++++++++ 7 files changed, 75 insertions(+), 8 deletions(-) rename tests/{example-success => success}/expected_results.json (100%) create mode 100644 tests/success/gleam.toml create mode 100644 tests/success/manifest.toml create mode 100644 tests/success/src/success.gleam create mode 100644 tests/success/test/success_test.gleam diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 2d8d86e..25c1948 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -26,7 +26,8 @@ for test_dir in tests/*; do results_file_path="${test_dir_path}/results.json" expected_results_file_path="${test_dir_path}/expected_results.json" - bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" + echo "${test_dir_name}: testing..." + bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" > /dev/null # OPTIONAL: Normalize the results file # If the results.json file contains information that changes between @@ -37,15 +38,16 @@ for test_dir in tests/*; do # -e "s~${test_dir_path}~/solution~g" \ # "${results_file_path}" - echo "${test_dir_name}: comparing results.json to expected_results.json" - - if ! diff "${results_file_path}" "${expected_results_file_path}" + if diff "${results_file_path}" "${expected_results_file_path}" then + echo "${test_dir_name}: pass" + else + echo "${test_dir_name}: fail" exit_code=1 fi + echo done -echo if [ "${exit_code}" -eq 0 ] then echo "All tests passed!" diff --git a/bin/run.sh b/bin/run.sh index 1d24575..62219a5 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -51,8 +51,10 @@ echo "${slug}: testing..." # Write the results.json file based on the exit code of the command that was # just executed that tested the implementation file # TODO: run test here -if test_output=$(false) +if test_output=$(gleam test 2>&1) then + jq -n '{version: 1, status: "pass"}' > "${results_file}" +else # OPTIONAL: Sanitize the output # In some cases, the test output might be overly verbose, in which case stripping # the unneeded information can be very helpful to the student @@ -65,8 +67,6 @@ then # | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \ # | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$') jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > "${results_file}" -else - jq -n '{version: 1, status: "pass"}' > "${results_file}" fi echo "${slug}: done" diff --git a/tests/example-success/expected_results.json b/tests/success/expected_results.json similarity index 100% rename from tests/example-success/expected_results.json rename to tests/success/expected_results.json diff --git a/tests/success/gleam.toml b/tests/success/gleam.toml new file mode 100644 index 0000000..d4ab757 --- /dev/null +++ b/tests/success/gleam.toml @@ -0,0 +1,16 @@ +name = "success" +version = "0.1.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# licences = ["Apache-2.0"] +# description = "A Gleam library..." +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] + +[dependencies] +gleam_stdlib = "~> 0.24" + +[dev-dependencies] +gleeunit = "~> 0.6" diff --git a/tests/success/manifest.toml b/tests/success/manifest.toml new file mode 100644 index 0000000..ac9fc1e --- /dev/null +++ b/tests/success/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.24.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "BD0E75F3153375218E9EC380930E3621036CADCF4246AA55B193BDABFD06D5CE" }, + { name = "gleeunit", version = "0.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "6F88395CAC9363EBE3D632E62C2C6EF731BBFB0A8D31E5E7287BC400002F15B2" }, +] + +[requirements] +gleam_stdlib = "~> 0.24" +gleeunit = "~> 0.6" diff --git a/tests/success/src/success.gleam b/tests/success/src/success.gleam new file mode 100644 index 0000000..5da14b7 --- /dev/null +++ b/tests/success/src/success.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() { + io.println("Hello from success!") +} diff --git a/tests/success/test/success_test.gleam b/tests/success/test/success_test.gleam new file mode 100644 index 0000000..b66207c --- /dev/null +++ b/tests/success/test/success_test.gleam @@ -0,0 +1,33 @@ +import gleeunit + +pub fn main() { + gleeunit.main() +} + +pub fn one_test() { + Nil +} + +pub fn two_test() { + Nil +} + +pub fn three_test() { + Nil +} + +pub fn four_test() { + Nil +} + +pub fn five_test() { + Nil +} + +pub fn six_test() { + Nil +} + +pub fn seven_test() { + Nil +} From 43b5e09692157a9343f45e03f6db18869650e8c9 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 14:00:50 +0000 Subject: [PATCH 04/16] Normalise output --- bin/run-tests.sh | 15 ++++++---- bin/run.sh | 30 +++++++++++--------- tests/all_fail/expected_results.json | 5 ++++ tests/all_fail/gleam.toml | 16 +++++++++++ tests/all_fail/manifest.toml | 11 +++++++ tests/all_fail/src/all_fail.gleam | 5 ++++ tests/all_fail/test/all_fail_test.gleam | 16 +++++++++++ tests/example-all-fail/expected_results.json | 5 ---- tests/syntax-error/expected_results.json | 2 +- 9 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 tests/all_fail/expected_results.json create mode 100644 tests/all_fail/gleam.toml create mode 100644 tests/all_fail/manifest.toml create mode 100644 tests/all_fail/src/all_fail.gleam create mode 100644 tests/all_fail/test/all_fail_test.gleam delete mode 100644 tests/example-all-fail/expected_results.json diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 25c1948..7d1607d 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -11,6 +11,8 @@ # Example: # ./bin/run-tests.sh +set -eu + exit_code=0 # Iterate over all test directories @@ -29,20 +31,21 @@ for test_dir in tests/*; do echo "${test_dir_name}: testing..." bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" > /dev/null - # OPTIONAL: Normalize the results file + # Normalize the results file # If the results.json file contains information that changes between # different test runs (e.g. timing information or paths), you should normalize # the results file to allow the diff comparison below to work as expected - # sed -i -E \ - # -e 's/Elapsed time: [0-9]+\.[0-9]+ seconds//g' \ - # -e "s~${test_dir_path}~/solution~g" \ - # "${results_file_path}" + sed -i -E \ + -e 's/Compiled in [0-9]+\.[0-9]+/Compiled in 0.0/' \ + "${results_file_path}" if diff "${results_file_path}" "${expected_results_file_path}" then echo "${test_dir_name}: pass" else - echo "${test_dir_name}: fail" + echo + echo "${test_dir_name}: fail." + echo "${test_dir_name}: ${results_file_path} does not match ${expected_results_file_path}" exit_code=1 fi echo diff --git a/bin/run.sh b/bin/run.sh index 62219a5..2b9971e 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -21,11 +21,24 @@ if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then exit 1 fi +set -eu + slug="$1" solution_dir=$(realpath "${2%/}") output_dir=$(realpath "${3%/}") results_file="${output_dir}/results.json" +sanitise_gleam_output() { + grep -vE \ + -e "^Downloading packages" \ + -e "^ Downloaded [0-9]+ packages in [0-9]\.[0-9]+s" \ + -e "^ Downloaded [0-9]+ packages in [0-9]\.[0-9]+s" \ + -e "^ Compiling [a-z0-9_]+$" \ + -e "^ Compiled in [0-9]+\.[0-9]+s" \ + -e "^ Running [a-z0-9_]+\.main" \ + -e "^Finished in [0-9]+\.[0-9]+" +} + # Create the output directory if it doesn't exist mkdir -p "${output_dir}" @@ -39,6 +52,7 @@ gleam clean if ! output=$(gleam build 2>&1) then + output=$(echo "${output}" | sanitise_gleam_output) jq -n --arg output "${output}" '{version: 1, status: "error", message: $output}' > "${results_file}" echo "Compilation contained error, see ${output_dir}/results.json" exit 0 @@ -51,22 +65,12 @@ echo "${slug}: testing..." # Write the results.json file based on the exit code of the command that was # just executed that tested the implementation file # TODO: run test here -if test_output=$(gleam test 2>&1) +if output=$(gleam test 2>&1) then jq -n '{version: 1, status: "pass"}' > "${results_file}" else - # OPTIONAL: Sanitize the output - # In some cases, the test output might be overly verbose, in which case stripping - # the unneeded information can be very helpful to the student - # sanitized_test_output=$(printf "${test_output}" | sed -n '/Test results:/,$p') - - # OPTIONAL: Manually add colors to the output to help scanning the output for errors - # If the test output does not contain colors to help identify failing (or passing) - # tests, it can be helpful to manually add colors to the output - # colorized_test_output=$(echo "${test_output}" \ - # | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \ - # | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$') - jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > "${results_file}" + output=$(echo "${output}" | sanitise_gleam_output) + jq -n --arg output "${output}" '{version: 1, status: "fail", message: $output}' > "${results_file}" fi echo "${slug}: done" diff --git a/tests/all_fail/expected_results.json b/tests/all_fail/expected_results.json new file mode 100644 index 0000000..302e3a2 --- /dev/null +++ b/tests/all_fail/expected_results.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "status": "fail", + "message": "\u001b[0;31mF\u001b[0m\u001b[0;31mF\u001b[0m\nFailures:\n\n 1) all_fail_test:one_test/0\n\u001b[0;31m Failure: ?assertEqual(<<111,111,112,115>>, Actual)\n expected: <<\"oops\">>\n got: <<\"one\">>\u001b[0m\n\u001b[0;36m %% eunit_proc.erl:346:in `eunit_proc:with_timeout/3`\u001b[0m\n\u001b[0;36m Output: \u001b[0m\n\u001b[0;36m Output: \u001b[0m\n\n 2) all_fail_test:two_test/0\n\u001b[0;31m Failure: ?assertEqual(<<111,111,112,115>>, Actual)\n expected: <<\"oops\">>\n got: <<\"two\">>\u001b[0m\n\u001b[0;36m %% eunit_proc.erl:346:in `eunit_proc:with_timeout/3`\u001b[0m\n\u001b[0;36m Output: \u001b[0m\n\u001b[0;36m Output: \u001b[0m\n\n\u001b[0;31m2 tests, 2 failures\n\u001b[0m" +} diff --git a/tests/all_fail/gleam.toml b/tests/all_fail/gleam.toml new file mode 100644 index 0000000..85f9b36 --- /dev/null +++ b/tests/all_fail/gleam.toml @@ -0,0 +1,16 @@ +name = "all_fail" +version = "0.1.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# licences = ["Apache-2.0"] +# description = "A Gleam library..." +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] + +[dependencies] +gleam_stdlib = "~> 0.24" + +[dev-dependencies] +gleeunit = "~> 0.6" diff --git a/tests/all_fail/manifest.toml b/tests/all_fail/manifest.toml new file mode 100644 index 0000000..ac9fc1e --- /dev/null +++ b/tests/all_fail/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.24.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "BD0E75F3153375218E9EC380930E3621036CADCF4246AA55B193BDABFD06D5CE" }, + { name = "gleeunit", version = "0.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "6F88395CAC9363EBE3D632E62C2C6EF731BBFB0A8D31E5E7287BC400002F15B2" }, +] + +[requirements] +gleam_stdlib = "~> 0.24" +gleeunit = "~> 0.6" diff --git a/tests/all_fail/src/all_fail.gleam b/tests/all_fail/src/all_fail.gleam new file mode 100644 index 0000000..61565bb --- /dev/null +++ b/tests/all_fail/src/all_fail.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() { + io.println("Hello from all_fail!") +} diff --git a/tests/all_fail/test/all_fail_test.gleam b/tests/all_fail/test/all_fail_test.gleam new file mode 100644 index 0000000..5344026 --- /dev/null +++ b/tests/all_fail/test/all_fail_test.gleam @@ -0,0 +1,16 @@ +import gleeunit +import gleeunit/should + +pub fn main() { + gleeunit.main() +} + +pub fn one_test() { + "one" + |> should.equal("oops") +} + +pub fn two_test() { + "two" + |> should.equal("oops") +} diff --git a/tests/example-all-fail/expected_results.json b/tests/example-all-fail/expected_results.json deleted file mode 100644 index 9ef8b6f..0000000 --- a/tests/example-all-fail/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "TODO: replace with correct output" -} diff --git a/tests/syntax-error/expected_results.json b/tests/syntax-error/expected_results.json index 6906ed2..d6d7ba4 100644 --- a/tests/syntax-error/expected_results.json +++ b/tests/syntax-error/expected_results.json @@ -1,5 +1,5 @@ { "version": 1, "status": "error", - "message": "Downloading packages\n Downloaded 2 packages in 0.01s\n Compiling gleam_stdlib\n Compiling gleeunit\n Compiling syntax_error\nerror: Syntax error\n ┌─ ./src/syntax_error.gleam:5:1\n │\n5 │ }\n │ ^ I was not expecting this.\n\nExpected one of: \"]\"" + "message": "error: Syntax error\n ┌─ ./src/syntax_error.gleam:5:1\n │\n5 │ }\n │ ^ I was not expecting this.\n\nExpected one of: \"]\"" } From e4fcb027d311f9a0bd9a87282f654623365f5783 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 14:16:15 +0000 Subject: [PATCH 05/16] Remaining tests --- bin/run-tests.sh | 14 ------------- tests/empty_file/expected_results.json | 5 +++++ tests/empty_file/gleam.toml | 16 ++++++++++++++ .../manifest.toml | 0 tests/empty_file/src/empty_file.gleam | 1 + tests/empty_file/test/empty_file_test.gleam | 12 +++++++++++ .../example-empty-file/expected_results.json | 5 ----- .../expected_results.json | 5 ----- tests/partial_fail/expected_results.json | 5 +++++ tests/partial_fail/gleam.toml | 16 ++++++++++++++ tests/partial_fail/manifest.toml | 11 ++++++++++ tests/partial_fail/src/partial_fail.gleam | 5 +++++ .../partial_fail/test/partial_fail_test.gleam | 21 +++++++++++++++++++ .../expected_results.json | 0 .../{syntax-error => syntax_error}/gleam.toml | 0 tests/syntax_error/manifest.toml | 11 ++++++++++ .../src/syntax_error.gleam | 0 .../test/syntax_error_test.gleam | 0 18 files changed, 103 insertions(+), 24 deletions(-) create mode 100644 tests/empty_file/expected_results.json create mode 100644 tests/empty_file/gleam.toml rename tests/{syntax-error => empty_file}/manifest.toml (100%) create mode 100644 tests/empty_file/src/empty_file.gleam create mode 100644 tests/empty_file/test/empty_file_test.gleam delete mode 100644 tests/example-empty-file/expected_results.json delete mode 100644 tests/example-partial-fail/expected_results.json create mode 100644 tests/partial_fail/expected_results.json create mode 100644 tests/partial_fail/gleam.toml create mode 100644 tests/partial_fail/manifest.toml create mode 100644 tests/partial_fail/src/partial_fail.gleam create mode 100644 tests/partial_fail/test/partial_fail_test.gleam rename tests/{syntax-error => syntax_error}/expected_results.json (100%) rename tests/{syntax-error => syntax_error}/gleam.toml (100%) create mode 100644 tests/syntax_error/manifest.toml rename tests/{syntax-error => syntax_error}/src/syntax_error.gleam (100%) rename tests/{syntax-error => syntax_error}/test/syntax_error_test.gleam (100%) diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 7d1607d..c45340e 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -17,12 +17,6 @@ exit_code=0 # Iterate over all test directories for test_dir in tests/*; do - # TODO: remove - # Skip if the test_dir starts with example - case "${test_dir}" in - tests/example*) continue ;; - esac - test_dir_name=$(basename "${test_dir}") test_dir_path=$(realpath "${test_dir}") results_file_path="${test_dir_path}/results.json" @@ -31,14 +25,6 @@ for test_dir in tests/*; do echo "${test_dir_name}: testing..." bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" > /dev/null - # Normalize the results file - # If the results.json file contains information that changes between - # different test runs (e.g. timing information or paths), you should normalize - # the results file to allow the diff comparison below to work as expected - sed -i -E \ - -e 's/Compiled in [0-9]+\.[0-9]+/Compiled in 0.0/' \ - "${results_file_path}" - if diff "${results_file_path}" "${expected_results_file_path}" then echo "${test_dir_name}: pass" diff --git a/tests/empty_file/expected_results.json b/tests/empty_file/expected_results.json new file mode 100644 index 0000000..7dfb2ad --- /dev/null +++ b/tests/empty_file/expected_results.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "status": "error", + "message": "error: Unknown module field\n ┌─ ./test/empty_file_test.gleam:10:13\n │\n10 │ empty_file.hello_world()\n │ ^^^^^^^^^^^^\n\nThe module `empty_file` does not have a `hello_world` field." +} diff --git a/tests/empty_file/gleam.toml b/tests/empty_file/gleam.toml new file mode 100644 index 0000000..60ed860 --- /dev/null +++ b/tests/empty_file/gleam.toml @@ -0,0 +1,16 @@ +name = "empty_file" +version = "0.1.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# licences = ["Apache-2.0"] +# description = "A Gleam library..." +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] + +[dependencies] +gleam_stdlib = "~> 0.24" + +[dev-dependencies] +gleeunit = "~> 0.6" diff --git a/tests/syntax-error/manifest.toml b/tests/empty_file/manifest.toml similarity index 100% rename from tests/syntax-error/manifest.toml rename to tests/empty_file/manifest.toml diff --git a/tests/empty_file/src/empty_file.gleam b/tests/empty_file/src/empty_file.gleam new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/empty_file/src/empty_file.gleam @@ -0,0 +1 @@ + diff --git a/tests/empty_file/test/empty_file_test.gleam b/tests/empty_file/test/empty_file_test.gleam new file mode 100644 index 0000000..06f19bc --- /dev/null +++ b/tests/empty_file/test/empty_file_test.gleam @@ -0,0 +1,12 @@ +import gleeunit +import gleeunit/should +import empty_file + +pub fn main() { + gleeunit.main() +} + +pub fn hello_world_test() { + empty_file.hello_world() + |> should.equal("Hello, from empty_file!") +} diff --git a/tests/example-empty-file/expected_results.json b/tests/example-empty-file/expected_results.json deleted file mode 100644 index 9ef8b6f..0000000 --- a/tests/example-empty-file/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "TODO: replace with correct output" -} diff --git a/tests/example-partial-fail/expected_results.json b/tests/example-partial-fail/expected_results.json deleted file mode 100644 index 9ef8b6f..0000000 --- a/tests/example-partial-fail/expected_results.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "version": 1, - "status": "fail", - "message": "TODO: replace with correct output" -} diff --git a/tests/partial_fail/expected_results.json b/tests/partial_fail/expected_results.json new file mode 100644 index 0000000..23d1e45 --- /dev/null +++ b/tests/partial_fail/expected_results.json @@ -0,0 +1,5 @@ +{ + "version": 1, + "status": "fail", + "message": "\u001b[0;32m.\u001b[0m\u001b[0;32m.\u001b[0m\u001b[0;31mF\u001b[0m\nFailures:\n\n 1) partial_fail_test:three_test/0\n\u001b[0;31m Failure: ?assertEqual(<<111,111,112,115>>, Actual)\n expected: <<\"oops\">>\n got: <<\"three\">>\u001b[0m\n\u001b[0;36m %% eunit_proc.erl:346:in `eunit_proc:with_timeout/3`\u001b[0m\n\u001b[0;36m Output: \u001b[0m\n\u001b[0;36m Output: \u001b[0m\n\n\u001b[0;31m3 tests, 1 failures\n\u001b[0m" +} diff --git a/tests/partial_fail/gleam.toml b/tests/partial_fail/gleam.toml new file mode 100644 index 0000000..fcd065f --- /dev/null +++ b/tests/partial_fail/gleam.toml @@ -0,0 +1,16 @@ +name = "partial_fail" +version = "0.1.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# licences = ["Apache-2.0"] +# description = "A Gleam library..." +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] + +[dependencies] +gleam_stdlib = "~> 0.24" + +[dev-dependencies] +gleeunit = "~> 0.6" diff --git a/tests/partial_fail/manifest.toml b/tests/partial_fail/manifest.toml new file mode 100644 index 0000000..ac9fc1e --- /dev/null +++ b/tests/partial_fail/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.24.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "BD0E75F3153375218E9EC380930E3621036CADCF4246AA55B193BDABFD06D5CE" }, + { name = "gleeunit", version = "0.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "6F88395CAC9363EBE3D632E62C2C6EF731BBFB0A8D31E5E7287BC400002F15B2" }, +] + +[requirements] +gleam_stdlib = "~> 0.24" +gleeunit = "~> 0.6" diff --git a/tests/partial_fail/src/partial_fail.gleam b/tests/partial_fail/src/partial_fail.gleam new file mode 100644 index 0000000..76c3467 --- /dev/null +++ b/tests/partial_fail/src/partial_fail.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() { + io.println("Hello from partial_fail!") +} diff --git a/tests/partial_fail/test/partial_fail_test.gleam b/tests/partial_fail/test/partial_fail_test.gleam new file mode 100644 index 0000000..e62eae4 --- /dev/null +++ b/tests/partial_fail/test/partial_fail_test.gleam @@ -0,0 +1,21 @@ +import gleeunit +import gleeunit/should + +pub fn main() { + gleeunit.main() +} + +pub fn one_test() { + "one" + |> should.equal("one") +} + +pub fn two_test() { + "two" + |> should.equal("two") +} + +pub fn three_test() { + "three" + |> should.equal("oops") +} diff --git a/tests/syntax-error/expected_results.json b/tests/syntax_error/expected_results.json similarity index 100% rename from tests/syntax-error/expected_results.json rename to tests/syntax_error/expected_results.json diff --git a/tests/syntax-error/gleam.toml b/tests/syntax_error/gleam.toml similarity index 100% rename from tests/syntax-error/gleam.toml rename to tests/syntax_error/gleam.toml diff --git a/tests/syntax_error/manifest.toml b/tests/syntax_error/manifest.toml new file mode 100644 index 0000000..ac9fc1e --- /dev/null +++ b/tests/syntax_error/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.24.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "BD0E75F3153375218E9EC380930E3621036CADCF4246AA55B193BDABFD06D5CE" }, + { name = "gleeunit", version = "0.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "6F88395CAC9363EBE3D632E62C2C6EF731BBFB0A8D31E5E7287BC400002F15B2" }, +] + +[requirements] +gleam_stdlib = "~> 0.24" +gleeunit = "~> 0.6" diff --git a/tests/syntax-error/src/syntax_error.gleam b/tests/syntax_error/src/syntax_error.gleam similarity index 100% rename from tests/syntax-error/src/syntax_error.gleam rename to tests/syntax_error/src/syntax_error.gleam diff --git a/tests/syntax-error/test/syntax_error_test.gleam b/tests/syntax_error/test/syntax_error_test.gleam similarity index 100% rename from tests/syntax-error/test/syntax_error_test.gleam rename to tests/syntax_error/test/syntax_error_test.gleam From d538254a03a694bfb03f3e13f1ed7fb0da6d6795 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 14:18:38 +0000 Subject: [PATCH 06/16] Use Gleam container image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d717591..be71f10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.10 +FROM ghcr.io/gleam-lang/gleam:v0.24.0-erlang-alpine # install packages required to run the tests RUN apk add --no-cache jq coreutils From 05b7f21b1782eaf8f06a90b994f21359f6896b52 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 14:19:18 +0000 Subject: [PATCH 07/16] Remove TODO --- README.md | 11 ----------- bin/run.sh | 1 - 2 files changed, 12 deletions(-) diff --git a/README.md b/README.md index 56c65c8..da101d7 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,3 @@ -# Exercism Test Runner Template - -## Using the Test Runner Template - -4. Build the test runner, conforming to the [Test Runner interface specification](https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md). - - Update the files to match your track's needs. At the very least, you'll need to update `bin/run.sh`, `Dockerfile` and the test solutions in the `tests` directory - - Tip: look for `TODO:` comments to point you towards code that need updating - - Tip: look for `OPTIONAL:` comments to point you towards code that _could_ be useful - -Once you're happy with your test runner, [open an issue on the exercism/exercism](https://github.com/exercism/exercism/issues/new?assignees=&labels=&template=new-test-runner.md&title=%5BNew+Test+Runner%5D+) to request an official test runner repository for your track. - # Exercism Gleam Test Runner The Docker image to automatically run tests on TRACK_NAME_HERE solutions submitted to [Exercism]. diff --git a/bin/run.sh b/bin/run.sh index 2b9971e..188a71b 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -64,7 +64,6 @@ echo "${slug}: testing..." # stderr to capture it # Write the results.json file based on the exit code of the command that was # just executed that tested the implementation file -# TODO: run test here if output=$(gleam test 2>&1) then jq -n '{version: 1, status: "pass"}' > "${results_file}" From 385a8cb19946b0739797b7051756e61e58af5e34 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 14:39:16 +0000 Subject: [PATCH 08/16] Download Gleam packags --- Dockerfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index be71f10..1b14b5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,11 @@ FROM ghcr.io/gleam-lang/gleam:v0.24.0-erlang-alpine -# install packages required to run the tests -RUN apk add --no-cache jq coreutils +RUN \ + # install packages required to run the tests + apk add --no-cache jq coreutils \ + # Download the used Gleam packages + echo get the packages here + WORKDIR /opt/test-runner COPY . . From 445b1c6d6e852a71d28a5130cca865ba4f75800e Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 14:50:14 +0000 Subject: [PATCH 09/16] Eagerly download packages --- .gitignore | 16 ++++++++-------- Dockerfile | 11 ++++++----- bin/run.sh | 8 ++++++++ packages/gleam.toml | 16 ++++++++++++++++ packages/manifest.toml | 11 +++++++++++ packages/src/packages.gleam | 5 +++++ 6 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 packages/gleam.toml create mode 100644 packages/manifest.toml create mode 100644 packages/src/packages.gleam diff --git a/.gitignore b/.gitignore index ff76e58..bc6ac64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -tests/*/results.json -tests/*/*.beam -tests/*/*.ez -tests/*/build -tests/*/erl_crash.dump -tests/*/.gitignore -tests/*/.github -tests/*/README.md +**/*/results.json +**/*/*.beam +**/*/*.ez +**/*/build +**/*/erl_crash.dump +**/*/.gitignore +**/*/.github +**/*/README.md diff --git a/Dockerfile b/Dockerfile index 1b14b5f..ffd105a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,13 @@ FROM ghcr.io/gleam-lang/gleam:v0.24.0-erlang-alpine -RUN \ # install packages required to run the tests - apk add --no-cache jq coreutils \ - # Download the used Gleam packages - echo get the packages here - +RUN apk add --no-cache jq coreutils WORKDIR /opt/test-runner COPY . . + +# Download the used Gleam packages eagerly as the test runner will not have +# network access to do so. +RUN cd packages && gleam deps download + ENTRYPOINT ["/opt/test-runner/bin/run.sh"] diff --git a/bin/run.sh b/bin/run.sh index 188a71b..da16c6b 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -23,11 +23,18 @@ fi set -eu +root_dir=$(dirname "$(dirname "$(realpath "$0")")") slug="$1" solution_dir=$(realpath "${2%/}") output_dir=$(realpath "${3%/}") results_file="${output_dir}/results.json" +echo "Copying dependencies..." +cd packages +gleam deps download +mkdir -p "$solution_dir"/build +cp -r "$root_dir"/packages/build/packages "$solution_dir"/build/packages + sanitise_gleam_output() { grep -vE \ -e "^Downloading packages" \ @@ -39,6 +46,7 @@ sanitise_gleam_output() { -e "^Finished in [0-9]+\.[0-9]+" } + # Create the output directory if it doesn't exist mkdir -p "${output_dir}" diff --git a/packages/gleam.toml b/packages/gleam.toml new file mode 100644 index 0000000..ae18cd8 --- /dev/null +++ b/packages/gleam.toml @@ -0,0 +1,16 @@ +name = "packages" +version = "0.1.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# licences = ["Apache-2.0"] +# description = "A Gleam library..." +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] + +[dependencies] +gleam_stdlib = "~> 0.24" + +[dev-dependencies] +gleeunit = "~> 0.6" diff --git a/packages/manifest.toml b/packages/manifest.toml new file mode 100644 index 0000000..ac9fc1e --- /dev/null +++ b/packages/manifest.toml @@ -0,0 +1,11 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_stdlib", version = "0.24.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "BD0E75F3153375218E9EC380930E3621036CADCF4246AA55B193BDABFD06D5CE" }, + { name = "gleeunit", version = "0.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "6F88395CAC9363EBE3D632E62C2C6EF731BBFB0A8D31E5E7287BC400002F15B2" }, +] + +[requirements] +gleam_stdlib = "~> 0.24" +gleeunit = "~> 0.6" diff --git a/packages/src/packages.gleam b/packages/src/packages.gleam new file mode 100644 index 0000000..1d0c95a --- /dev/null +++ b/packages/src/packages.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() { + io.println("Hello from packages!") +} From a88897c99cc0807bab7b8ede153b83d0fe7c3624 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 15:00:05 +0000 Subject: [PATCH 10/16] Do not auto-download packages --- README.md | 3 ++- bin/run.sh | 1 - bin/setup-locally.sh | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 bin/setup-locally.sh diff --git a/README.md b/README.md index da101d7..6bfbe2c 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ Once the test runner has finished, its results will be written to `/ To run the tests to verify the behavior of the test runner, do the following: 1. Open a terminal in the project's root -2. Run `./bin/run-tests.sh` +2. Run `./bin/setup-locally.sh` +3. Run `./bin/run-tests.sh` These are [golden tests][golden] that compare the `results.json` generated by running the current state of the code against the "known good" `tests//results.json`. All files created during the test run itself are discarded. diff --git a/bin/run.sh b/bin/run.sh index da16c6b..31a4d33 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -31,7 +31,6 @@ results_file="${output_dir}/results.json" echo "Copying dependencies..." cd packages -gleam deps download mkdir -p "$solution_dir"/build cp -r "$root_dir"/packages/build/packages "$solution_dir"/build/packages diff --git a/bin/setup-locally.sh b/bin/setup-locally.sh new file mode 100755 index 0000000..052f528 --- /dev/null +++ b/bin/setup-locally.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# Synopsis: +# Setup the test runner locally by pre-downloading dependency packages. + +# Example: +# ./bin/setup-locally.sh + +set -eu + +root_dir=$(dirname "$(dirname "$(realpath "$0")")") +cd "$root_dir"/packages +gleam deps download From 378b60213cf2a716bbe1737da5ed99c3e46681cd Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 15:04:38 +0000 Subject: [PATCH 11/16] Funny indentation --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ffd105a..1d87952 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ghcr.io/gleam-lang/gleam:v0.24.0-erlang-alpine - # install packages required to run the tests +# Install packages required to run the tests RUN apk add --no-cache jq coreutils WORKDIR /opt/test-runner From 0ea8a6ca91d25504448825dab4deef750776aa84 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Fri, 11 Nov 2022 15:41:20 +0000 Subject: [PATCH 12/16] Remove duplicate entry --- bin/run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/run.sh b/bin/run.sh index 31a4d33..917dd96 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -38,7 +38,6 @@ sanitise_gleam_output() { grep -vE \ -e "^Downloading packages" \ -e "^ Downloaded [0-9]+ packages in [0-9]\.[0-9]+s" \ - -e "^ Downloaded [0-9]+ packages in [0-9]\.[0-9]+s" \ -e "^ Compiling [a-z0-9_]+$" \ -e "^ Compiled in [0-9]+\.[0-9]+s" \ -e "^ Running [a-z0-9_]+\.main" \ From 0740acc7a881062c2a825e1122672142805eba72 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Mon, 14 Nov 2022 19:10:07 +0000 Subject: [PATCH 13/16] Thank you @TanklesXL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bfbe2c..f2118ba 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Exercism Gleam Test Runner -The Docker image to automatically run tests on TRACK_NAME_HERE solutions submitted to [Exercism]. +The Docker image to automatically run tests on Gleam solutions submitted to [Exercism]. ## Run the test runner From d8af1ba40b41b22aed00dc78f699c53b2ba4f383 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 15 Nov 2022 11:14:13 +0000 Subject: [PATCH 14/16] Precompile deps --- Dockerfile | 5 +++-- bin/run.sh | 10 +++------- bin/setup-locally.sh | 5 +++-- packages/src/.keep | 0 packages/src/packages.gleam | 5 ----- 5 files changed, 9 insertions(+), 16 deletions(-) create mode 100644 packages/src/.keep delete mode 100644 packages/src/packages.gleam diff --git a/Dockerfile b/Dockerfile index 1d87952..2027ece 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ WORKDIR /opt/test-runner COPY . . # Download the used Gleam packages eagerly as the test runner will not have -# network access to do so. -RUN cd packages && gleam deps download +# network access to do so. They are also pre-compiled for performance when +# compiling test projects. +RUN cd packages && gleam build ENTRYPOINT ["/opt/test-runner/bin/run.sh"] diff --git a/bin/run.sh b/bin/run.sh index 917dd96..fd0bcd8 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -30,9 +30,9 @@ output_dir=$(realpath "${3%/}") results_file="${output_dir}/results.json" echo "Copying dependencies..." -cd packages -mkdir -p "$solution_dir"/build -cp -r "$root_dir"/packages/build/packages "$solution_dir"/build/packages +mkdir -p "$solution_dir" +rm -r "$solution_dir"/build +cp -r "$root_dir"/packages/build "$solution_dir"/build sanitise_gleam_output() { grep -vE \ @@ -44,7 +44,6 @@ sanitise_gleam_output() { -e "^Finished in [0-9]+\.[0-9]+" } - # Create the output directory if it doesn't exist mkdir -p "${output_dir}" @@ -53,9 +52,6 @@ echo "${slug}: compiling..." cd "${solution_dir}" || exit 1 -# Reset the build directory -gleam clean - if ! output=$(gleam build 2>&1) then output=$(echo "${output}" | sanitise_gleam_output) diff --git a/bin/setup-locally.sh b/bin/setup-locally.sh index 052f528..b457ea4 100755 --- a/bin/setup-locally.sh +++ b/bin/setup-locally.sh @@ -1,7 +1,8 @@ #!/usr/bin/env sh # Synopsis: -# Setup the test runner locally by pre-downloading dependency packages. +# Setup the test runner locally by pre-downloading and compiling dependency +# packages. # Example: # ./bin/setup-locally.sh @@ -10,4 +11,4 @@ set -eu root_dir=$(dirname "$(dirname "$(realpath "$0")")") cd "$root_dir"/packages -gleam deps download +gleam build diff --git a/packages/src/.keep b/packages/src/.keep new file mode 100644 index 0000000..e69de29 diff --git a/packages/src/packages.gleam b/packages/src/packages.gleam deleted file mode 100644 index 1d0c95a..0000000 --- a/packages/src/packages.gleam +++ /dev/null @@ -1,5 +0,0 @@ -import gleam/io - -pub fn main() { - io.println("Hello from packages!") -} From e137162794756575057379bd0dda16cfc1d4c9cc Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 15 Nov 2022 11:16:02 +0000 Subject: [PATCH 15/16] Note requirements --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f2118ba..75d1746 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ Once the test runner has finished, its results will be written to `/ To run the tests to verify the behavior of the test runner, do the following: +1. Ensure you have Gleam, Erlang, and jq installed on your macOS, Linux, or + similar machine. 1. Open a terminal in the project's root 2. Run `./bin/setup-locally.sh` 3. Run `./bin/run-tests.sh` From 055de34e6af0768128bb5d656b9a45052c192e78 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 15 Nov 2022 11:16:50 +0000 Subject: [PATCH 16/16] -f --- bin/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run.sh b/bin/run.sh index fd0bcd8..d6f0248 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -31,7 +31,7 @@ results_file="${output_dir}/results.json" echo "Copying dependencies..." mkdir -p "$solution_dir" -rm -r "$solution_dir"/build +rm -fr "$solution_dir"/build cp -r "$root_dir"/packages/build "$solution_dir"/build sanitise_gleam_output() {