aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2019-07-25 16:51:48 +0200
committerGravatar GitHub <noreply@github.com> 2019-07-25 16:51:48 +0200
commit82611c9622ed23b0e9fcf5f9f651ddffa1fd7706 (patch)
treefc2c97fd8dd84ec30473cb85b889d8326c9a831a /tests
parent744a9e8cf00aef7dec0acfa5f90f0dcfa2ef8837 (diff)
parent042b40eeeea77db854daab1bec96fce5c2cdd4b2 (diff)
Merge pull request #2451 from FreshRSS/dev1.14.3
FreshRSS 1.14.3
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md4
-rwxr-xr-xtests/shellchecks.sh29
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/README.md b/tests/README.md
index 3dd9602be..fbc38ac4d 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -5,3 +5,7 @@ cd ./tests/
wget https://phar.phpunit.de/phpunit.phar
php phpunit.phar --bootstrap bootstrap.php
```
+
+The `shellchecks.sh` script is used to safeguard shell scripts from common
+shell script bugs and to ensure a consistent style.
+It requires [ShellCheck](https://www.shellcheck.net/) and [shfmt](https://github.com/mvdan/sh).
diff --git a/tests/shellchecks.sh b/tests/shellchecks.sh
new file mode 100755
index 000000000..648f2766e
--- /dev/null
+++ b/tests/shellchecks.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+# Based on https://github.com/koreader/koreader/blob/master/.ci/helper_shellchecks.sh
+
+ANSI_RED="\\033[31;1m"
+ANSI_GREEN="\\033[32;1m"
+ANSI_RESET="\\033[0m"
+
+mapfile -t shellscript_locations < <({ git grep -lE '^#!(/usr)?/bin/(env )?(bash|sh)' && git ls-files ./*.sh; } | sort | uniq)
+
+SHELLSCRIPT_ERROR=0
+
+for shellscript in "${shellscript_locations[@]}"; do
+ echo -e "${ANSI_GREEN}Running shellcheck on ${shellscript}"
+ shellcheck "${shellscript}" || SHELLSCRIPT_ERROR=1
+ echo -e "${ANSI_GREEN}Running shfmt on ${shellscript}"
+ if ! shfmt "${shellscript}" >/dev/null 2>&1; then
+ echo -e "${ANSI_RED}Warning: ${shellscript} contains the following problem:"
+ shfmt "${shellscript}" || SHELLSCRIPT_ERROR=1
+ continue
+ fi
+ if [ "$(cat "${shellscript}")" != "$(shfmt "${shellscript}")" ]; then
+ echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style, diff for expected style:"
+ shfmt "${shellscript}" | diff "${shellscript}" - || SHELLSCRIPT_ERROR=1
+ fi
+done
+
+echo -ne "${ANSI_RESET}"
+
+exit "${SHELLSCRIPT_ERROR}"