@@ -34,6 +34,13 @@ Skip file:
34
34
EOF
35
35
}
36
36
37
+ function user_error() {
38
+ echo " error: $1 " >&2
39
+ echo " " >&2
40
+ show_help >&2
41
+ exit 1
42
+ }
43
+
37
44
while [[ " $# " -gt 0 ]]; do
38
45
case $1 in
39
46
-h | --help)
@@ -55,9 +62,7 @@ while [[ "$#" -gt 0 ]]; do
55
62
case $2 in
56
63
windows | linux | macos) ;;
57
64
* )
58
- printf " error: Unrecognized os: '$2 '\n\n" >&2
59
- show_help >&2
60
- exit 1
65
+ user_error " Unrecognized os: '$2 '"
61
66
;;
62
67
esac
63
68
os=" $2 "
@@ -67,56 +72,44 @@ while [[ "$#" -gt 0 ]]; do
67
72
case $2 in
68
73
debug | release) ;;
69
74
* )
70
- printf " error: Unrecognized config: '$2 '\n\n" >&2
71
- show_help >&2
72
- exit 1
75
+ user_error " Unrecognized config: '$2 '"
73
76
;;
74
77
esac
75
78
config=" $2 "
76
79
shift
77
80
;;
78
81
* )
79
- echo " unrecognized argument: $1 " >&2
80
- show_help >&2
81
- exit 1
82
+ user_error " Unrecognized argument: '$1 '"
82
83
;;
83
84
esac
84
85
shift
85
86
done
86
87
87
88
if [[ " $os " == " " ]]; then
88
- echo " error: No OS specified.\n\n"
89
- show_help >&2
90
- exit 1
89
+ user_error " No OS specified."
91
90
fi
92
91
93
92
if [[ " $config " == " " ]]; then
94
- printf " error: No build configuration specified.\n\n" >&2
95
- show_help >&2
96
- exit 1
93
+ user_error " No build configuration specified."
97
94
fi
98
95
99
96
if [[ " $bin_dir " == " " ]]; then
100
- printf " error: No binary directory specified.\n\n" >&2
101
- show_help >&2
102
- exit 1
97
+ user_error " No binary directory specified."
103
98
fi
104
99
105
100
if [[ " $skip_file " == " " ]]; then
106
- printf " error: No skip file specified.\n\n" >&2
107
- show_help >&2
108
- exit 1
101
+ user_error " No skip file specified."
109
102
fi
110
103
111
104
if [[ ! -f " $skip_file " ]]; then
112
- printf " error: Skip file '$skip_file ' does not exist.\n\n " >&2
105
+ user_error " Skip file '$skip_file ' does not exist."
113
106
fi
114
107
115
108
if [[ ! -d " $bin_dir " ]]; then
116
- printf " error: Binary directory '$bin_dir ' does not exist.\n\n " >&2
109
+ user_error " Binary directory '$bin_dir ' does not exist."
117
110
fi
118
111
119
- summary=" "
112
+ summary=()
120
113
failure_count=0
121
114
skip_count=0
122
115
sample_count=0
@@ -126,46 +119,45 @@ function skip {
126
119
local line_index
127
120
p=" $1 "
128
121
line_index=1
129
- while read pattern; do
122
+ while read -r pattern; do
130
123
pat=$pattern
131
124
if [[ ! $pat =~ .* # ]]; then
132
- echo " error: Skip pattern on line $line_index is missing a comment!"
133
- exit 1
125
+ user_error " Skip pattern on line $line_index is missing a comment!"
134
126
fi
135
127
pat= " ${pattern%% *#* } "
136
128
if [[ $p =~ ^$pat $ ]]; then
137
129
return 0
138
130
fi
139
131
line_index= $(( line_index + 1 ))
140
- done < $skip_file
132
+ done < " $skip_file "
141
133
142
134
return 1
143
135
}
144
136
145
137
function run_sample {
146
- local command
147
138
local sample
148
- command=$@
139
+ local args
140
+ sample=" $1 "
149
141
shift
150
- sample= " ${command %% * } "
142
+ args=( " $@ " )
151
143
sample_count=$(( sample_count + 1 ))
152
- summary+= " $ sample : "
144
+ summary=( " ${summary[@]} " " $ sample : " )
153
145
if skip " $os :$config :$sample " ; then
154
146
echo " Skipping $sample ..."
155
- summary+= " \n skipped\n "
147
+ summary=( " ${summary[@]} " " skipped" )
156
148
skip_count=$(( skip_count + 1 ))
157
149
return
158
150
fi
159
- echo " Running '$command '..."
151
+ echo " Running '$sample ${args[*]} '..."
160
152
result=0
161
- pushd $bin_dir 1> /dev/null 2>&1
153
+ pushd " $bin_dir " 1> /dev/null 2>&1
162
154
if [[ ! " $dry_run " = true ]]; then
163
- ./$command || result=$?
155
+ ./" $sample " " ${args[@]} " || result=$?
164
156
fi
165
157
if [[ $result -eq 0 ]]; then
166
- summary+= " \n success\n "
158
+ summary=( " ${summary[@]} " " success" )
167
159
else
168
- summary+= " \n failure (exit code: $result )\n "
160
+ summary=( " ${summary[@]} " " failure (exit code: $result )" )
169
161
failure_count=$(( failure_count + 1 ))
170
162
fi
171
163
popd 1> /dev/null 2>&1
@@ -187,13 +179,18 @@ sample_commands=(
187
179
)
188
180
189
181
for sample_command in " ${sample_commands[@]} " ; do
190
- run_sample $sample_command
182
+ run_sample ${ sample_command}
191
183
echo " "
192
184
done
193
185
194
186
echo " "
195
187
echo " Summary: "
196
- printf " \n$summary \n\n"
188
+ echo
189
+ for line in " ${summary[@]} "
190
+ do
191
+ printf ' %s\n' " $line "
192
+ done
193
+ echo " "
197
194
echo " $failure_count failed, and $skip_count skipped, out of $sample_count tests"
198
195
if [[ $failure_count -ne 0 ]]; then
199
196
exit 1
0 commit comments