@@ -133,30 +133,57 @@ void defineCreateTests() {
133
133
// if they've executed correctly. These templates won't exit on their
134
134
// own, so we'll need to terminate the process once we've verified it
135
135
// runs correctly.
136
+ var hasError = false ;
136
137
stdoutSub = process.stdout.transform (utf8.decoder).listen ((e) {
137
138
print ('stdout: $e ' );
138
- if ((isServerTemplate && e.contains ('Server listening on port' )) ||
139
+ if (e.contains ('[SEVERE]' ) ||
140
+ (isServerTemplate && e.contains ('Server listening on port' )) ||
139
141
(isWebTemplate && e.contains ('Succeeded after' ))) {
142
+ if (e.contains ('[SEVERE]' )) {
143
+ hasError = true ;
144
+ }
140
145
stderrSub.cancel ();
141
146
stdoutSub.cancel ();
142
147
process.kill ();
143
148
completer.complete ();
144
149
}
145
150
});
146
- stderrSub = process.stderr
147
- .transform (utf8.decoder)
148
- .listen ((e) => print ('stderr: $e ' ));
151
+ stderrSub = process.stderr.transform (utf8.decoder).listen ((e) {
152
+ print ('stderr: $e ' );
153
+ hasError = true ;
154
+ stderrSub.cancel ();
155
+ stdoutSub.cancel ();
156
+ process.kill ();
157
+ completer.complete ();
158
+ });
149
159
await completer.future;
160
+ expect (hasError, isFalse, reason: 'Command $command failed.' );
150
161
151
162
// Since we had to terminate the process manually, we aren't certain
152
163
// as to what the exit code will be on all platforms (should be -15
153
164
// for POSIX systems), so we'll just wait for the process to exit
154
165
// here.
155
166
await process.exitCode;
156
167
} else {
168
+ final output = < String > [];
169
+ final errors = < String > [];
170
+ process.stdout.transform (utf8.decoder).listen (output.add);
171
+ process.stderr.transform (utf8.decoder).listen (errors.add);
172
+
157
173
// If the sample should exit on its own, it should always result in
158
174
// an exit code of 0.
159
- expect (await process.exitCode, 0 );
175
+ final duration = const Duration (seconds: 30 );
176
+ final exitCode =
177
+ await process.exitCode.timeout (duration, onTimeout: () {
178
+ print ('Command $command timed out' );
179
+ return - 1 ;
180
+ });
181
+ if (exitCode != 0 ) {
182
+ print ('Command $command exited with code $exitCode ' );
183
+ print ('Output: \n ${output .join ('\n ' )}' );
184
+ print ('Errors: \n ${errors .join ('\n ' )}' );
185
+ }
186
+ expect (exitCode, 0 );
160
187
}
161
188
print ('[${i + 1 } / ${runCommands .length }] Done "$command ".' );
162
189
}
0 commit comments