Skip to content

Commit

Permalink
GH-45050: [CI][Dev] Apply ShellCheck lint to c_glib/test/run-test.sh (#…
Browse files Browse the repository at this point in the history
…45052)

### Rationale for this change

```bash
❯ pre-commit run --show-diff-on-failure --color=always --all-files shellcheck
ShellCheck v0.10.0.......................................................Failed

- hook id: shellcheck
- exit code: 1

In c_glib/test/run-test.sh line 20:
test_dir="$(cd $(dirname $0); pwd)"
            ^--------------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
               ^-----------^ SC2046 (warning): Quote this to prevent word splitting.
                         ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
test_dir="$(cd $(dirname "$0") || exit; pwd)"

In c_glib/test/run-test.sh line 50:
  MODULE_TYPELIB_DIR_VAR_NAME="$(echo ${module} | tr a-z- A-Z_)_TYPELIB_DIR"
                                      ^-------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
  MODULE_TYPELIB_DIR_VAR_NAME="$(echo "${module}" | tr a-z- A-Z_)_TYPELIB_DIR"

In c_glib/test/run-test.sh line 77:
${DEBUGGER} "${DEBUGGER_ARGS[@]}" "${RUBY}" ${test_dir}/run-test.rb "$@"
                                            ^---------^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
${DEBUGGER} "${DEBUGGER_ARGS[@]}" "${RUBY}" "${test_dir}"/run-test.rb "$@"

For more information:
  <https://www.shellcheck.net/wiki/SC2046> -- Quote this to prevent word splitt...
  <https://www.shellcheck.net/wiki/SC2164> -- Use 'cd ... || exit' or 'cd ... |...
  <https://www.shellcheck.net/wiki/SC2086> -- Double quote to prevent globbing ...

```

### What changes are included in this PR?
- add missing double quotes(SC2046,SC2086)
- Use cd ... || exit in case cd fails.(SC2164)

### Are these changes tested?
yes

### Are there any user-facing changes?
no

* GitHub Issue: #45050

Lead-authored-by: takaaki.koike <[email protected]>
Co-authored-by: Takaaki Koike <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
tks1197 and kou authored Dec 19, 2024
1 parent 6f65782 commit 9e08c57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,5 @@ repos:
(
?^ci/scripts/c_glib_build\.sh$|
?^ci/scripts/c_glib_test\.sh$|
?^c_glib/test/run-test\.sh$|
)
6 changes: 3 additions & 3 deletions c_glib/test/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# specific language governing permissions and limitations
# under the License.

test_dir="$(cd $(dirname $0); pwd)"
test_dir="$(cd "$(dirname "$0")" && pwd)"
build_dir="$(cd .; pwd)"

modules=(
Expand Down Expand Up @@ -47,7 +47,7 @@ if [ "${BUILD}" != "no" ]; then
fi

for module in "${modules[@]}"; do
MODULE_TYPELIB_DIR_VAR_NAME="$(echo ${module} | tr a-z- A-Z_)_TYPELIB_DIR"
MODULE_TYPELIB_DIR_VAR_NAME="$(echo "${module}" | tr a-z- A-Z_)_TYPELIB_DIR"
module_typelib_dir=$(eval "echo \${${MODULE_TYPELIB_DIR_VAR_NAME}}")
if [ -z "${module_typelib_dir}" ]; then
module_typelib_dir="${build_dir}/${module}"
Expand All @@ -74,4 +74,4 @@ case "${DEBUGGER}" in
DEBUGGER_ARGS+=(--)
;;
esac
${DEBUGGER} "${DEBUGGER_ARGS[@]}" "${RUBY}" ${test_dir}/run-test.rb "$@"
${DEBUGGER} "${DEBUGGER_ARGS[@]}" "${RUBY}" "${test_dir}"/run-test.rb "$@"

0 comments on commit 9e08c57

Please sign in to comment.