Skip to content

Commit 744da25

Browse files
authored
Merge pull request #41 from artamonovkirill/fix/custom-class-names
Allow for custom test class names
2 parents 65dc93b + 71946c6 commit 744da25

File tree

24 files changed

+38
-1533
lines changed

24 files changed

+38
-1533
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
tests/**/results.json
22
tests/**/build/
3-
tests/**/gradle/
4-
tests/**/.gradle/
53
tests/**/*.groovy.original
64
target/
75
jansi-tmp/

bin/run-tests-in-docker.sh

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ set -e
1717
docker build --rm -t exercism/groovy-test-runner .
1818

1919
# Run the Docker image using the settings mimicking the production environment
20-
# --read-only cannot be used because it causes https://github.com/gradle/gradle/issues/8107
2120
docker run \
2221
--rm \
2322
--network none \

bin/run-tests.sh

-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ exit_code=0
1717
for test_dir in tests/*; do
1818
test_dir_name="$(basename $test_dir)"
1919
test_dir_path="$(realpath $test_dir)"
20-
gradle_dir_path="${test_dir}/.gradle"
21-
build_dir_path="${test_dir}/build"
2220
results_file="results.json"
2321
results_file_path="${test_dir}/results.json"
2422
expected_results_file="expected_results.json"
2523
expected_results_file_path="${test_dir}/expected_results.json"
2624

27-
# Clear cache as this influences the test output
28-
rm -rf "${gradle_dir_path}" > /dev/null
29-
rm -rf "${build_dir_path}" > /dev/null
30-
3125
bin/run.sh "${test_dir_name}" "${test_dir}" "${test_dir}"
3226

3327
# Normalize the results file

bin/run.sh

+17-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,23 @@ fi
2424
slug="$1"
2525
input_dir="${2%/}"
2626
output_dir="${3%/}"
27-
exercise=$(echo "${slug}" | sed -r 's/(^|-)([a-z])/\U\2/g')
28-
tests_file="${input_dir}/src/test/groovy/${exercise}Spec.groovy"
27+
path=${CONFIG_PATH:-'.meta'}
28+
29+
function test_name_from_config() {
30+
local config="${input_dir}/${path}/config.json"
31+
[[ -f "${config}" ]] || return 1
32+
local -a test_files
33+
mapfile -t test_files < <(jq -r '.files.test[]' "${config}")
34+
(( ${#test_files[@]} == 1 )) || return 1
35+
basename "${test_files[0]}"
36+
}
37+
38+
function test_name_from_slug() {
39+
exercise=$(sed -r 's/(^|-)([a-z])/\U\2/g' <<< "${slug}")
40+
echo "${exercise}Spec.groovy"
41+
}
42+
43+
tests_file="${input_dir}/src/test/groovy/$(test_name_from_config || test_name_from_slug)"
2944
tests_file_original="${tests_file}.original"
3045
results_file="${output_dir}/results.json"
3146

build.gradle

-10
This file was deleted.

tests/example-all-fail/build.gradle

-18
This file was deleted.

tests/example-all-fail/gradlew

-183
This file was deleted.

tests/example-all-fail/gradlew.bat

-103
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"blurb": "Verify that expected test class names can be extracted from .meta/config.json",
3+
"files": {
4+
"test": [
5+
"src/test/groovy/SomeSpec.groovy"
6+
]
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version": 1,
3+
"status": "fail",
4+
"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"
5+
}

tests/example-custom-class/src/main/groovy/Some.groovy

Whitespace-only changes.

0 commit comments

Comments
 (0)