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
|
|
|
|
2022-02-13 10:16:30 +03:00
|
|
|
# Test that we only pass twin colors 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
|
2021-04-27 08:05:52 +03:00
|
|
|
echo Building sources...
|
2021-04-19 08:16:58 +03:00
|
|
|
./build.sh
|
|
|
|
|
2021-04-19 16:18:51 +03:00
|
|
|
# Linting
|
2022-02-13 10:22:57 +03:00
|
|
|
echo 'Linting, repro any errors locally using "golangci-lint run"...'
|
2022-02-13 10:16:30 +03:00
|
|
|
echo ' Linting without tests...'
|
2022-02-13 10:22:57 +03:00
|
|
|
golangci-lint run --tests=false
|
2022-02-13 10:16:30 +03:00
|
|
|
echo ' Linting with tests...'
|
2022-02-13 10:22:57 +03:00
|
|
|
golangci-lint run --tests=true
|
2021-04-19 16:18:51 +03:00
|
|
|
|
2021-04-21 09:32:31 +03:00
|
|
|
# Unit tests
|
|
|
|
echo "Running unit tests..."
|
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
|
2022-12-19 12:05:07 +03:00
|
|
|
echo "Testing cross compilation..."
|
2022-12-19 12:08:38 +03:00
|
|
|
echo " Linux i386..."
|
2019-07-07 19:34:05 +03:00
|
|
|
GOOS=linux GOARCH=386 ./build.sh
|
2023-02-22 21:48:31 +03:00
|
|
|
|
|
|
|
# Ref: https://github.com/walles/moar/issues/122
|
2023-02-22 21:58:29 +03:00
|
|
|
echo " Linux arm32..."
|
2023-02-22 21:48:31 +03:00
|
|
|
GOOS=linux GOARCH=arm ./build.sh
|
|
|
|
|
2022-12-19 12:08:38 +03:00
|
|
|
echo " macOS amd64..."
|
2019-07-07 19:34:05 +03:00
|
|
|
GOOS=darwin GOARCH=amd64 ./build.sh
|
2022-12-19 12:08:38 +03:00
|
|
|
echo " Windows amd64..."
|
2021-09-10 07:50:44 +03:00
|
|
|
GOOS=windows GOARCH=amd64 ./build.sh
|
2019-07-07 19:34:05 +03:00
|
|
|
|
2023-01-22 13:36:43 +03:00
|
|
|
# Build locally so we can do our testing
|
|
|
|
echo "Doing a local build so we can continue testing..."
|
|
|
|
./build.sh
|
|
|
|
|
2019-07-07 19:34:05 +03:00
|
|
|
# Verify sending the output to a file
|
2019-06-09 23:03:25 +03:00
|
|
|
RESULT="$(mktemp)"
|
|
|
|
function cleanup {
|
2022-12-19 12:05:07 +03:00
|
|
|
rm -rf "${RESULT}"
|
2019-06-09 23:03:25 +03:00
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
echo Test reading from redirected stdin, writing to redirected stdout...
|
2022-12-19 12:05:07 +03:00
|
|
|
./moar <moar.go >"${RESULT}"
|
|
|
|
diff -u moar.go "${RESULT}"
|
2019-06-09 23:03:25 +03:00
|
|
|
|
|
|
|
echo Test redirecting a file by name into file by redirecting stdout...
|
2022-12-19 12:05:07 +03:00
|
|
|
./moar moar.go >"${RESULT}"
|
|
|
|
diff -u moar.go "${RESULT}"
|
2019-06-09 23:03:25 +03:00
|
|
|
|
|
|
|
echo Test redirecting non-existing file by name into redirected stdout...
|
2022-04-18 09:41:40 +03:00
|
|
|
if ./moar does-not-exist >&/dev/null; then
|
|
|
|
echo ERROR: Should have failed on non-existing input file name
|
|
|
|
exit 1
|
2019-06-09 23:03:25 +03:00
|
|
|
fi
|
2019-06-09 20:55:49 +03:00
|
|
|
|
2019-07-07 19:23:57 +03:00
|
|
|
echo Test --version...
|
2022-04-18 09:41:40 +03:00
|
|
|
./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
|
|
|
|
2022-07-22 12:26:04 +03:00
|
|
|
echo Test that the man page and --help document the same set of options...
|
2022-07-22 10:05:09 +03:00
|
|
|
MAN_OPTIONS="$(grep -E '^\\fB' moar.1 | cut -d\\ -f4- | sed 's/fR.*//' | sed 's/\\//g')"
|
2022-07-22 12:26:04 +03:00
|
|
|
MOAR_OPTIONS="$(./moar --help | grep -E '^ -' | cut -d' ' -f3 | grep -v -- -version)"
|
2022-12-19 12:05:07 +03:00
|
|
|
diff -u <(echo "${MAN_OPTIONS}") <(echo "${MOAR_OPTIONS}")
|
2022-07-22 09:45:27 +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
|
|
|
|
2022-04-18 09:41:40 +03:00
|
|
|
./scripts/test-path-help.sh "$(realpath ./moar)"
|
|
|
|
|
2019-06-09 20:55:49 +03:00
|
|
|
echo
|
|
|
|
echo "All tests passed!"
|