Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin(run-tests): refactor #299

Merged
merged 12 commits into from
Aug 22, 2023
Merged

bin(run-tests): refactor #299

merged 12 commits into from
Aug 22, 2023

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Aug 19, 2023

Make the run-tests script more readable (at least for my taste), and more consistent with the style in bin/fetch-configlet.

This is just refactoring - no change in functionality. But we exchange some theoretical TOCTOU subtleties for other ones. See individual commits for more details. A whitespace-ignoring or whitespace-aware diff is more readable here.

Summary:

  • Move zig detection out of the loop. We don't need to support moving the zig installation while the script is executing.
  • Prefer [[ to [ for bash. See e.g. this section in the Google Shell Style Guide.
  • Add a main function, and declare variables as local. This is also suggested (here and here) in the same guide, and matches bin/fetch-configlet.
  • Prefer -f and -d to -e.
  • Remove some unnecessary directory existence checks.
  • Use printf more consistently.

ee7 added 12 commits August 19, 2023 11:00
The shebang in this file is

    #!/usr/bin/env bash

So let's prefer [[.

This also matches the style in the `bin/fetch-configlet` script.

See e.g. the Google Shell Style Guide [1].

[1] https://google.github.io/styleguide/shellguide.html#s6.3-tests
Allow defining more variables as `local`, and work towards matching the
style of the bin/fetch-configlet script.

This is also suggested in the Google Shell Style Guide [1].

[1] https://google.github.io/styleguide/shellguide.html#main
Signal to the reader that there's nothing complex here.

From the Google Shell Style Guide [1]:

    Ensure that local variables are only seen inside a function and its
    children by using local when declaring them. This avoids polluting
    the global name space and inadvertently setting variables that may
    have significance outside the function.

And again, this matches the style in `bin/fetch-configlet`.

[1] https://google.github.io/styleguide/shellguide.html#s7.6-use-local-variables
Be stricter, and improve readability.
We already pass the -f option.
And remove the directory existence check that previously existed
immediately after

    for exercise in *; do
Allow moving the `rm` command closer to the `cp` command.
Make it easier to see that the `zig test` command is the same,
regardless of where the zig executable is located.

The cost: it's no longer possible to move your zig installation while
the script is executing. But we don't need to support that.
If a directory is removed in the time between the outer
validation/globbing and here, just let `cd` error.
As we do elsewhere in this script.
@ee7 ee7 merged commit 90461da into exercism:main Aug 22, 2023
@ee7 ee7 deleted the run-tests-refactor branch August 22, 2023 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants