Skip to content

Commit 4c0bb65

Browse files
committed
Fix a couple things
1 parent 871618b commit 4c0bb65

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ bin/exercise
99
bin/exercise.exe
1010
exercises/*/*/Cargo.lock
1111
exercises/*/*/clippy.log
12+
canonical_data.json

bin/generator-utils/generate_tests

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# shellcheck source=/dev/null
4-
source ./bin/generator-utils/utils
4+
source ./bin/generator-utils/utils.sh
55

66
function digest_template() {
77
template=$(cat bin/generator-utils/test_template)
@@ -12,15 +12,18 @@ function digest_template() {
1212

1313
canonical_json=$(cat canonical_data.json)
1414
SLUG=$(echo "$canonical_json" | jq '.exercise')
15-
EXERCISE_DIR="exercises/practice/${SLUG}"
16-
EXERCISE_DIR="exercises/practice/${SLUG}"
17-
TEST_FILE="${EXERCISE_DIR}/tests/${SLUG}.rs"
18-
cat <<EOT >"$TEST_FILE"
15+
# shellcheck disable=SC2001
16+
# Remove double quotes
17+
SLUG=$(echo "$SLUG" | sed 's/"//g')
18+
EXERCISE_DIR="exercises/practice/$SLUG"
19+
TEST_FILE="$EXERCISE_DIR/tests/$SLUG.rs"
20+
rm "$TEST_FILE"
21+
22+
cat <<EOT >"$TEST_FILE"
1923
use $(dash_to_underscore "$SLUG")::*;
2024
// Add tests here
2125
2226
EOT
23-
rm "$TEST_FILE"
2427
cases=$(echo "$canonical_json" | jq '[ .. | objects | with_entries(select(.key | IN("uuid", "description", "input", "expected", "property"))) | select(. != {}) | select(has("uuid")) ]')
2528

2629
# shellcheck disable=SC2034
@@ -33,6 +36,10 @@ jq -c '.[]' <<<"$cases" | while read -r case; do
3336
# Turn function name unto snake_case
3437
formatted_template=$(echo "$eval_template" | sed -e ':loop' -e 's/\(fn[^(]*\)[ -]/\1_/g' -e 't loop' | sed 's/fn_/fn /')
3538
# Push to file
36-
echo "$formatted_template" >>tests.rs
39+
40+
echo "$formatted_template" >>"$TEST_FILE"
41+
printf "\\n" >> "$TEST_FILE"
3742

3843
done
44+
45+
rustfmt "$TEST_FILE"

bin/generator-utils/templates.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ EOT
2424
)
2525
# fetch canonical_data
2626
canonical_json=$(curl "${curlopts[@]}" "https://raw.githubusercontent.com/exercism/problem-specifications/main/exercises/${slug}/canonical-data.json")
27-
$canonical_json >>canonical_data.json
27+
echo "$canonical_json" >>canonical_data.json
2828

2929
if [ "${canonical_json}" == "404: Not Found" ]; then
3030
canonical_json=$(jq --null-input '{cases: []}')

0 commit comments

Comments
 (0)