Skip to content

Commit

Permalink
bin(run-tests): improve status messages (#305)
Browse files Browse the repository at this point in the history
Changes:

- Print the exercise name in its canonical kebab-case form, not its
  snake_case form.

- Improve ellipsis usage.

- Prefix error messages with Error, being consistent with the style in
  a recent commit [1].

- Add quotes around a path.

- Consistently use "directory", not "folder".

- Consistently write status messages to stderr.

Note that the `zig test` output goes to stderr. Before this commit:

    $ bin/run-tests > /dev/null
    All 9 tests passed.
    All 50 tests passed.
    All 13 tests passed.
    [...]

With this commit:

    $ bin/run-tests > /dev/null
    Running tests for acronym...
    All 9 tests passed.

    Running tests for allergies...
    All 50 tests passed.

    Running tests for armstrong-numbers...
    All 13 tests passed.

    [...]

[1] 7ff0372, 2023-08-23, "bin(run-tests): error for missing example"
  • Loading branch information
ee7 authored Aug 26, 2023
1 parent 7ff0372 commit fdf1f9d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bin/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ execute_test() {
local exercise_name
exercise_name=$(echo "$1" | tr '-' '_')

printf '%s\n' "Running tests for ${exercise_name}"
printf '%s\n' "Running tests for ${1}..." >&2

# Copy the examples with the correct name for the exercise
if [[ -f "./.meta/example.zig" ]]; then
mv ./.meta/example.zig "${exercise_name}".zig
# No building required, just test it
zig test "test_${exercise_name}.zig"
printf '\n'
printf '\n' >&2
else
printf '%s\n' "Error: ${exercise_name} lacks its '.meta/example.zig' file" >&2
exit 1
Expand All @@ -30,7 +30,7 @@ main() {
cd "${script_dir}"/..

if [[ ! -d "exercises/practice" ]]; then
printf '%s\n' "The exercises/practice folder is missing..." >&2
printf '%s\n' "Error: the 'exercises/practice' directory is missing" >&2
exit 1
fi

Expand All @@ -47,7 +47,7 @@ main() {
local exercises=("$@")
for exercise in "${exercises[@]}"; do
if [[ ! -d "${exercise}" ]]; then
printf '%s\n' "The specified exercise '${1}' does not exist" >&2
printf '%s\n' "Error: the specified exercise '${1}' does not exist" >&2
exit 1
fi
done
Expand Down

0 comments on commit fdf1f9d

Please sign in to comment.