2019-06-09 19:42:25 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-06-09 23:03:25 +03:00
|
|
|
set -e -o pipefail
|
2019-06-09 19:42:25 +03:00
|
|
|
|
2021-04-19 19:56:13 +03:00
|
|
|
# Latest version: https://github.com/dominikh/go-tools/releases/latest
|
|
|
|
STATICCHECK_VERSION=2020.2.3
|
|
|
|
|
2020-12-29 19:08:54 +03:00
|
|
|
# Test that we only pass tcell.Color constants to these methods, not numbers
|
2020-12-06 23:37:00 +03:00
|
|
|
grep -En 'Foreground\([1-9]' ./*.go ./*/*.go && exit 1
|
|
|
|
grep -En 'Background\([1-9]' ./*.go ./*/*.go && exit 1
|
|
|
|
|
2021-04-19 08:16:58 +03:00
|
|
|
# Compile test first
|
|
|
|
./build.sh
|
|
|
|
|
2021-04-19 16:18:51 +03:00
|
|
|
# Linting
|
|
|
|
MISFORMATTED="$(gofmt -l -s .)"
|
2021-04-19 08:16:58 +03:00
|
|
|
if [ -n "$MISFORMATTED" ]; then
|
|
|
|
echo >&2 "==="
|
2021-04-19 16:30:09 +03:00
|
|
|
echo >&2 "ERROR: The following files are not formatted, run './build.sh', './test.sh' or 'gofmt -s -w .' to fix:"
|
2021-04-19 08:16:58 +03:00
|
|
|
echo >&2 "$MISFORMATTED"
|
|
|
|
echo >&2 "==="
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-19 16:29:28 +03:00
|
|
|
# "go vet" catches fmt-placeholders-vs-args problems (and others)
|
|
|
|
if ! go vet . ./twin ./m ; then
|
|
|
|
if [ -n "${CI}" ]; then
|
|
|
|
echo >&2 "==="
|
|
|
|
echo >&2 "=== Please run './test.sh' before pushing to see these issues locally rather than in CI"
|
|
|
|
echo >&2 "==="
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-19 19:56:13 +03:00
|
|
|
# Docs: https://staticcheck.io/docs/
|
|
|
|
go get "honnef.co/go/tools/cmd/staticcheck@${STATICCHECK_VERSION}"
|
|
|
|
if ! "$(go env GOPATH)/bin/staticcheck" -f stylish . ./... ; then
|
|
|
|
if [ -n "${CI}" ]; then
|
|
|
|
echo >&2 "==="
|
|
|
|
echo >&2 "=== Please run './test.sh' before pushing to see these issues locally rather than in CI"
|
|
|
|
echo >&2 "==="
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-19 16:18:51 +03:00
|
|
|
# FIXME: Add https://staticcheck.io/docs/
|
|
|
|
# FIXME: Add https://github.com/kisielk/errcheck
|
|
|
|
|
2019-07-06 23:16:08 +03:00
|
|
|
# Unit tests first
|
2021-04-19 07:46:10 +03:00
|
|
|
go test -timeout 20s ./...
|
2019-06-09 19:42:25 +03:00
|
|
|
|
2019-07-07 19:34:05 +03:00
|
|
|
# Ensure we can cross compile
|
2019-08-04 20:07:14 +03:00
|
|
|
# NOTE: Make sure this list matches the one in release.sh
|
2019-07-07 19:34:05 +03:00
|
|
|
GOOS=linux GOARCH=386 ./build.sh
|
|
|
|
GOOS=darwin GOARCH=amd64 ./build.sh
|
|
|
|
|
|
|
|
# Verify sending the output to a file
|
2019-06-09 23:03:25 +03:00
|
|
|
RESULT="$(mktemp)"
|
|
|
|
function cleanup {
|
|
|
|
rm -rf "$RESULT"
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
echo Running to-file redirection tests...
|
|
|
|
|
|
|
|
echo Test reading from redirected stdin, writing to redirected stdout...
|
|
|
|
./moar < moar.go > "$RESULT"
|
|
|
|
diff -u moar.go "$RESULT"
|
|
|
|
|
|
|
|
echo Test redirecting a file by name into file by redirecting stdout...
|
|
|
|
./moar moar.go > "$RESULT"
|
|
|
|
diff -u moar.go "$RESULT"
|
|
|
|
|
|
|
|
echo Test redirecting non-existing file by name into redirected stdout...
|
|
|
|
if ./moar does-not-exist >& /dev/null ; then
|
|
|
|
echo ERROR: Should have failed on non-existing input file name
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-06-09 20:55:49 +03:00
|
|
|
|
2019-07-07 19:23:57 +03:00
|
|
|
echo Test --version...
|
|
|
|
./moar --version > /dev/null # Should exit with code 0
|
2021-04-15 16:16:06 +03:00
|
|
|
diff -u <(./moar --version) <(git describe --tags --dirty --always)
|
2019-07-07 19:23:57 +03:00
|
|
|
|
2019-07-15 23:14:36 +03:00
|
|
|
# FIXME: On unknown command line options, test that help text goes to stderr
|
2019-07-08 07:42:48 +03:00
|
|
|
|
2019-06-09 20:55:49 +03:00
|
|
|
echo
|
|
|
|
echo "All tests passed!"
|