@@ -239,62 +239,83 @@ class BuildRunnerProcess {
239239 /// defaults to [BuildLog.failurePattern] so that `expect` will stop if the
240240 /// process reports a build failure.
241241 ///
242- /// if [expectFailure] is set, then both [pattern] and [failOn] must be
243- /// encountered for the test to pass.
242+ /// If the process exits instead, the test fails immediately.
243+ ///
244+ /// Otherwise, waits until [pattern] appears, then completes.
245+ ///
246+ /// Throws if the process appears to be stuck or done: if it outputs nothing
247+ /// for 30s.
248+ Future <void > expect (Pattern pattern, {Pattern ? failOn}) async =>
249+ expectAndGetLine (pattern, failOn: failOn);
250+
251+ /// Expects [pattern] to appear in the process's stdout or stderr.
252+ ///
253+ /// If [failOn] is encountered instead, the test fails immediately. It
254+ /// defaults to [BuildLog.failurePattern] so that `expect` will stop if the
255+ /// process reports a build failure.
244256 ///
245257 /// If the process exits instead, the test fails immediately.
246258 ///
247259 /// Otherwise, waits until [pattern] appears, returns the matching line.
248260 ///
249261 /// Throws if the process appears to be stuck or done: if it outputs nothing
250262 /// for 30s.
251- Future <String > expect (
252- Pattern pattern, {
253- Pattern ? failOn,
254- bool expectFailure = false ,
255- }) async {
263+ Future <String > expectAndGetLine (Pattern pattern, {Pattern ? failOn}) async {
256264 printOnFailure (
257265 '--- $_testLine expects `$pattern `'
258- '${failOn == null ? '' : ', failOn: `$failOn `' }'
259- '${expectFailure ? ', expectFailure: true' : '' }' ,
266+ '${failOn == null ? '' : ', failOn: `$failOn `' }' ,
260267 );
261268 failOn ?? = BuildLog .failurePattern;
262-
263- final expectsMessage =
264- expectFailure
265- ? '`$pattern ` with failure matching (`$failOn `)'
266- : '`$pattern `' ;
267-
268- var failureSeen = false ;
269- var patternSeen = false ;
270269 while (true ) {
271270 String ? line;
272271 try {
273272 line = await _outputs.next.timeout (const Duration (seconds: 30 ));
274273 } on TimeoutException catch (_) {
275- throw fail ('While expecting $ expectsMessage , timed out after 30s.' );
274+ throw fail ('While expecting `$ pattern ` , timed out after 30s.' );
276275 } catch (_) {
277- throw fail ('While expecting $ expectsMessage , process exited.' );
276+ throw fail ('While expecting `$ pattern ` , process exited.' );
278277 }
279278 printOnFailure (line);
279+ if (line.contains (pattern)) return line;
280280 if (line.contains (failOn)) {
281- failureSeen = true ;
282- }
283- if (line.contains (pattern)) {
284- patternSeen = true ;
281+ fail ('While expecting `$pattern `, got `$failOn `.' );
285282 }
283+ }
284+ }
286285
287- if (expectFailure) {
288- if (patternSeen && failureSeen) {
289- return line;
290- }
291- } else {
292- if (failureSeen) {
293- fail ('While expecting $expectsMessage , got `$failOn `.' );
294- }
295- if (patternSeen) {
296- return line;
297- }
286+ /// Expects [pattern] to appear in the process's stdout or stderr.
287+ ///
288+ /// If [failOn] is encountered instead, the test fails immediately. It
289+ /// defaults to [BuildLog.failurePattern] so that `expect` will stop if the
290+ /// process reports a build failure.
291+ ///
292+ /// If the process exits instead, the test fails immediately.
293+ ///
294+ /// Otherwise, waits until [pattern] appears, returns all text seen.
295+ ///
296+ /// Throws if the process appears to be stuck or done: if it outputs nothing
297+ /// for 30s.
298+ Future <String > expectAndGetBlock (Pattern pattern, {Pattern ? failOn}) async {
299+ printOnFailure (
300+ '--- $_testLine expects `$pattern `'
301+ '${failOn == null ? '' : ', failOn: `$failOn `' }' ,
302+ );
303+ failOn ?? = BuildLog .failurePattern;
304+ final lines = StringBuffer ();
305+ while (true ) {
306+ String ? line;
307+ try {
308+ line = await _outputs.next.timeout (const Duration (seconds: 30 ));
309+ lines.writeln (line);
310+ } on TimeoutException catch (_) {
311+ throw fail ('While expecting `$pattern `, timed out after 30s.' );
312+ } catch (_) {
313+ throw fail ('While expecting `$pattern `, process exited.' );
314+ }
315+ printOnFailure (line);
316+ if (line.contains (pattern)) return lines.toString ();
317+ if (line.contains (failOn)) {
318+ fail ('While expecting `$pattern `, got `$failOn `.' );
298319 }
299320 }
300321 }
@@ -329,7 +350,7 @@ class BuildRunnerProcess {
329350 // Expects the server to log that it is serving, records the port.
330351 Future <void > expectServing () async {
331352 final regexp = RegExp ('Serving `web` on http://localhost:([0-9]+)' );
332- final line = await expect (regexp);
353+ final line = await expectAndGetLine (regexp);
333354 final port = int .parse (regexp.firstMatch (line)! .group (1 )! );
334355 _port = port;
335356 }
0 commit comments