Core

/bin/coverage.sh (901 B)

 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
#!/bin/bash

## Runs all the tests. Pass "-c" to clear the cache first, "-w" to watch for changes.

set -euo pipefail
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$dir/.."

do_clean=false

while getopts c option
do
case "${option}" in
c) do_clean=true;;
*) echo "unknown option"; exit 1;;
esac
done

test_args=""

if $do_clean; then
echo "cleaning test cache...";
go clean -testcache
fi

if [ -f "test.env" ]; then
while IFS= read -r line || [ -n "$line" ]; do
if [[ -n "$line" && ! $line =~ ^#.* ]]; then
export "${line?}"
fi
done < "test.env"
fi

if [ -f "./bin/test-setup.sh" ]; then
./bin/test-setup.sh
fi

gotestsum${test_args} -- -race -coverprofile ./tmp/coverage.out ./app/...

if command -v go-cover-treemap &> /dev/null; then
echo "generating code coverage SVG..."
go-cover-treemap -coverprofile ./tmp/coverage.out > ./tmp/coverage.svg
fi