-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.sh
executable file
·110 lines (87 loc) · 3.21 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
set -e -o pipefail
# Test that we only pass twin colors to these methods, not numbers
grep -En 'Foreground\([1-9]' ./*.go ./*/*.go && exit 1
grep -En 'Background\([1-9]' ./*.go ./*/*.go && exit 1
# Compile test first
echo Building sources...
./build.sh
# Linting
echo 'Linting, repro any errors locally using "golangci-lint run"...'
echo ' Linting without tests...'
golangci-lint run --tests=false
echo ' Linting with tests...'
golangci-lint run --tests=true
# Unit tests
echo "Running unit tests..."
RACE=-race
if [ "$GOARCH" == "386" ]; then
# -race is not supported on i386
RACE=""
fi
go test $RACE -timeout 20s ./...
# Ensure we can cross compile
# NOTE: Make sure this list matches the one in release.sh
echo "Testing cross compilation..."
echo " Linux i386..."
GOOS=linux GOARCH=386 ./build.sh
# Ref:
echo " Linux amd64..."
GOOS=linux GOARCH=amd64 ./build.sh
# Ref: https://github.com/walles/moar/issues/122
echo " Linux arm32..."
GOOS=linux GOARCH=arm ./build.sh
echo " macOS amd64..."
GOOS=darwin GOARCH=amd64 ./build.sh
echo " Windows amd64..."
GOOS=windows GOARCH=amd64 ./build.sh
# Build locally so we can do our testing
echo "Doing a local build so we can continue testing..."
./build.sh
# Verify sending the output to a file
RESULT="$(mktemp)"
function cleanup {
rm -rf "${RESULT}"
}
trap cleanup EXIT
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}"
# Ref: https://github.com/walles/moar/issues/187
echo Test redirecting multiple files by name into redirected stdout...
./moar moar.go moar.go >"${RESULT}"
diff -u <(cat moar.go 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
echo Testing not crashing with different argument orders...
./moar +123 moar.go >/dev/null
./moar moar.go +123 >/dev/null
./moar +123 --trace moar.go >/dev/null
./moar --trace +123 moar.go >/dev/null
./moar --trace moar.go +123 >/dev/null
# We can only do this test if we have a terminal. This means it will be run
# locally but not in CI. Not great, but better than nothing.
if [[ -t 1 ]]; then
echo Test auto quitting on single screen...
echo " (success)" | ./moar --quit-if-one-screen
fi
echo Test decompressing while piping
# Related to https://github.com/walles/moar/issues/177
./moar sample-files/compressed.txt.gz | grep compressed >/dev/null
echo Test --version...
./moar --version >/dev/null # Should exit with code 0
diff -u <(./moar --version) <(git describe --tags --dirty --always)
echo Test that the man page and --help document the same set of options...
MAN_OPTIONS="$(grep -E '^\\fB\\-' moar.1 | cut -d\\ -f4- | sed 's/fR.*//' | sed 's/\\//g')"
MOAR_OPTIONS="$(./moar --help | grep -E '^ -' | cut -d' ' -f3 | grep -v -- -version)"
diff -u <(echo "${MAN_OPTIONS}") <(echo "${MOAR_OPTIONS}")
# FIXME: On unknown command line options, test that help text goes to stderr
./scripts/test-path-help.sh "$(realpath ./moar)"
echo
echo "All tests passed!"