Skip to content

Commit 961639a

Browse files
committed
Lowercase var names in bin/generate_tests, remove redundant shellcheck disable
1 parent e93023b commit 961639a

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

bin/generate_tests

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,44 @@ source ./bin/generator-utils/utils.sh
99

1010
digest_template() {
1111
template=$(cat bin/test_template)
12-
# turn every token into a jq command
12+
# Turn every token into a jq command
1313
echo "$template" | sed 's/${\([^}]*\)\}\$/$(echo $case | jq -r '\''.\1'\'')/g'
1414
}
1515

1616
message "info" "Generating tests.."
1717
canonical_json=$(cat canonical_data.json)
18-
SLUG=$(echo "$canonical_json" | jq '.exercise')
19-
# shellcheck disable=SC2001
18+
slug=$(echo "$canonical_json" | jq '.exercise')
2019
# Remove double quotes
21-
SLUG=$(echo "$SLUG" | sed 's/"//g')
22-
EXERCISE_DIR="exercises/practice/$SLUG"
23-
TEST_FILE="$EXERCISE_DIR/tests/$SLUG.rs"
20+
slug=$(echo "$slug" | sed 's/"//g')
21+
exercise_dir="exercises/practice/$slug"
22+
test_file="$exercise_dir/tests/$slug.rs"
2423

25-
cat <<EOT >"$TEST_FILE"
26-
use $(dash_to_underscore "$SLUG")::*;
24+
cat <<EOT >"$test_file"
25+
use $(dash_to_underscore "$slug")::*;
2726
// Add tests here
2827
2928
EOT
3029

3130
# Flattens canonical json, extracts only the objects with a uuid
32-
CASES=$(echo "$CANONICAL_JSON" | jq '[ .. | objects | with_entries(select(.key | IN("uuid", "description", "input", "expected", "property"))) | select(. != {}) | select(has("uuid")) ]')
31+
cases=$(echo "$canonical_json" | jq '[ .. | objects | with_entries(select(.key | IN("uuid", "description", "input", "expected", "property"))) | select(. != {}) | select(has("uuid")) ]')
3332

33+
# Shellcheck doesn't recognize that `case` is not unused
3434
# shellcheck disable=SC2034
35-
jq -c '.[]' <<<"$CASES" | while read -r case; do
35+
jq -c '.[]' <<<"$cases" | while read -r case; do
3636

3737
# Evaluate the bash parts and replace them with their return values
38-
EVAL_TEMPLATE="$(digest_template | sed -e "s/\$(\(.*\))/\$\(\1\)/g")"
39-
EVAL_TEMPLATE="$(eval "echo \"$EVAL_TEMPLATE\"")"
38+
eval_template="$(digest_template | sed -e "s/\$(\(.*\))/\$\(\1\)/g")"
39+
eval_template="$(eval "echo \"$eval_template\"")"
4040

41-
# Turn function name unto snake_case
42-
FORMATTED_TEMPLATE=$(echo "$EVAL_TEMPLATE" | sed -e ':loop' -e 's/\(fn[^(]*\)[ -]/\1_/g' -e 't loop' | sed 's/fn_/fn /')
43-
# Push to file
41+
# Turn function name into snake_case
42+
formatted_template=$(echo "$eval_template" | sed -e ':loop' -e 's/\(fn[^(]*\)[ -]/\1_/g' -e 't loop' | sed 's/fn_/fn /')
4443

45-
echo "$FORMATTED_TEMPLATE" >>"$TEST_FILE"
46-
printf "\\n" >>"$TEST_FILE"
44+
# Push to test file
45+
echo "$formatted_template" >>"$test_file"
46+
printf "\\n" >>"$test_file"
4747

4848
done
4949

50-
rustfmt "$TEST_FILE"
50+
rustfmt "$test_file"
5151

52-
message "success" "Generated tests successfully! Check out ${TEST_FILE}"
52+
message "success" "Generated tests successfully! Check out ${test_file}"

bin/generator-utils/utils.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function message() {
1515
"error") printf "${red}%s${reset_color}\n" "[error]: $message" ;;
1616
"done")
1717
echo
18-
# Create a dashed-line as wide as the screen
18+
# Generate a dashed line that spans the entire width of the screen.
1919
local cols
2020
cols=$(tput cols)
2121
printf "%*s\n" "$cols" "" | tr " " "-"
@@ -46,7 +46,7 @@ check_exercise_existence() {
4646
exit 1
4747
fi
4848

49-
# fetch configlet and crop out exercise list
49+
# Fetch configlet and crop out exercise list
5050
local unimplemented_exercises
5151
unimplemented_exercises=$(bin/configlet info | sed -n '/With canonical data:/,/Track summary:/p' | sed -e '/\(With\(out\)\? canonical data:\|Track summary:\)/d' -e '/^$/d')
5252
if echo "$unimplemented_exercises" | grep -q "^$slug$"; then
@@ -57,7 +57,7 @@ check_exercise_existence() {
5757
${unimplemented_exercises}"
5858

5959
# Find closest match to typed-in not-found slug
60-
# see util/ngram for source
60+
# See util/ngram for source
6161
# First it builds a binary for the system of the contributor
6262
if [ -e bin/generator-utils/ngram ]; then
6363
echo "${yellow}$(bin/generator-utils/ngram "${unimplemented_exercises}" "$slug")${reset_color}"

0 commit comments

Comments
 (0)