flutter/dev/devicelab/bin/tasks/flutter_run_test.dart
Ian Hickson e768c92fbc
Add many more global analyses. (#47875)
* Update packages.

* Add many more global analyses.

* Catch trailing spaces and trailing newlines in all text files.
  Before we were only checking newly added files, but that means we
  missed some.

* Port the trailing spaces logic to work on Windows too.

* Correct all the files with trailing spaces and newlines.

* Refactor some of the dev/bots logic into a utils.dart library.
  Notably, the "exit" and "print" shims for testing are now usable
  from test.dart, analyze.dart, and run_command.dart.

* Add an "exitWithError" function that prints the red lines and
  then exits. This is the preferred way to exit from test.dart,
  analyze.dart, and run_command.dart.

* More consistency in the output of analyze.dart.

* Refactor analyze.dart to use the _allFiles file enumerating logic
  more widely.

* Add some double-checking logic to the _allFiles logic to catch
  cases where changes to that logic end up catching fewer files
  than expected (helps prevent future false positives).

* Add a check to prevent new binary files from being added to
  the repository. Grandfather in the binaries that we've already
  added.

* Update all the dependencies (needed because we now import crypto in
  dev/bots/analyze.dart).
2019-12-30 17:12:19 -08:00

66 lines
2.4 KiB
Dart

// 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.
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as path;
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';
final Directory flutterGalleryDir = dir(path.join(flutterDirectory.path, 'examples/hello_world'));
final File runTestSource = File(path.join(
flutterDirectory.path, 'dev', 'automated_tests', 'flutter_run_test', 'flutter_run_test.dart',
));
const Pattern passedMessageMatch = '+0: example passed';
const Pattern failedMessageMatch = '+1: example failed [E]';
const Pattern skippedMessageMatch = '+1 -1: example skipped';
const Pattern finishedMessageMatch = '+1 ~1 -1: Some tests failed.';
Future<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.android;
await task(createFlutterRunTask);
}
// verifies that the messages above are printed as a test script is executed.
Future<TaskResult> createFlutterRunTask() async {
bool passedTest = false;
bool failedTest = false;
bool skippedTest = false;
bool finishedMessage = false;
final Device device = await devices.workingDevice;
await device.unlock();
final List<String> options = <String>[
'-t', runTestSource.absolute.path, '-d', device.deviceId,
];
await inDirectory<void>(flutterGalleryDir, () async {
startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'),
flutterCommandArgs('run', options),
environment: null,
);
final Completer<void> finished = Completer<void>();
final StreamSubscription<void> subscription = device.logcat.listen((String line) {
// tests execute in order.
if (line.contains(passedMessageMatch)) {
passedTest = true;
} else if (line.contains(failedMessageMatch)) {
failedTest = true;
} else if (line.contains(skippedMessageMatch)) {
skippedTest = true;
} else if (line.contains(finishedMessageMatch)) {
finishedMessage = true;
finished.complete();
}
});
await finished.future.timeout(const Duration(minutes: 1));
subscription.cancel();
});
return passedTest && failedTest && skippedTest && finishedMessage
? TaskResult.success(<String, dynamic>{})
: TaskResult.failure('Test did not execute as expected.');
}