@@ -18,12 +18,13 @@ Options:
18
18
-h, --help: Display this help message and exit
19
19
-l, --list: Display the list of tests and exit
20
20
-s, --system <system>: Launch checks for "<system>" instead of "${NIXVIM_SYSTEM} ".
21
+ -g, --group-size N: The maximum number of tests to build at once. Default 20.
21
22
-i, --interactive: Pick interactively the tests. Can't be supplied if tests where passed.
22
23
-a, --attr: Print full attrpath of the tests, instead of running them.
23
24
EOF
24
25
}
25
26
26
- if ! OPTS=$( getopt -o " hlis:a" -l " help,list,interactive,system:,attr" -- " $@ " ) ; then
27
+ if ! OPTS=$( getopt -o " hlis:g: a" -l " help,list,interactive,system:,group-size :,attr" -- " $@ " ) ; then
27
28
echo " Invalid options" >&2
28
29
help
29
30
exit 1
@@ -35,6 +36,7 @@ system=${NIXVIM_SYSTEM}
35
36
specified_tests=()
36
37
nix_args=()
37
38
interactive=false
39
+ group_size=20
38
40
print_attrpath=false
39
41
40
42
mk_test_list () {
@@ -55,6 +57,10 @@ while true; do
55
57
interactive=true
56
58
shift
57
59
;;
60
+ -g | --group-size)
61
+ group_size=$2
62
+ shift 2
63
+ ;;
58
64
-s | --system)
59
65
system=$2
60
66
shift 2
@@ -94,6 +100,50 @@ get_tests() {
94
100
done
95
101
}
96
102
103
+ build_group () {
104
+ if ! " ${NIXVIM_NIX_COMMAND} " build " ${nix_args[@]} " --no-link --file . " $@ " ; then
105
+ echo " Test failure" >&2
106
+ return 1
107
+ fi
108
+ }
109
+
110
+ build_in_groups () {
111
+ # Count failures
112
+ failures=0
113
+
114
+ # $@ is weird and sometimes includes the script's filename, othertimes doesn't.
115
+ # Copying it to a normal array results in a consistent behaviour.
116
+ tests=(" $@ " )
117
+ test_count=${# tests[@]}
118
+
119
+ # Calculate how many groups we need
120
+ if (( group_size > test_count)) ; then
121
+ group_size=$test_count
122
+ fi
123
+ group_count=$(( test_count / group_size))
124
+
125
+ for (( group_idx = 0 ; group_idx <= group_count; group_idx++ )) ; do
126
+ # The index pointing to the start of the group slice
127
+ start_idx=$(( group_idx * group_size))
128
+
129
+ if (( group_idx == group_count)) ; then
130
+ group_slice=(" ${tests[@]: start_idx} " )
131
+ else
132
+ group_slice=(" ${tests[@]: start_idx: group_size} " )
133
+ fi
134
+
135
+ if (( group_count > 1 )) ; then
136
+ echo " Building group $group_idx of $group_count "
137
+ fi
138
+
139
+ if ! build_group " ${group_slice[@]} " ; then
140
+ (( ++ failures))
141
+ fi
142
+ done
143
+
144
+ (( failures == 0 ))
145
+ }
146
+
97
147
run_tests () {
98
148
readarray -t test_list < <( get_tests " $@ " )
99
149
if [[ $print_attrpath == true ]]; then
@@ -102,7 +152,7 @@ run_tests() {
102
152
for test in " ${test_list[@]} " ; do
103
153
echo " - $test "
104
154
done
105
- elif ! " ${NIXVIM_NIX_COMMAND} " build " ${nix_args[@]} " --no-link --file . " ${test_list[@]} " ; then
155
+ elif ! build_in_groups " ${test_list[@]} " ; then
106
156
echo " Test failure" >&2
107
157
exit 1
108
158
fi
0 commit comments