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

Allow for custom test class names #41

Merged
merged 6 commits into from
Jan 18, 2025
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
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
tests/**/results.json
tests/**/build/
tests/**/gradle/
tests/**/.gradle/
tests/**/*.groovy.original
target/
jansi-tmp/
Expand Down
1 change: 0 additions & 1 deletion bin/run-tests-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set -e
docker build --rm -t exercism/groovy-test-runner .

# Run the Docker image using the settings mimicking the production environment
# --read-only cannot be used because it causes https://github.com/gradle/gradle/issues/8107
docker run \
--rm \
--network none \
Expand Down
6 changes: 0 additions & 6 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ exit_code=0
for test_dir in tests/*; do
test_dir_name="$(basename $test_dir)"
test_dir_path="$(realpath $test_dir)"
gradle_dir_path="${test_dir}/.gradle"
build_dir_path="${test_dir}/build"
results_file="results.json"
results_file_path="${test_dir}/results.json"
expected_results_file="expected_results.json"
expected_results_file_path="${test_dir}/expected_results.json"

# Clear cache as this influences the test output
rm -rf "${gradle_dir_path}" > /dev/null
rm -rf "${build_dir_path}" > /dev/null

bin/run.sh "${test_dir_name}" "${test_dir}" "${test_dir}"

# Normalize the results file
Expand Down
19 changes: 17 additions & 2 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@ fi
slug="$1"
input_dir="${2%/}"
output_dir="${3%/}"
exercise=$(echo "${slug}" | sed -r 's/(^|-)([a-z])/\U\2/g')
tests_file="${input_dir}/src/test/groovy/${exercise}Spec.groovy"
path=${CONFIG_PATH:-'.meta'}

function test_name_from_config() {
local config="${input_dir}/${path}/config.json"
[[ -f "${config}" ]] || return 1
local -a test_files
mapfile -t test_files < <(jq -r '.files.test[]' "${config}")
(( ${#test_files[@]} == 1 )) || return 1
basename "${test_files[0]}"
}

function test_name_from_slug() {
exercise=$(sed -r 's/(^|-)([a-z])/\U\2/g' <<< "${slug}")
echo "${exercise}Spec.groovy"
}

tests_file="${input_dir}/src/test/groovy/$(test_name_from_config || test_name_from_slug)"
tests_file_original="${tests_file}.original"
results_file="${output_dir}/results.json"

Expand Down
10 changes: 0 additions & 10 deletions build.gradle

This file was deleted.

18 changes: 0 additions & 18 deletions tests/example-all-fail/build.gradle

This file was deleted.

183 changes: 0 additions & 183 deletions tests/example-all-fail/gradlew

This file was deleted.

103 changes: 0 additions & 103 deletions tests/example-all-fail/gradlew.bat

This file was deleted.

8 changes: 8 additions & 0 deletions tests/example-custom-class/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"blurb": "Verify that expected test class names can be extracted from .meta/config.json",
"files": {
"test": [
"src/test/groovy/SomeSpec.groovy"
]
}
}
5 changes: 5 additions & 0 deletions tests/example-custom-class/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": 1,
"status": "fail",
"message": "\u001b[01;31m\u001b[K[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, <<< FAILURE! - in SomeSpec\u001b[m\u001b[K\n\u001b[01;31m\u001b[K[ERROR] SomeSpec.some test <<< FAILURE!\u001b[m\u001b[K\norg.spockframework.runtime.ConditionNotSatisfiedError: \nCondition not satisfied:\n\nfalse\n\n\tat SomeSpec.some test(SomeSpec.groovy:7)\n\n\u001b[01;31m\u001b[K[ERROR] Failures: \u001b[m\u001b[K\n\u001b[01;31m\u001b[K[ERROR] SomeSpec.some test:7 Condition not satisfied:\u001b[m\u001b[K\n\nfalse\n\n\u001b[01;31m\u001b[K[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0\u001b[m\u001b[K"
}
Empty file.
Loading