From 0bcf3fd3a9049fdc5574d8868f55ba9c277ce280 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Thu, 3 Oct 2019 01:53:00 +0200 Subject: [PATCH] Add some tests for shell scripts --- Makefile | 7 +++++-- scripts/test.sh | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 scripts/test.sh diff --git a/Makefile b/Makefile index deeb7ee..353f9c1 100644 --- a/Makefile +++ b/Makefile @@ -41,15 +41,18 @@ sanitize: # # -build: test submodules bin/resh-collect bin/resh-daemon bin/resh-evaluate bin/resh-sanitize +build: test_go submodules bin/resh-collect bin/resh-daemon bin/resh-evaluate bin/resh-sanitize -test: +test_go: # Running tests @for dir in {cmd,pkg}/* ; do \ echo $$dir ; \ go test $$dir/*.go ; \ done +test: + scripts/test.sh + rebuild: make clean make build diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..3eca974 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +[ "${BASH_SOURCE[0]}" != "scripts/test.sh" ] && echo 'Run this script using `make test`' && exit 1 + +for f in scripts/*.sh; do + echo "Running shellcheck on $f ..." + shellcheck $f --shell=bash --severity=error || exit 1 +done + +echo "Checking Zsh syntax of scripts/shellrc.sh ..." +! zsh -n scripts/shellrc.sh && echo "Zsh syntax check failed!" && exit 1 + +for sh in bash zsh; do + echo "Running functions in scripts/shellrc.sh using $sh ..." + ! $sh -c ". scripts/shellrc.sh; __resh_preexec; __resh_precmd" && echo "Error while running functions!" && exit 1 +done + +# TODO: test installation + +exit 0