Skip to content

[C++] Fix shellcheck errors in cpp/build-support/run-test.sh #50934

Description

@hiroyuki-sato

Describe the enhancement requested

This is the sub issue #44748.

  • SC2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
  • SC2035: Use ./glob or -- glob so names with dashes won't become options.
  • SC2046: Quote this to prevent word splitting.
  • SC2048: Use "$@" (with quotes) to prevent whitespace problems.
  • SC2086: Double quote to prevent globbing and word splitting.
  • SC2128: Expanding an array without an index only gives the element in the index 0.
  • SC2164: Use cd ... || exit in case cd fails.
  • SC2209: Use var=$(command) to assign output (or quote to assign string).

In cpp/build-support/run-test.sh line 28:
ROOT=$(cd $(dirname $BASH_SOURCE)/..; pwd)
^---------------------------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
^---------------------^ SC2046 (warning): Quote this to prevent word splitting.
^----------^ SC2128 (warning): Expanding an array without an index only gives the first element.
^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
ROOT=$(cd $(dirname "$BASH_SOURCE")/.. || exit; pwd)
In cpp/build-support/run-test.sh line 31:
mkdir -p $TEST_LOGDIR
^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
mkdir -p "$TEST_LOGDIR"
In cpp/build-support/run-test.sh line 36:
mkdir -p $TEST_DEBUGDIR
^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
mkdir -p "$TEST_DEBUGDIR"
In cpp/build-support/run-test.sh line 38:
TEST_DIRNAME=$(cd $(dirname $1); 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_DIRNAME=$(cd $(dirname "$1") || exit; pwd)
In cpp/build-support/run-test.sh line 39:
TEST_FILENAME=$(basename $1)
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
TEST_FILENAME=$(basename "$1")
In cpp/build-support/run-test.sh line 42:
TEST_NAME=$(echo $TEST_FILENAME | sed -E -e 's/\..+$//') # Remove path and extension (if any).
^------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
TEST_NAME=$(echo "$TEST_FILENAME" | sed -E -e 's/\..+$//') # Remove path and extension (if any).
In cpp/build-support/run-test.sh line 46:
mkdir -p $TEST_WORKDIR
^-----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
mkdir -p "$TEST_WORKDIR"
In cpp/build-support/run-test.sh line 47:
pushd $TEST_WORKDIR >/dev/null || exit 1
^-----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
pushd "$TEST_WORKDIR" >/dev/null || exit 1
In cpp/build-support/run-test.sh line 48:
rm -f *
^-- SC2035 (info): Use ./*glob* or -- *glob* so names with dashes won't become options.
In cpp/build-support/run-test.sh line 59:
rm -f $LOGFILE $LOGFILE.gz
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
rm -f "$LOGFILE" "$LOGFILE".gz
In cpp/build-support/run-test.sh line 61:
pipe_cmd=cat
^------^ SC2209 (warning): Use var=$(command) to assign output (or quote to assign string).
In cpp/build-support/run-test.sh line 93:
rm -f $XMLFILE
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
rm -f "$XMLFILE"
In cpp/build-support/run-test.sh line 95:
$TEST_EXECUTABLE "$@" > $LOGFILE.raw 2>&1
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
$TEST_EXECUTABLE "$@" > "$LOGFILE".raw 2>&1
In cpp/build-support/run-test.sh line 97:
cat $LOGFILE.raw \
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
cat "$LOGFILE".raw \
In cpp/build-support/run-test.sh line 98:
| ${PYTHON:-python} $ROOT/build-support/asan_symbolize.py \
^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
| ${PYTHON:-python} "$ROOT"/build-support/asan_symbolize.py \
In cpp/build-support/run-test.sh line 100:
| $pipe_cmd 2>&1 | tee $LOGFILE
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
| $pipe_cmd 2>&1 | tee "$LOGFILE"
In cpp/build-support/run-test.sh line 101:
rm -f $LOGFILE.raw
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
rm -f "$LOGFILE".raw
In cpp/build-support/run-test.sh line 111:
if grep -E -q "ThreadSanitizer|Leak check.*detected leaks" $LOGFILE ; then
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
if grep -E -q "ThreadSanitizer|Leak check.*detected leaks" "$LOGFILE" ; then
In cpp/build-support/run-test.sh line 112:
echo ThreadSanitizer or leak check failures in $LOGFILE
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
echo ThreadSanitizer or leak check failures in "$LOGFILE"
In cpp/build-support/run-test.sh line 114:
rm -f $XMLFILE
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
rm -f "$XMLFILE"
In cpp/build-support/run-test.sh line 137:
FILENAME=$(echo ${FILENAME} | cut -c-15)
^---------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
FILENAME=$(echo "${FILENAME}" | cut -c-15)
In cpp/build-support/run-test.sh line 140:
COREFILES=$(ls /tmp | grep $PATTERN)
^-- SC2010 (warning): Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
COREFILES=$(ls /tmp | grep "$PATTERN")
In cpp/build-support/run-test.sh line 150:
gdb -c "${COREPATH}" $TEST_EXECUTABLE -ex "thread apply all bt" -ex "set pagination 0" -batch
^--------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
gdb -c "${COREPATH}" "$TEST_EXECUTABLE" -ex "thread apply all bt" -ex "set pagination 0" -batch
In cpp/build-support/run-test.sh line 163:
if grep -E -q "ERROR: LeakSanitizer: detected memory leaks" $LOGFILE ; then
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
if grep -E -q "ERROR: LeakSanitizer: detected memory leaks" "$LOGFILE" ; then
In cpp/build-support/run-test.sh line 171:
$XMLFILE
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
"$XMLFILE"
In cpp/build-support/run-test.sh line 172:
mv $XMLFILE.bak $XMLFILE
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
mv "$XMLFILE".bak "$XMLFILE"
In cpp/build-support/run-test.sh line 178:
$TEST_EXECUTABLE "$@" 2>&1 | $pipe_cmd > $LOGFILE
^------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
$TEST_EXECUTABLE "$@" 2>&1 | $pipe_cmd > "$LOGFILE"
In cpp/build-support/run-test.sh line 182:
if [ $RUN_TYPE = "test" ]; then
^-------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
if [ "$RUN_TYPE" = "test" ]; then
In cpp/build-support/run-test.sh line 188:
if [ $ATTEMPT_NUMBER -lt $TEST_EXECUTION_ATTEMPTS ]; then
^-------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
if [ "$ATTEMPT_NUMBER" -lt $TEST_EXECUTION_ATTEMPTS ]; then
In cpp/build-support/run-test.sh line 195:
TEST_TMPDIR_BEFORE=$(find $TEST_TMPDIR -maxdepth 1 -type d | sort)
^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
TEST_TMPDIR_BEFORE=$(find "$TEST_TMPDIR" -maxdepth 1 -type d | sort)
In cpp/build-support/run-test.sh line 198:
if [ $ATTEMPT_NUMBER -lt $TEST_EXECUTION_ATTEMPTS ]; then
^-------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
if [ "$ATTEMPT_NUMBER" -lt $TEST_EXECUTION_ATTEMPTS ]; then
In cpp/build-support/run-test.sh line 200:
TEST_TMPDIR_AFTER=$(find $TEST_TMPDIR -maxdepth 1 -type d | sort)
^----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
TEST_TMPDIR_AFTER=$(find "$TEST_TMPDIR" -maxdepth 1 -type d | sort)
In cpp/build-support/run-test.sh line 218:
if [ $RUN_TYPE = "test" ]; then
^-------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
if [ "$RUN_TYPE" = "test" ]; then
In cpp/build-support/run-test.sh line 219:
run_test $*
^-- SC2048 (warning): Use "$@" (with quotes) to prevent whitespace problems.
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
run_test "$*"
In cpp/build-support/run-test.sh line 221:
run_other $*
^-- SC2048 (warning): Use "$@" (with quotes) to prevent whitespace problems.
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
run_other "$*"
In cpp/build-support/run-test.sh line 226:
echo Test failed attempt number $ATTEMPT_NUMBER
^-------------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
echo Test failed attempt number "$ATTEMPT_NUMBER"
In cpp/build-support/run-test.sh line 231:
if [ $RUN_TYPE = "test" ]; then
^-------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
if [ "$RUN_TYPE" = "test" ]; then
In cpp/build-support/run-test.sh line 237:
popd
^--^ SC2164 (warning): Use 'popd ... || exit' or 'popd ... || return' in case popd fails.
Did you mean:
popd || exit
In cpp/build-support/run-test.sh line 238:
rm -Rf $TEST_WORKDIR
^-----------^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
rm -Rf "$TEST_WORKDIR"
In cpp/build-support/run-test.sh line 240:
exit $STATUS
^-----^ SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean:
exit "$STATUS"
For more information:
https://www.shellcheck.net/wiki/SC2010 -- Don't use ls | grep. Use a glob o...
https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
https://www.shellcheck.net/wiki/SC2048 -- Use "$@" (with quotes) to prevent...

Component(s)

C++

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions