Repository navigation
Expand file tree
/
Copy pathrun_all_unit_tests.sh
More file actions
executable file
·118 lines (76 loc) · 2.2 KB
/
Copy pathrun_all_unit_tests.sh
File metadata and controls
executable file
·118 lines (76 loc) · 2.2 KB
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
111
112
113
114
115
116
117
118
#! /bin/bash
ScriptPath=$0
Dir=$(cd "$(dirname "$ScriptPath")" && pwd)
ProjectNameFile="$Dir/.sis/project_name.txt"
ProjectName=$(tr -d '[:space:]' < "$ProjectNameFile")
ListOnly=0
Verbosity=${XTESTS_VERBOSITY:-${TEST_VERBOSITY:-3}}
# ##########################################################
# command-line handling
while [[ $# -gt 0 ]]; do
case $1 in
-l|--list-only)
ListOnly=1
;;
--verbosity)
shift
Verbosity=$1
;;
--help)
[ -f "$Dir/.sis/script_info_lines.txt" ] && cat "$Dir/.sis/script_info_lines.txt"
cat << EOF
Runs all (matching) component and unit test packages
$ScriptPath [ ... flags/options ... ]
Flags/options:
behaviour:
-l
--list-only
lists the target packages but does not execute them
--verbosity <verbosity>
specifies an explicit verbosity for the unit-test(s)
standard flags:
--help
displays this help and terminates
EOF
exit 0
;;
*)
>&2 echo "$ScriptPath: unrecognised argument '$1'; use --help for usage"
exit 1
;;
esac
shift
done
# ##########################################################
# main()
cd "$Dir" || exit 1
# Only packages that contain tests (avoids broken multi-main examples/ dirs)
Packages=$(go list -f '{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}{{end}}' ./...)
if [ -z "$Packages" ]; then
echo "${ScriptPath}: no test packages found for ${ProjectName}"
exit 0
fi
if [ $ListOnly -ne 0 ]; then
echo "Listing all ${ProjectName} test packages"
printf '%s\n' $Packages
exit 0
fi
if [ $Verbosity -ge 2 ]; then
echo "Running all ${ProjectName} unit-test packages"
fi
#
# Mitigate rare macOS `dyld` aborts caused by corrupted cached `*.test` binaries.
#
go clean -cache -testcache
LD_FLAGS=""
if [ "$(uname -s)" = "Darwin" ]; then
# Older Go toolchains can produce Mach-O binaries without LC_UUID on newer macOS
# versions, triggering `dyld: missing LC_UUID load command ...` at test start.
LD_FLAGS="-ldflags=-linkmode=external"
fi
if [ $Verbosity -ge 2 ]; then
go test -v $LD_FLAGS $Packages
else
go test $LD_FLAGS $Packages
fi
# ############################## end of file ############################# #