From 9a1ad7bc0dd8a0769738ca4dffbeb8d55438b0dc Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sun, 7 Nov 2021 14:13:39 +0200 Subject: test: Enable SC2086 shellcheck rule --- test/lint/commit-script-check.sh | 16 ++++++++-------- test/lint/git-subtree-check.sh | 10 ++++++---- test/lint/lint-files.sh | 2 +- test/lint/lint-git-commit-check.sh | 2 +- test/lint/lint-includes.sh | 2 +- test/lint/lint-shell.sh | 6 +++--- 6 files changed, 20 insertions(+), 18 deletions(-) (limited to 'test/lint') diff --git a/test/lint/commit-script-check.sh b/test/lint/commit-script-check.sh index 9fca1129b6..912bb24f9d 100755 --- a/test/lint/commit-script-check.sh +++ b/test/lint/commit-script-check.sh @@ -12,7 +12,7 @@ # one. Any remaining diff signals an error. export LC_ALL=C -if test -z $1; then +if test -z "$1"; then echo "Usage: $0 ..." exit 1 fi @@ -20,10 +20,10 @@ fi RET=0 PREV_BRANCH=$(git name-rev --name-only HEAD) PREV_HEAD=$(git rev-parse HEAD) -for commit in $(git rev-list --reverse $1); do - if git rev-list -n 1 --pretty="%s" $commit | grep -q "^scripted-diff:"; then - git checkout --quiet $commit^ || exit - SCRIPT="$(git rev-list --format=%b -n1 $commit | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d')" +for commit in $(git rev-list --reverse "$1"); do + if git rev-list -n 1 --pretty="%s" "$commit" | grep -q "^scripted-diff:"; then + git checkout --quiet "$commit"^ || exit + SCRIPT="$(git rev-list --format=%b -n1 "$commit" | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d')" if test -z "$SCRIPT"; then echo "Error: missing script for: $commit" echo "Failed" @@ -32,16 +32,16 @@ for commit in $(git rev-list --reverse $1); do echo "Running script for: $commit" echo "$SCRIPT" (eval "$SCRIPT") - git --no-pager diff --exit-code $commit && echo "OK" || (echo "Failed"; false) || RET=1 + git --no-pager diff --exit-code "$commit" && echo "OK" || (echo "Failed"; false) || RET=1 fi git reset --quiet --hard HEAD else - if git rev-list "--format=%b" -n1 $commit | grep -q '^-\(BEGIN\|END\)[ a-zA-Z]*-$'; then + if git rev-list "--format=%b" -n1 "$commit" | grep -q '^-\(BEGIN\|END\)[ a-zA-Z]*-$'; then echo "Error: script block marker but no scripted-diff in title of commit $commit" echo "Failed" RET=1 fi fi done -git checkout --quiet $PREV_BRANCH 2>/dev/null || git checkout --quiet $PREV_HEAD +git checkout --quiet "$PREV_BRANCH" 2>/dev/null || git checkout --quiet "$PREV_HEAD" exit $RET diff --git a/test/lint/git-subtree-check.sh b/test/lint/git-subtree-check.sh index 3556e49e08..cdaa5752ac 100755 --- a/test/lint/git-subtree-check.sh +++ b/test/lint/git-subtree-check.sh @@ -82,6 +82,7 @@ if [ -z "$latest_squash" ]; then echo "ERROR: $DIR is not a subtree" >&2 exit 2 fi +# shellcheck disable=SC2086 set $latest_squash old=$1 rev=$2 @@ -92,6 +93,7 @@ if [ -z "$tree_actual" ]; then echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2 exit 1 fi +# shellcheck disable=SC2086 set $tree_actual tree_actual_type=$2 tree_actual_tree=$3 @@ -102,23 +104,23 @@ if [ "d$tree_actual_type" != "dtree" ]; then fi # get the tree at the time of the last subtree update -tree_commit=$(git show -s --format="%T" $old) +tree_commit=$(git show -s --format="%T" "$old") echo "$DIR in $COMMIT was last updated in commit $old (tree $tree_commit)" # ... and compare the actual tree with it if [ "$tree_actual_tree" != "$tree_commit" ]; then - git diff $tree_commit $tree_actual_tree >&2 + git diff "$tree_commit" "$tree_actual_tree" >&2 echo "FAIL: subtree directory was touched without subtree merge" >&2 exit 1 fi if [ "$check_remote" != "0" ]; then # get the tree in the subtree commit referred to - if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then + if [ "d$(git cat-file -t "$rev" 2>/dev/null)" != dcommit ]; then echo "subtree commit $rev unavailable: cannot compare. Did you add and fetch the remote?" >&2 exit 1 fi - tree_subtree=$(git show -s --format="%T" $rev) + tree_subtree=$(git show -s --format="%T" "$rev") echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)" # ... and compare the actual tree with it diff --git a/test/lint/lint-files.sh b/test/lint/lint-files.sh index 1e115778bd..f9ede4bc68 100755 --- a/test/lint/lint-files.sh +++ b/test/lint/lint-files.sh @@ -3,5 +3,5 @@ export LC_ALL=C set -e -cd "$(dirname $0)/../.." +cd "$(dirname "$0")/../.." test/lint/lint-files.py diff --git a/test/lint/lint-git-commit-check.sh b/test/lint/lint-git-commit-check.sh index 2b3a9b87c2..d1ab72658b 100755 --- a/test/lint/lint-git-commit-check.sh +++ b/test/lint/lint-git-commit-check.sh @@ -38,7 +38,7 @@ while IFS= read -r commit_hash || [[ -n "$commit_hash" ]]; do while IFS= read -r line || [[ -n "$line" ]]; do n_line=$((n_line+1)) length=${#line} - if [ $n_line -eq 2 ] && [ $length -ne 0 ]; then + if [ $n_line -eq 2 ] && [ "$length" -ne 0 ]; then echo "The subject line of commit hash ${commit_hash} is followed by a non-empty line. Subject lines should always be followed by a blank line." EXIT_CODE=1 fi diff --git a/test/lint/lint-includes.sh b/test/lint/lint-includes.sh index e9893558e4..9b19699dab 100755 --- a/test/lint/lint-includes.sh +++ b/test/lint/lint-includes.sh @@ -12,7 +12,7 @@ export LC_ALL=C IGNORE_REGEXP="/(leveldb|secp256k1|minisketch|univalue|crc32c)/" # cd to root folder of git repo for git ls-files to work properly -cd "$(dirname $0)/../.." || exit 1 +cd "$(dirname "$0")/../.." || exit 1 filter_suffix() { git ls-files | grep -E "^src/.*\.${1}"'$' | grep -Ev "${IGNORE_REGEXP}" diff --git a/test/lint/lint-shell.sh b/test/lint/lint-shell.sh index 0e18c73013..1a12df6591 100755 --- a/test/lint/lint-shell.sh +++ b/test/lint/lint-shell.sh @@ -11,7 +11,6 @@ export LC_ALL=C # Disabled warnings: disabled=( SC2046 # Quote this to prevent word splitting. - SC2086 # Double quote to prevent globbing and word splitting. SC2162 # read without -r will mangle backslashes. ) @@ -24,8 +23,9 @@ fi SHELLCHECK_CMD=(shellcheck --external-sources --check-sourced) EXCLUDE="--exclude=$(IFS=','; echo "${disabled[*]}")" -SOURCED_FILES=$(git ls-files | xargs gawk '/^# shellcheck shell=/ {print FILENAME} {nextfile}') # Check shellcheck directive used for sourced files -if ! "${SHELLCHECK_CMD[@]}" "$EXCLUDE" $SOURCED_FILES $(git ls-files -- '*.sh' | grep -vE 'src/(leveldb|secp256k1|minisketch|univalue)/'); then +# Check shellcheck directive used for sourced files +mapfile -t SOURCED_FILES < <(git ls-files | xargs gawk '/^# shellcheck shell=/ {print FILENAME} {nextfile}') +if ! "${SHELLCHECK_CMD[@]}" "$EXCLUDE" "${SOURCED_FILES[@]}" $(git ls-files -- '*.sh' | grep -vE 'src/(leveldb|secp256k1|minisketch|univalue)/'); then EXIT_CODE=1 fi -- cgit v1.2.3