Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·160 lines (142 loc) · 4 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·160 lines (142 loc) · 4 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_DIR="${BUILD_DIR:-build}"
QT_CMAKE_BIN="${QT_CMAKE_BIN:-qt-cmake}"
usage() {
cat <<'EOF'
Usage:
./tools/test.sh configure
./tools/test.sh build
./tools/test.sh all
./tools/test.sh one <suite_regex>
./tools/test.sh js
./tools/test.sh js-one <suite_regex>
./tools/test.sh qml
./tools/test.sh qml-one <suite_regex>
./tools/test.sh list
Environment overrides:
BUILD_DIR=<dir> Build directory (default: build)
QT_CMAKE_BIN=<path> qt-cmake command/path (default: qt-cmake from PATH)
CTEST_JUNIT_FILE=<path> If set, write JUnit XML for GitLab test reports (ctest --output-junit)
Examples:
./tools/test.sh all
./tools/test.sh one test_json
./tools/test.sh one "test_(util|json)"
./tools/test.sh js
./tools/test.sh js-one util
./tools/test.sh qml
./tools/test.sh qml-one amountvalidator
EOF
}
configure_tests() {
if ! command -v "$QT_CMAKE_BIN" >/dev/null 2>&1; then
echo "Could not find '$QT_CMAKE_BIN' in PATH."
echo "Set QT_CMAKE_BIN to an explicit path or add qt-cmake to PATH."
exit 1
fi
"$QT_CMAKE_BIN" -S "$ROOT_DIR" -B "$ROOT_DIR/$BUILD_DIR" -DBUILD_TESTING=ON
}
build_tests() {
local build_path="$ROOT_DIR/$BUILD_DIR"
mapfile -t test_targets < <(
cmake --build "$build_path" --target help \
| awk '/^\.\.\. test_[A-Za-z0-9_]+$/ { t=$2; if (t !~ /(autogen|qmlimportscan|timestamp|copy_qml|copy_res|other_files|qmltyperegistration|lrelease|lupdate)/) print t }'
)
if [[ ${#test_targets[@]} -eq 0 ]]; then
echo "No buildable test_* targets found in $build_path."
return 0
fi
cmake --build "$build_path" --target "${test_targets[@]}"
}
run_all_tests() {
local ctest_args=(--test-dir "$ROOT_DIR/$BUILD_DIR" --output-on-failure)
if [[ -n "${CTEST_JUNIT_FILE:-}" ]]; then
mkdir -p "$(dirname "$CTEST_JUNIT_FILE")"
ctest_args+=(--output-junit "$CTEST_JUNIT_FILE")
fi
ctest "${ctest_args[@]}"
}
run_one_test() {
local suite_regex="${1:-}"
if [[ -z "$suite_regex" ]]; then
echo "Missing suite regex for 'one' command."
usage
exit 1
fi
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" -R "$suite_regex" --output-on-failure
}
run_js_tests() {
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" -R "test_js_" --output-on-failure
}
run_one_js_test() {
local suite_regex="${1:-}"
if [[ -z "$suite_regex" ]]; then
echo "Missing suite regex for 'js-one' command."
usage
exit 1
fi
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" -R "test_js_.*${suite_regex}" --output-on-failure
}
run_qml_tests() {
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" -R "test_qml_" --output-on-failure
}
run_one_qml_test() {
local suite_regex="${1:-}"
if [[ -z "$suite_regex" ]]; then
echo "Missing suite regex for 'qml-one' command."
usage
exit 1
fi
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" -R "test_qml_.*${suite_regex}" --output-on-failure
}
list_tests() {
ctest --test-dir "$ROOT_DIR/$BUILD_DIR" -N
}
main() {
local cmd="${1:-}"
case "$cmd" in
configure)
configure_tests
;;
build)
build_tests
;;
all)
configure_tests
build_tests
run_all_tests
;;
one)
configure_tests
build_tests
run_one_test "${2:-}"
;;
js)
configure_tests
run_js_tests
;;
js-one)
configure_tests
run_one_js_test "${2:-}"
;;
qml)
configure_tests
build_tests
run_qml_tests
;;
qml-one)
configure_tests
build_tests
run_one_qml_test "${2:-}"
;;
list)
list_tests
;;
*)
usage
exit 1
;;
esac
}
main "$@"