From 9e08c57c0986531879aadf7942998d26a94a5d1b Mon Sep 17 00:00:00 2001 From: Takaaki Koike <93052259+tks1197@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:55:26 +0900 Subject: [PATCH] GH-45050: [CI][Dev] Apply ShellCheck lint to c_glib/test/run-test.sh (#45052) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 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: -- Quote this to prevent word splitt... -- Use 'cd ... || exit' or 'cd ... |... -- 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 Co-authored-by: Takaaki Koike <93052259+tks1197@users.noreply.github.com> Co-authored-by: Sutou Kouhei Signed-off-by: Sutou Kouhei --- .pre-commit-config.yaml | 1 + c_glib/test/run-test.sh | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6bde1cb2964e0..27823cae5fa28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -182,4 +182,5 @@ repos: ( ?^ci/scripts/c_glib_build\.sh$| ?^ci/scripts/c_glib_test\.sh$| + ?^c_glib/test/run-test\.sh$| ) diff --git a/c_glib/test/run-test.sh b/c_glib/test/run-test.sh index c7bc6edca5f0d..8b1868942073c 100755 --- a/c_glib/test/run-test.sh +++ b/c_glib/test/run-test.sh @@ -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=( @@ -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}" @@ -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 "$@"