-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.sh
More file actions
executable file
·125 lines (113 loc) · 3.57 KB
/
Copy pathtests.sh
File metadata and controls
executable file
·125 lines (113 loc) · 3.57 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
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
CRATES=(gitfleet-core gitfleet gitfleet-providers)
SELECTED_CRATE=""
TEST_KIND="all"
usage() {
printf 'Usage: %s [-a|--all] [-c|--crate CRATE]\n' "$(basename "$0")"
printf '\nCount unique Rust unit and integration test functions in the workspace.\n'
printf ' -a, --all count workspace tests (default)\n'
printf ' -c, --crate count one crate: core, cli, or providers\n'
printf ' --unit count unit tests only\n'
printf ' --integration count integration tests only\n'
printf ' -h, --help show this help\n'
}
while (($# > 0)); do
case "$1" in
-a|--all)
if [[ -n "$SELECTED_CRATE" ]]; then
printf 'Error: --all and --crate cannot be combined.\n' >&2
exit 2
fi
;;
-c|--crate)
if (($# < 2)); then
printf 'Error: --crate requires core, cli, or providers.\n' >&2
exit 2
fi
case "$2" in
core|gitfleet-core) SELECTED_CRATE=gitfleet-core ;;
cli|gitfleet) SELECTED_CRATE=gitfleet ;;
provider|providers|gitfleet-providers) SELECTED_CRATE=gitfleet-providers ;;
*)
printf 'Error: unknown crate: %s\n' "$2" >&2
exit 2
;;
esac
shift
;;
--unit)
if [[ "$TEST_KIND" != "all" ]]; then
printf 'Error: --unit and --integration cannot be combined.\n' >&2
exit 2
fi
TEST_KIND=unit
;;
--integration)
if [[ "$TEST_KIND" != "all" ]]; then
printf 'Error: --unit and --integration cannot be combined.\n' >&2
exit 2
fi
TEST_KIND=integration
;;
--crate=*)
crate_arg="${1#*=}"
case "$crate_arg" in
core|gitfleet-core) SELECTED_CRATE=gitfleet-core ;;
cli|gitfleet) SELECTED_CRATE=gitfleet ;;
provider|providers|gitfleet-providers) SELECTED_CRATE=gitfleet-providers ;;
*)
printf 'Error: unknown crate: %s\n' "$crate_arg" >&2
exit 2
;;
esac
;;
-h|--help)
usage
exit 0
;;
*)
printf 'Error: unknown option: %s\n' "$1" >&2
usage >&2
exit 2
;;
esac
shift
done
count_tests() {
local path="$1"
if [[ ! -d "$path" ]]; then
printf '0\n'
return
fi
find "$path" -type f -name '*.rs' -print0 |
xargs -0 awk '
/^[[:space:]]*#\[test\][[:space:]]*$/ { count++ }
/^[[:space:]]*#\[[[:alnum:]_]+::test\][[:space:]]*$/ { count++ }
END { print count + 0 }
'
}
unit_total=0
integration_total=0
if [[ -n "$SELECTED_CRATE" ]]; then
CRATES=("$SELECTED_CRATE")
fi
for crate in "${CRATES[@]}"; do
unit=$(count_tests "$ROOT_DIR/$crate/src")
integration=$(count_tests "$ROOT_DIR/$crate/tests")
total=$((unit + integration))
unit_total=$((unit_total + unit))
integration_total=$((integration_total + integration))
done
case "$TEST_KIND" in
unit)
printf '%d\n' "$unit_total"
;;
integration)
printf '%d\n' "$integration_total"
;;
all)
printf '%d\n' "$((unit_total + integration_total))"
;;
esac