1
1
mirror of https://github.com/nmattia/snack.git synced 2024-09-11 03:45:32 +03:00
snack/script/test

83 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2018-02-14 02:56:23 +03:00
#!/usr/bin/env nix-shell
#!nix-shell -i bash
#!nix-shell -I nixpkgs=./nix
2018-07-02 23:56:26 +03:00
#!nix-shell -p git
2018-06-23 19:16:15 +03:00
#!nix-shell -p jq
2018-07-01 14:42:51 +03:00
#!nix-shell -p nix
2018-07-02 23:56:26 +03:00
#!nix-shell -p shfmt
2019-02-22 13:31:19 +03:00
#!nix-shell -p packages.snack-exe
2018-07-02 23:56:26 +03:00
#!nix-shell -p glibcLocales
2018-02-14 02:56:23 +03:00
#!nix-shell --pure
# vim: ft=sh sw=2 et
set -euo pipefail
2018-02-14 02:56:23 +03:00
2018-07-02 23:56:26 +03:00
export LC_ALL="en_US.utf-8"
export LANG="en_US.utf-8"
## Functions
banner() {
2018-07-01 14:42:51 +03:00
echo
echo "--- $*"
}
2018-06-01 00:25:21 +03:00
capture_io() {
2018-07-01 14:42:51 +03:00
OUT_FILE="$1"
2018-06-01 00:25:21 +03:00
2018-07-01 14:42:51 +03:00
cat <<END_HEREDOC
2018-06-01 00:25:21 +03:00
import GHC.IO.Handle
import System.IO
old_stdout <- hDuplicate stdout
:{
withFile "$OUT_FILE" WriteMode $ \\h -> do
hDuplicateTo h stdout
$2
hDuplicateTo old_stdout stdout
:}
END_HEREDOC
}
export -f capture_io
fail() {
echo "ERROR: $*"
exit 1
}
## Main
2018-08-26 17:51:18 +03:00
# Run the test name provided on the CLI _or_ all tests if none was provided
SNACK_TESTS=""
while [[ $# -gt 0 ]]; do
arg="$1"
2018-07-03 16:55:56 +03:00
2018-08-26 17:51:18 +03:00
SNACK_TESTS="$SNACK_TESTS $arg"
shift
done
2018-07-03 16:55:56 +03:00
2018-08-26 17:51:18 +03:00
if [ -z "$SNACK_TESTS" ]; then
SNACK_TESTS=$(ls tests | xargs -n 1 basename)
fi
2018-07-11 19:49:00 +03:00
cd "$(dirname "$0")/.."
2018-07-29 20:36:20 +03:00
2018-08-26 17:51:18 +03:00
echo "Running the following tests:"
for t in $SNACK_TESTS; do
echo " - $t"
done
for t in $SNACK_TESTS; do
2018-10-21 14:10:35 +03:00
banner "Test $t"
2018-08-26 17:51:18 +03:00
pushd "tests/$t"
./test
popd
done
2018-08-26 16:45:06 +03:00
2018-07-01 14:42:51 +03:00
banner "Test this file's formatting"
list=$(shfmt -i 2 -l script/test)
if [[ -n "$list" ]]; then
2018-07-01 14:42:51 +03:00
fail "Please apply script/snack-fmt to format script/test"
fi
echo OK