Skip to content

Commit 136a113

Browse files
matttbekuba-moo
authored andcommitted
tests: shellcheck: print full path in logs
It is clearer, and helpful when multiple files have the same base name. Even more when we only have the SHA to print. To get that, we can simply use an associative array variable. While at it, move some code out of the sub-shells, the same way before and after the patch, to only use these sub-shells when changing directories. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 9361c52 commit 136a113

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

tests/patch/shellcheck/shellcheck.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ git checkout -q HEAD~
3232

3333
# Also ignore created, as not present in the parent commit
3434
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
35-
(
36-
sha=$(echo "$f" | sha256sum | awk '{print $1}')
37-
echo "Checking $f - $sha"
38-
echo
35+
sha=$(echo "$f" | sha256sum | awk '{print $1}')
36+
echo "Checking $f - $sha"
37+
echo
3938

39+
(
4040
cd "$(dirname "$f")" || exit 1
4141
sha="${tmpfile_o}_${sha}"
4242
rm -f "${sha}"
@@ -53,12 +53,14 @@ incumbent_w=$(grep -c " (warning):" "$tmpfile_o")
5353
pr "Checking the tree with the patch"
5454
git checkout -q "$HEAD"
5555

56+
declare -A files
5657
for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
57-
(
58-
sha=$(echo "$f" | sha256sum | awk '{print $1}')
59-
echo "Checking $f - $sha"
60-
echo
58+
sha=$(echo "$f" | sha256sum | awk '{print $1}')
59+
files[${sha}]="${f}"
60+
echo "Checking $f - $sha"
61+
echo
6162

63+
(
6264
cd "$(dirname "$f")" || exit 1
6365
sha="${tmpfile_n}_${sha}"
6466
rm -f "${sha}"
@@ -74,16 +76,16 @@ current_w=$(grep -c " (warning):" "$tmpfile_n")
7476
# if a file was compliant before or is new, mark everything as error to keep it good.
7577
for f in "${tmpfile_n}_"*; do
7678
sha="${f:${#tmpfile_n}+1}"
77-
[ ! -s "${f}" ] && echo "${sha} is shellcheck compliant" && continue
79+
fpath="${files[${sha}]}"
80+
[ ! -s "${f}" ] && echo "${fpath} is shellcheck compliant" && continue
7881

7982
old="${tmpfile_o}_${sha}"
8083
[ -s "${old}" ] && continue # wasn't compliant
8184

82-
fname=$(head -n2 "${f}" | tail -n1 | sed "s/^In \(\S\+\.sh\) line [0-9]\+:/\1/g")
8385
if [ -f "${old}" ]; then
84-
echo "${fname} was shellcheck compliant, not anymore" 1>&2
86+
echo "${fpath} was shellcheck compliant, not anymore" 1>&2
8587
else
86-
echo "${fname} is a new file, but not shellcheck compliant" 1>&2
88+
echo "${fpath} is a new file, but not shellcheck compliant" 1>&2
8789
fi
8890

8991
extra=$(grep -c -E " \((warning|info|style)\):" "${f}")

0 commit comments

Comments
 (0)