Skip to content

Commit 7f41482

Browse files
committed
Explicitly handle non-zero exit statuses
1 parent 3d23acf commit 7f41482

File tree

2 files changed

+120
-16
lines changed

2 files changed

+120
-16
lines changed

tools/ci/appveyor

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ tail_output() {
8585
# $1 - log directory
8686
# $2 - log file path
8787
create_log_file() {
88+
echo "Creating an output log file: $2." >&2
8889
mkdir -p "$1"
8990
touch "$2"
9091
}
@@ -100,6 +101,12 @@ print_success() {
100101
run_tests() {
101102
echo 'Running tests...' >&2
102103
make test >> "$1" 2>&1
104+
if [[ "$?" -ne 0 ]]; then
105+
echo 'Tests failed.' >&2
106+
return 1
107+
fi
108+
echo 'Tests passed.' >&2
109+
return 0
103110
}
104111

105112
# Runs test coverage.
@@ -108,6 +115,12 @@ run_tests() {
108115
run_test_coverage() {
109116
echo 'Running test coverage...' >&2
110117
make test-cov >> "$1" 2>&1
118+
if [[ "$?" -ne 0 ]]; then
119+
echo 'Tests failed.' >&2
120+
return 1
121+
fi
122+
echo 'Tests passed.' >&2
123+
return 0
111124
}
112125

113126
# Sends test coverage to coverage service.
@@ -117,6 +130,12 @@ run_test_coverage() {
117130
send_coverage() {
118131
echo 'Sending coverage report to coverage service...' >&2
119132
make COVERAGE_NAME="$1" coverage >> "$2" 2>&1
133+
if [[ "$?" -ne 0 ]]; then
134+
echo 'Sending coverage report to coverage service failed.' >&2
135+
return 1
136+
fi
137+
echo 'Coverage report sent to coverage service.' >&2
138+
return 0
120139
}
121140

122141
# Runs benchmarks.
@@ -125,6 +144,12 @@ send_coverage() {
125144
run_benchmarks() {
126145
echo 'Running benchmarks...' >&2
127146
make benchmark >> "$1" 2>&1
147+
if [[ "$?" -ne 0 ]]; then
148+
echo 'Benchmarks failed.' >&2
149+
return 1
150+
fi
151+
echo 'Successfully ran benchmarks.' >&2
152+
return 0
128153
}
129154

130155
# Runs examples.
@@ -133,6 +158,12 @@ run_benchmarks() {
133158
run_examples() {
134159
echo 'Running examples...' >&2
135160
make examples >> "$1" 2>&1
161+
if [[ "$?" -ne 0 ]]; then
162+
echo 'Examples failed.' >&2
163+
return 1
164+
fi
165+
echo 'Successfully ran examples.' >&2
166+
return 0
136167
}
137168

138169
# Checks dependencies.
@@ -141,23 +172,49 @@ run_examples() {
141172
check_deps() {
142173
echo 'Checking dependencies...' >&2
143174
make check-deps >> "$1" 2>&1
175+
if [[ "$?" -ne 0 ]]; then
176+
echo 'Dependencies are out-of-date.' >&2
177+
return 1
178+
fi
179+
echo 'Dependencies are up-to-date.' >&2
180+
return 0
144181
}
145182

146183
# Main execution sequence.
147184
main() {
148185
create_log_file "$log_dir" "$log_file"
149186
start_heartbeat "$heartbeat_interval"
187+
188+
echo "Task: $task." >&2
150189
if [[ "$task" = "test" ]]; then
151190
run_tests "$log_file"
191+
if [[ "$?" -ne 0 ]]; then
192+
on_error 1
193+
fi
152194
elif [[ "$task" = "benchmark" ]]; then
153195
run_benchmarks "$log_file"
196+
if [[ "$?" -ne 0 ]]; then
197+
on_error 1
198+
fi
154199
elif [[ "$task" = "examples" ]]; then
155200
run_examples "$log_file"
201+
if [[ "$?" -ne 0 ]]; then
202+
on_error 1
203+
fi
156204
elif [[ "$task" = "test-coverage" ]]; then
157205
run_test_coverage "$log_file"
206+
if [[ "$?" -ne 0 ]]; then
207+
on_error 1
208+
fi
158209
send_coverage "unit_test" "$log_file"
210+
if [[ "$?" -ne 0 ]]; then
211+
on_error 1
212+
fi
159213
elif [[ "task" = "check-deps" ]]; then
160214
check_deps "$log_file"
215+
if [[ "$?" -ne 0 ]]; then
216+
on_error 1
217+
fi
161218
else
162219
echo "ERROR: unknown task: $task." >&2
163220
on_error 1
@@ -167,21 +224,11 @@ main() {
167224
exit 0
168225
}
169226

170-
# Run in the top-level project directory:
171-
cd `dirname "$0"`/../..
172-
173-
# Exit immediately if one of the executed commands exits with a non-zero status:
174-
set -e
175-
176227
# Set an error handler to print captured output and perform any clean-up tasks:
177228
trap 'on_error' ERR
178229

230+
# Run in the top-level project directory:
231+
cd `dirname "$0"`/../..
232+
179233
# Run main:
180234
main
181-
182-
183-
184-
185-
186-
187-

tools/ci/travis

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ tail_output() {
8383
#
8484
# $1 - log file path
8585
create_log_file() {
86+
echo "Creating an output log file: $1." >&2
8687
sudo touch "$1"
8788
sudo chown travis "$1"
8889
}
@@ -98,6 +99,12 @@ print_success() {
9899
run_tests() {
99100
echo 'Running tests...' >&2
100101
make test >> "$1" 2>&1
102+
if [[ "$?" -ne 0 ]]; then
103+
echo 'Tests failed.' >&2
104+
return 1
105+
fi
106+
echo 'Tests passed.' >&2
107+
return 0
101108
}
102109

103110
# Runs test coverage.
@@ -106,6 +113,12 @@ run_tests() {
106113
run_test_coverage() {
107114
echo 'Running test coverage...' >&2
108115
make test-cov >> "$1" 2>&1
116+
if [[ "$?" -ne 0 ]]; then
117+
echo 'Tests failed.' >&2
118+
return 1
119+
fi
120+
echo 'Tests passed.' >&2
121+
return 0
109122
}
110123

111124
# Sends test coverage to coverage service.
@@ -115,6 +128,12 @@ run_test_coverage() {
115128
send_coverage() {
116129
echo 'Sending coverage report to coverage service...' >&2
117130
make COVERAGE_NAME="$1" coverage >> "$2" 2>&1
131+
if [[ "$?" -ne 0 ]]; then
132+
echo 'Sending coverage report to coverage service failed.' >&2
133+
return 1
134+
fi
135+
echo 'Coverage report sent to coverage service.' >&2
136+
return 0
118137
}
119138

120139
# Runs benchmarks.
@@ -123,6 +142,12 @@ send_coverage() {
123142
run_benchmarks() {
124143
echo 'Running benchmarks...' >&2
125144
make benchmark >> "$1" 2>&1
145+
if [[ "$?" -ne 0 ]]; then
146+
echo 'Benchmarks failed.' >&2
147+
return 1
148+
fi
149+
echo 'Successfully ran benchmarks.' >&2
150+
return 0
126151
}
127152

128153
# Runs examples.
@@ -131,6 +156,12 @@ run_benchmarks() {
131156
run_examples() {
132157
echo 'Running examples...' >&2
133158
make examples >> "$1" 2>&1
159+
if [[ "$?" -ne 0 ]]; then
160+
echo 'Examples failed.' >&2
161+
return 1
162+
fi
163+
echo 'Successfully ran examples.' >&2
164+
return 0
134165
}
135166

136167
# Checks dependencies.
@@ -139,25 +170,54 @@ run_examples() {
139170
check_deps() {
140171
echo 'Checking dependencies...' >&2
141172
make check-deps >> "$1" 2>&1
173+
if [[ "$?" -ne 0 ]]; then
174+
echo 'Dependencies are out-of-date.' >&2
175+
return 1
176+
fi
177+
echo 'Dependencies are up-to-date.' >&2
178+
return 0
142179
}
143180

144181
# Main execution sequence.
145182
main() {
146183
create_log_file "$log_file"
147184
start_heartbeat "$heartbeat_interval"
185+
186+
echo "Task: $task." >&2
148187
if [[ "$task" = "test" ]]; then
149188
# FIXME: remove checking deps once separate build environment
150189
check_deps "$log_file"
190+
if [[ "$?" -ne 0 ]]; then
191+
on_error 1
192+
fi
151193
run_tests "$log_file"
194+
if [[ "$?" -ne 0 ]]; then
195+
on_error 1
196+
fi
152197
elif [[ "$task" = "benchmark" ]]; then
153198
run_benchmarks "$log_file"
199+
if [[ "$?" -ne 0 ]]; then
200+
on_error 1
201+
fi
154202
elif [[ "$task" = "examples" ]]; then
155203
run_examples "$log_file"
204+
if [[ "$?" -ne 0 ]]; then
205+
on_error 1
206+
fi
156207
elif [[ "$task" = "test-coverage" ]]; then
157208
run_test_coverage "$log_file"
209+
if [[ "$?" -ne 0 ]]; then
210+
on_error 1
211+
fi
158212
send_coverage "unit_test" "$log_file"
213+
if [[ "$?" -ne 0 ]]; then
214+
on_error 1
215+
fi
159216
elif [[ "task" = "check-deps" ]]; then
160217
check_deps "$log_file"
218+
if [[ "$?" -ne 0 ]]; then
219+
on_error 1
220+
fi
161221
else
162222
echo "ERROR: unknown task: $task." >&2
163223
on_error 1
@@ -167,9 +227,6 @@ main() {
167227
exit 0
168228
}
169229

170-
# Exit immediately if one of the executed commands exits with a non-zero status:
171-
set -e
172-
173230
# Set an error handler to print captured output and perform any clean-up tasks:
174231
trap 'on_error' ERR
175232

0 commit comments

Comments
 (0)