Skip to content

Commit f6bcb12

Browse files
Update add-practice-exercise script to reference test generator (#738)
1 parent 7fa9f91 commit f6bcb12

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

bin/add-practice-exercise

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ fi
6969

7070
exercise_dir="exercises/practice/${slug}"
7171
config_json_file="${exercise_dir}/.meta/config.json"
72+
generator_tpl_file="${exercise_dir}/.meta/generator.tpl"
7273
files=$(jq -r --arg dir "${exercise_dir}" '.files | to_entries | map({key: .key, value: (.value | map("'"'"'" + $dir + "/" + . + "'"'"'") | join(" and "))}) | from_entries' "${config_json_file}")
74+
prob_specs_dir=$(./bin/configlet info --verbosity detailed | head -n 1 | sed 's/.*dir: //')
75+
canonical_data_json_file="${prob_specs_dir}/exercises/${slug}/canonical-data.json"
7376

7477
sample_exercise_dir="exercises/practice/acronym"
7578
for sample_file in deps.edn project.clj; do
@@ -96,11 +99,28 @@ for file_type in solution example; do
9699
FILE
97100
done
98101

99-
cat << NEXT_STEPS
100-
Your next steps are:
102+
if [[ -f "${prob_specs_dir}/exercises/${slug}/canonical-data.json" ]]; then
103+
cp "${exercise_dir}/${test_file}" "${generator_tpl_file}"
104+
105+
TEST_STEPS=$(cat << EOF
106+
- Create the test generator in '${generator_tpl_file}'
107+
- The test generator uses the canonical data from 'https://github.com/exercism/problem-specifications/blob/main/exercises/${slug}/canonical-data.json'
108+
- Any test cases you don't want to implement, mark them in 'exercises/practice/${slug}/.meta/tests.toml' with "include = false"
109+
- Run 'bin/generate-exercise-tests ${slug}' to generate the tests
110+
EOF
111+
)
112+
else
113+
TEST_STEPS=$(cat << EOF
101114
- Create the test suite in $(jq -r '.test' <<< "${files}")
102115
- The tests should be based on the canonical data at 'https://github.com/exercism/problem-specifications/blob/main/exercises/${slug}/canonical-data.json'
103116
- Any test cases you don't implement, mark them in 'exercises/practice/${slug}/.meta/tests.toml' with "include = false"
117+
EOF
118+
)
119+
fi
120+
121+
cat << NEXT_STEPS
122+
Your next steps are:
123+
${TEST_STEPS}
104124
- Create the example solution in $(jq -r '.example' <<< "${files}")
105125
- Verify the example solution passes the tests by running 'bin/verify-exercises ${slug}'
106126
- Create the stub solution in $(jq -r '.solution' <<< "${files}")

0 commit comments

Comments
 (0)