overall_experience_test.dart 26.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The purpose of this test is to verify the end-to-end behavior of
// "flutter run" and other such commands, as closely as possible to
// the default behavior. To that end, it avoids the use of any test
// features that are not critical (-dflutter-test being the primary
// example of a test feature that it does use). For example, no use
// is made of "--machine" in these tests.

// There are a number of risks when it comes to writing a test such
// as this one. Typically these tests are hard to debug if they are
// in a failing condition, because they just hang as they await the
// next expected line that never comes. To avoid this, here we have
// the policy of looking for multiple lines, printing what expected
// lines were not seen when a short timeout expires (but timing out
// does not cause the test to fail, to reduce flakes), and wherever
// possible recording all output and comparing the actual output to
// the expected output only once the test is completed.

// To aid in debugging, consider passing the `debug: true` argument
// to the runFlutter function.

// @dart = 2.8
26
// This file is ready to transition, just uncomment /*?*/, /*!*/, and /*late*/.
27

28
// This file intentionally assumes the tests run in order.
29 30
@Tags(<String>['no-shuffle'])

31 32 33 34 35 36 37 38
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:meta/meta.dart';
import 'package:process/process.dart';

import '../src/common.dart';
39
import 'test_utils.dart' show fileSystem;
40 41 42 43 44

const ProcessManager processManager = LocalProcessManager();
final String flutterRoot = getFlutterRoot();
final String flutterBin = fileSystem.path.join(flutterRoot, 'bin', 'flutter');

45 46 47 48 49 50 51
void debugPrint(String message) {
  // This is called to intentionally print debugging output when a test is
  // either taking too long or has failed.
  // ignore: avoid_print
  print(message);
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
typedef LineHandler = String/*?*/ Function(String line);

abstract class Transition {
  const Transition({this.handler, this.logging});

  /// Callback that is invoked when the transition matches.
  ///
  /// This should not throw, even if the test is failing. (For example, don't use "expect"
  /// in these callbacks.) Throwing here would prevent the [runFlutter] function from running
  /// to completion, which would leave zombie `flutter` processes around.
  final LineHandler/*?*/ handler;

  /// Whether to enable or disable logging when this transition is matched.
  ///
  /// The default value, null, leaves the logging state unaffected.
  final bool/*?*/ logging;

  bool matches(String line);

  @protected
  bool lineMatchesPattern(String line, Pattern pattern) {
    if (pattern is String) {
      return line == pattern;
    }
    return line.contains(pattern);
  }

  @protected
  String describe(Pattern pattern) {
    if (pattern is String) {
      return '"$pattern"';
    }
    if (pattern is RegExp) {
      return '/${pattern.pattern}/';
    }
    return '$pattern';
  }
}

class Barrier extends Transition {
  const Barrier(this.pattern, {LineHandler/*?*/ handler, bool/*?*/ logging}) : super(handler: handler, logging: logging);
  final Pattern pattern;

  @override
  bool matches(String line) => lineMatchesPattern(line, pattern);

  @override
  String toString() => describe(pattern);
}

class Multiple extends Transition {
  Multiple(List<Pattern> patterns, {
    LineHandler/*?*/ handler,
    bool/*?*/ logging,
  }) : _originalPatterns = patterns,
       patterns = patterns.toList(),
       super(handler: handler, logging: logging);

  final List<Pattern> _originalPatterns;
  final List<Pattern> patterns;

  @override
  bool matches(String line) {
    for (int index = 0; index < patterns.length; index += 1) {
      if (lineMatchesPattern(line, patterns[index])) {
        patterns.removeAt(index);
        break;
      }
    }
    return patterns.isEmpty;
  }

  @override
  String toString() {
126
    if (patterns.isEmpty) {
127 128
      return '${_originalPatterns.map(describe).join(', ')} (all matched)';
    }
129
    return '${_originalPatterns.map(describe).join(', ')} (matched ${_originalPatterns.length - patterns.length} so far)';
130 131 132
  }
}

133 134 135 136 137 138 139
class LogLine {
  const LogLine(this.channel, this.stamp, this.message);
  final String channel;
  final String stamp;
  final String message;

  bool get couldBeCrash => message.contains('Oops; flutter has exited unexpectedly:');
140 141

  @override
142
  String toString() => '$stamp $channel: $message';
143

144
  void printClearly() {
145
    debugPrint('$stamp $channel: ${clarify(message)}');
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
  }

  static String clarify(String line) {
    return line.runes.map<String>((int rune) {
      if (rune >= 0x20 && rune <= 0x7F) {
        return String.fromCharCode(rune);
      }
      switch (rune) {
        case 0x00: return '<NUL>';
        case 0x07: return '<BEL>';
        case 0x08: return '<TAB>';
        case 0x09: return '<BS>';
        case 0x0A: return '<LF>';
        case 0x0D: return '<CR>';
      }
      return '<${rune.toRadixString(16).padLeft(rune <= 0xFF ? 2 : rune <= 0xFFFF ? 4 : 5, '0')}>';
    }).join('');
  }
164 165
}

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
class ProcessTestResult {
  const ProcessTestResult(this.exitCode, this.logs);
  final int exitCode;
  final List<LogLine> logs;

  List<String> get stdout {
    return logs
      .where((LogLine log) => log.channel == 'stdout')
      .map<String>((LogLine log) => log.message)
      .toList();
  }

  List<String> get stderr {
    return logs
      .where((LogLine log) => log.channel == 'stderr')
      .map<String>((LogLine log) => log.message)
      .toList();
  }

  @override
  String toString() => 'exit code $exitCode\nlogs:\n  ${logs.join('\n  ')}\n';
187 188 189 190 191 192 193 194
}

Future<ProcessTestResult> runFlutter(
  List<String> arguments,
  String workingDirectory,
  List<Transition> transitions, {
  bool debug = false,
  bool logging = true,
195
  Duration expectedMaxDuration = const Duration(minutes: 10), // must be less than test timeout of 15 minutes! See ../../dart_test.yaml.
196
}) async {
197
  final Stopwatch clock = Stopwatch()..start();
198 199 200 201
  final Process process = await processManager.start(
    <String>[flutterBin, ...arguments],
    workingDirectory: workingDirectory,
  );
202
  final List<LogLine> logs = <LogLine>[];
203 204 205
  int nextTransition = 0;
  void describeStatus() {
    if (transitions.isNotEmpty) {
206
      debugPrint('Expected state transitions:');
207
      for (int index = 0; index < transitions.length; index += 1) {
208
        debugPrint(
209 210 211 212 213 214
          '${index.toString().padLeft(5)} '
          '${index <  nextTransition ? 'ALREADY MATCHED ' :
             index == nextTransition ? 'NOW WAITING FOR>' :
                                       '                '} ${transitions[index]}');
      }
    }
215
    if (logs.isEmpty) {
216
      debugPrint('So far nothing has been logged${ debug ? "" : "; use debug:true to print all output" }.');
217
    } else {
218
      debugPrint('Log${ debug ? "" : " (only contains logged lines; use debug:true to print all output)" }:');
219 220 221
      for (final LogLine log in logs) {
        log.printClearly();
      }
222 223 224 225 226 227 228 229
    }
  }
  bool streamingLogs = false;
  Timer/*?*/ timeout;
  void processTimeout() {
    if (!streamingLogs) {
      streamingLogs = true;
      if (!debug) {
230
        debugPrint('Test is taking a long time (${clock.elapsed.inSeconds} seconds so far).');
231 232
      }
      describeStatus();
233
      debugPrint('(streaming all logs from this point on...)');
234
    } else {
235
      debugPrint('(taking a long time...)');
236 237
    }
  }
238
  String stamp() => '[${(clock.elapsed.inMilliseconds / 1000.0).toStringAsFixed(1).padLeft(5, " ")}s]';
239
  void processStdout(String line) {
240
    final LogLine log = LogLine('stdout', stamp(), line);
241
    if (logging) {
242
      logs.add(log);
243 244
    }
    if (streamingLogs) {
245
      log.printClearly();
246 247 248
    }
    if (nextTransition < transitions.length && transitions[nextTransition].matches(line)) {
      if (streamingLogs) {
249
        debugPrint('(matched ${transitions[nextTransition]})');
250 251 252
      }
      if (transitions[nextTransition].logging != null) {
        if (!logging && transitions[nextTransition].logging/*!*/) {
253
          logs.add(log);
254 255 256 257
        }
        logging = transitions[nextTransition].logging/*!*/;
        if (streamingLogs) {
          if (logging) {
258
            debugPrint('(enabled logging)');
259
          } else {
260
            debugPrint('(disabled logging)');
261 262 263 264 265 266
          }
        }
      }
      if (transitions[nextTransition].handler != null) {
        final String/*?*/ command = transitions[nextTransition].handler/*!*/(line);
        if (command != null) {
267 268
          final LogLine inLog = LogLine('stdin', stamp(), command);
          logs.add(inLog);
269
          if (streamingLogs) {
270
            inLog.printClearly();
271 272 273 274 275 276
          }
          process.stdin.write(command);
        }
      }
      nextTransition += 1;
      timeout?.cancel();
277
      timeout = Timer(expectedMaxDuration ~/ 5, processTimeout); // This is not a failure timeout, just when to start logging verbosely to help debugging.
278 279 280
    }
  }
  void processStderr(String line) {
281 282
    final LogLine log = LogLine('stdout', stamp(), line);
    logs.add(log);
283
    if (streamingLogs) {
284
      log.printClearly();
285 286 287 288 289
    }
  }
  if (debug) {
    processTimeout();
  } else {
290
    timeout = Timer(expectedMaxDuration ~/ 2, processTimeout); // This is not a failure timeout, just when to start logging verbosely to help debugging.
291 292 293
  }
  process.stdout.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen(processStdout);
  process.stderr.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen(processStderr);
294
  unawaited(process.exitCode.timeout(expectedMaxDuration, onTimeout: () { // This is a failure timeout, must not be short.
295 296
    debugPrint('${stamp()} (process is not quitting, trying to send a "q" just in case that helps)');
    debugPrint('(a functional test should never reach this point)');
297 298 299 300 301
    final LogLine inLog = LogLine('stdin', stamp(), 'q');
    logs.add(inLog);
    if (streamingLogs) {
      inLog.printClearly();
    }
302
    process.stdin.write('q');
303
    return -1; // discarded
304
  }).catchError((Object error) { /* ignore errors here, they will be reported on the next line */ }));
305 306
  final int exitCode = await process.exitCode;
  if (streamingLogs) {
307
    debugPrint('${stamp()} (process terminated with exit code $exitCode)');
308 309 310
  }
  timeout?.cancel();
  if (nextTransition < transitions.length) {
311
    debugPrint('The subprocess terminated before all the expected transitions had been matched.');
312
    if (logs.any((LogLine line) => line.couldBeCrash)) {
313
      debugPrint('The subprocess may in fact have crashed. Check the stderr logs below.');
314
    }
315 316
    debugPrint('The transition that we were hoping to see next but that we never saw was:');
    debugPrint('${nextTransition.toString().padLeft(5)} NOW WAITING FOR> ${transitions[nextTransition]}');
317 318
    if (!streamingLogs) {
      describeStatus();
319
      debugPrint('(process terminated with exit code $exitCode)');
320 321 322 323
    }
    throw TestFailure('Missed some expected transitions.');
  }
  if (streamingLogs) {
324
    debugPrint('${stamp()} (completed execution successfully!)');
325
  }
326
  return ProcessTestResult(exitCode, logs);
327 328
}

329 330
const int progressMessageWidth = 64;

331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
void main() {
  testWithoutContext('flutter run writes and clears pidfile appropriately', () async {
    final String tempDirectory = fileSystem.systemTempDirectory.createTempSync('flutter_overall_experience_test.').resolveSymbolicLinksSync();
    final String pidFile = fileSystem.path.join(tempDirectory, 'flutter.pid');
    final String testDirectory = fileSystem.path.join(flutterRoot, 'examples', 'hello_world');
    bool/*?*/ existsDuringTest;
    try {
      expect(fileSystem.file(pidFile).existsSync(), isFalse);
      final ProcessTestResult result = await runFlutter(
        <String>['run', '-dflutter-tester', '--pid-file', pidFile],
        testDirectory,
        <Transition>[
          Barrier('q Quit (terminate the application on the device).', handler: (String line) {
            existsDuringTest = fileSystem.file(pidFile).existsSync();
            return 'q';
          }),
          const Barrier('Application finished.'),
        ],
      );
      expect(existsDuringTest, isNot(isNull));
      expect(existsDuringTest, isTrue);
      expect(result.exitCode, 0, reason: 'subprocess failed; $result');
      expect(fileSystem.file(pidFile).existsSync(), isFalse);
      // This first test ignores the stdout and stderr, so that if the
      // first run outputs "building flutter", or the "there's a new
      // flutter" banner, or other such first-run messages, they won't
      // fail the tests. This does mean that running this test first is
      // actually important in the case where you're running the tests
      // manually. (On CI, all those messages are expected to be seen
      // long before we get here, e.g. because we run "flutter doctor".)
    } finally {
      tryToDelete(fileSystem.directory(tempDirectory));
    }
364 365 366
    // This test is expected to be skipped when Platform.isWindows:
    // [intended] Windows doesn't support sending signals so we don't care if it can store the PID.
  }, skip: true); // Flake: https://github.com/flutter/flutter/issues/92042
367 368 369 370 371 372 373 374 375 376 377 378

  testWithoutContext('flutter run handle SIGUSR1/2', () async {
    final String tempDirectory = fileSystem.systemTempDirectory.createTempSync('flutter_overall_experience_test.').resolveSymbolicLinksSync();
    final String pidFile = fileSystem.path.join(tempDirectory, 'flutter.pid');
    final String testDirectory = fileSystem.path.join(flutterRoot, 'dev', 'integration_tests', 'ui');
    final String testScript = fileSystem.path.join('lib', 'commands.dart');
    /*late*/ int pid;
    try {
      final ProcessTestResult result = await runFlutter(
        <String>['run', '-dflutter-tester', '--report-ready', '--pid-file', pidFile, '--no-devtools', testScript],
        testDirectory,
        <Transition>[
379
          Multiple(<Pattern>['Flutter run key commands.', 'called paint'], handler: (String line) {
380 381 382 383
            pid = int.parse(fileSystem.file(pidFile).readAsStringSync());
            processManager.killPid(pid, ProcessSignal.sigusr1);
            return null;
          }),
384 385
          Barrier('Performing hot reload...'.padRight(progressMessageWidth), logging: true),
          Multiple(<Pattern>[RegExp(r'^Reloaded 0 libraries in [0-9]+ms\.$'), 'called reassemble', 'called paint'], handler: (String line) {
386 387 388
            processManager.killPid(pid, ProcessSignal.sigusr2);
            return null;
          }),
389 390
          Barrier('Performing hot restart...'.padRight(progressMessageWidth)),
          Multiple(<Pattern>[RegExp(r'^Restarted application in [0-9]+ms.$'), 'called main', 'called paint'], handler: (String line) {
391 392 393 394 395 396 397 398 399
            return 'q';
          }),
          const Barrier('Application finished.'),
        ],
        logging: false, // we ignore leading log lines to avoid making this test sensitive to e.g. the help message text
      );
      // We check the output from the app (all starts with "called ...") and the output from the tool
      // (everything else) separately, because their relative timing isn't guaranteed. Their rough timing
      // is verified by the expected transitions above.
400
      expect(result.stdout.where((String line) => line.startsWith('called ')), <Object>[
401 402
        // logs start after we receive the response to sending SIGUSR1
        // SIGUSR1:
403
        'called reassemble',
404 405
        'called paint',
        // SIGUSR2:
406
        'called main',
407 408 409 410
        'called paint',
      ]);
      expect(result.stdout.where((String line) => !line.startsWith('called ')), <Object>[
        // logs start after we receive the response to sending SIGUSR1
411
        'Performing hot reload...'.padRight(progressMessageWidth),
412
        startsWith('Reloaded 0 libraries in '),
413
        'Performing hot restart...'.padRight(progressMessageWidth),
414 415 416 417 418 419 420 421 422
        startsWith('Restarted application in '),
        '', // this newline is the one for after we hit "q"
        'Application finished.',
        'ready',
      ]);
      expect(result.exitCode, 0);
    } finally {
      tryToDelete(fileSystem.directory(tempDirectory));
    }
423
  }, skip: Platform.isWindows); // [intended] Windows doesn't support sending signals.
424 425 426 427 428 429 430 431 432 433

  testWithoutContext('flutter run can hot reload and hot restart, handle "p" key', () async {
    final String tempDirectory = fileSystem.systemTempDirectory.createTempSync('flutter_overall_experience_test.').resolveSymbolicLinksSync();
    final String testDirectory = fileSystem.path.join(flutterRoot, 'dev', 'integration_tests', 'ui');
    final String testScript = fileSystem.path.join('lib', 'commands.dart');
    try {
      final ProcessTestResult result = await runFlutter(
        <String>['run', '-dflutter-tester', '--report-ready', '--no-devtools', testScript],
        testDirectory,
        <Transition>[
434
          Multiple(<Pattern>['Flutter run key commands.', 'called main', 'called paint'], handler: (String line) {
435 436
            return 'r';
          }),
437 438
          Barrier('Performing hot reload...'.padRight(progressMessageWidth), logging: true),
          Multiple(<Pattern>['ready', 'called reassemble', 'called paint'], handler: (String line) {
439 440
            return 'R';
          }),
441
          Barrier('Performing hot restart...'.padRight(progressMessageWidth)),
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
          Multiple(<Pattern>['ready', 'called main', 'called paint'], handler: (String line) {
            return 'p';
          }),
          Multiple(<Pattern>['ready', 'called paint', 'called debugPaintSize'], handler: (String line) {
            return 'p';
          }),
          Multiple(<Pattern>['ready', 'called paint'], handler: (String line) {
            return 'q';
          }),
          const Barrier('Application finished.'),
        ],
        logging: false, // we ignore leading log lines to avoid making this test sensitive to e.g. the help message text
      );
      // We check the output from the app (all starts with "called ...") and the output from the tool
      // (everything else) separately, because their relative timing isn't guaranteed. Their rough timing
      // is verified by the expected transitions above.
458 459
      expect(result.stdout.where((String line) => line.startsWith('called ')), <Object>[
        // logs start after we initiate the hot reload
460
        // hot reload:
461
        'called reassemble',
462 463 464 465 466 467 468 469 470 471 472 473
        'called paint',
        // hot restart:
        'called main',
        'called paint',
        // debugPaintSizeEnabled = true:
        'called paint',
        'called debugPaintSize',
        // debugPaintSizeEnabled = false:
        'called paint',
      ]);
      expect(result.stdout.where((String line) => !line.startsWith('called ')), <Object>[
        // logs start after we receive the response to hitting "r"
474
        'Performing hot reload...'.padRight(progressMessageWidth),
475 476 477
        startsWith('Reloaded 0 libraries in '),
        'ready',
        '', // this newline is the one for after we hit "R"
478
        'Performing hot restart...'.padRight(progressMessageWidth),
479 480 481 482 483 484 485 486 487 488 489 490 491 492
        startsWith('Restarted application in '),
        'ready',
        '', // newline for after we hit "p" the first time
        'ready',
        '', // newline for after we hit "p" the second time
        'ready',
        '', // this newline is the one for after we hit "q"
        'Application finished.',
        'ready',
      ]);
      expect(result.exitCode, 0);
    } finally {
      tryToDelete(fileSystem.directory(tempDirectory));
    }
493
  });
494 495 496

  testWithoutContext('flutter error messages include a DevTools link', () async {
    final String testDirectory = fileSystem.path.join(flutterRoot, 'dev', 'integration_tests', 'ui');
497
    final String tempDirectory = fileSystem.systemTempDirectory.createTempSync('flutter_overall_experience_test.').resolveSymbolicLinksSync();
498 499 500 501 502 503 504 505 506 507
    final String testScript = fileSystem.path.join('lib', 'overflow.dart');
    try {
      final ProcessTestResult result = await runFlutter(
        <String>['run', '-dflutter-tester', testScript],
        testDirectory,
        <Transition>[
          Barrier(RegExp(r'^An Observatory debugger and profiler on Flutter test device is available at: ')),
          Barrier(RegExp(r'^The Flutter DevTools debugger and profiler on Flutter test device is available at: '), handler: (String line) {
            return 'r';
          }),
508
          Barrier('Performing hot reload...'.padRight(progressMessageWidth), logging: true),
509 510 511 512 513 514 515
          Barrier(RegExp(r'^Reloaded 0 libraries in [0-9]+ms.'), handler: (String line) {
            return 'q';
          }),
        ],
        logging: false,
      );
      expect(result.exitCode, 0);
516
      expect(result.stdout, <Object>[
517
        startsWith('Performing hot reload...'),
518
        '',
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
        '══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════',
        'The following assertion was thrown during layout:',
        'A RenderFlex overflowed by 69200 pixels on the right.',
        '',
        'The relevant error-causing widget was:',
        matches(RegExp(r'^  Row .+flutter/dev/integration_tests/ui/lib/overflow\.dart:31:12$')),
        '',
        'To inspect this widget in Flutter DevTools, visit:',
        startsWith('http'),
        '',
        'The overflowing RenderFlex has an orientation of Axis.horizontal.',
        'The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and',
        'black striped pattern. This is usually caused by the contents being too big for the RenderFlex.',
        'Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the',
        'RenderFlex to fit within the available space instead of being sized to their natural size.',
        'This is considered an error condition because it indicates that there is content that cannot be',
        'seen. If the content is legitimately bigger than the available space, consider clipping it with a',
        'ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,',
        'like a ListView.',
        matches(RegExp(r'^The specific RenderFlex in question is: RenderFlex#..... OVERFLOWING:$')),
        startsWith('  creator: Row ← Test ← '),
        contains(' ← '),
541
        endsWith(' ← ⋯'),
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
        '  parentData: <none> (can use size)',
        '  constraints: BoxConstraints(w=800.0, h=600.0)',
        '  size: Size(800.0, 600.0)',
        '  direction: horizontal',
        '  mainAxisAlignment: start',
        '  mainAxisSize: max',
        '  crossAxisAlignment: center',
        '  textDirection: ltr',
        '  verticalDirection: down',
        '◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤',
        '════════════════════════════════════════════════════════════════════════════════════════════════════',
        startsWith('Reloaded 0 libraries in '),
        '',
        'Application finished.',
      ]);
    } finally {
      tryToDelete(fileSystem.directory(tempDirectory));
    }
560
  });
561 562 563 564 565 566

  testWithoutContext('flutter run help output', () async {
    // This test enables all logging so that it checks the exact text of starting up an application.
    // The idea is to verify that we're not outputting spurious messages.
    // WHEN EDITING THIS TEST PLEASE CAREFULLY CONSIDER WHETHER THE NEW OUTPUT IS AN IMPROVEMENT.
    final String testDirectory = fileSystem.path.join(flutterRoot, 'examples', 'hello_world');
567
    final RegExp finalLine = RegExp(r'^The Flutter DevTools');
568
    final ProcessTestResult result = await runFlutter(
569
      <String>['run', '-dflutter-tester'],
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
      testDirectory,
      <Transition>[
        Barrier(finalLine, handler: (String line) {
          return 'h';
        }),
        Barrier(finalLine, handler: (String line) {
          return 'q';
        }),
        const Barrier('Application finished.'),
      ],
    );
    expect(result.exitCode, 0);
    expect(result.stderr, isEmpty);
    expect(result.stdout, <Object>[
      startsWith('Launching '),
      startsWith('Syncing files to device Flutter test device...'),
      '',
      'Flutter run key commands.',
      startsWith('r Hot reload.'),
      'R Hot restart.',
590
      'h List all available interactive commands.',
591 592 593 594 595 596 597
      'd Detach (terminate "flutter run" but leave application running).',
      'c Clear the screen',
      'q Quit (terminate the application on the device).',
      '',
      contains('Running with sound null safety'),
      '',
      startsWith('An Observatory debugger and profiler on Flutter test device is available at: http://'),
598
      startsWith('The Flutter DevTools debugger and profiler on Flutter test device is available at: http://'),
599 600 601 602
      '',
      'Flutter run key commands.',
      startsWith('r Hot reload.'),
      'R Hot restart.',
603
      'v Open Flutter DevTools.',
604 605 606 607 608 609 610
      'w Dump widget hierarchy to the console.                                               (debugDumpApp)',
      't Dump rendering tree to the console.                                          (debugDumpRenderTree)',
      'L Dump layer tree to the console.                                               (debugDumpLayerTree)',
      'S Dump accessibility tree in traversal order.                                   (debugDumpSemantics)',
      'U Dump accessibility tree in inverse hit test order.                            (debugDumpSemantics)',
      'i Toggle widget inspector.                                  (WidgetsApp.showWidgetInspectorOverride)',
      'p Toggle the display of construction lines.                                  (debugPaintSizeEnabled)',
611
      'I Toggle oversized image inversion.                                     (debugInvertOversizedImages)',
612
      'o Simulate different operating systems.                                      (defaultTargetPlatform)',
613
      'b Toggle platform brightness (dark and light mode).                        (debugBrightnessOverride)',
614 615
      'P Toggle performance overlay.                                    (WidgetsApp.showPerformanceOverlay)',
      'a Toggle timeline events for all widget build methods.                    (debugProfileWidgetBuilds)',
616 617 618 619 620 621
      'M Write SkSL shaders to a unique file in the project directory.',
      'g Run source code generators.',
      'h Repeat this help message.',
      'd Detach (terminate "flutter run" but leave application running).',
      'c Clear the screen',
      'q Quit (terminate the application on the device).',
622 623 624 625
      '',
      contains('Running with sound null safety'),
      '',
      startsWith('An Observatory debugger and profiler on Flutter test device is available at: http://'),
626
      startsWith('The Flutter DevTools debugger and profiler on Flutter test device is available at: http://'),
627 628 629
      '',
      'Application finished.',
    ]);
630
  });
631
}