2017-06-12 23:52:35 +00:00
|
|
|
// Copyright 2017 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-02-14 18:21:33 +00:00
|
|
|
import 'dart:async';
|
2017-04-13 17:22:41 +00:00
|
|
|
import 'dart:convert';
|
2017-02-23 21:37:26 +00:00
|
|
|
import 'dart:io';
|
2017-02-14 18:21:33 +00:00
|
|
|
|
2017-04-13 17:22:41 +00:00
|
|
|
import 'package:path/path.dart' as path;
|
2017-02-14 18:21:33 +00:00
|
|
|
|
2017-06-16 00:54:45 +00:00
|
|
|
typedef Future<Null> ShardRunner();
|
|
|
|
|
2017-04-13 17:22:41 +00:00
|
|
|
final String flutterRoot = path.dirname(path.dirname(path.dirname(path.fromUri(Platform.script))));
|
|
|
|
final String flutter = path.join(flutterRoot, 'bin', Platform.isWindows ? 'flutter.bat' : 'flutter');
|
|
|
|
final String dart = path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', Platform.isWindows ? 'dart.exe' : 'dart');
|
|
|
|
final String pub = path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', Platform.isWindows ? 'pub.bat' : 'pub');
|
|
|
|
final String flutterTestArgs = Platform.environment['FLUTTER_TEST_ARGS'];
|
|
|
|
final bool hasColor = stdout.supportsAnsiEscapes;
|
|
|
|
|
|
|
|
final String bold = hasColor ? '\x1B[1m' : '';
|
|
|
|
final String red = hasColor ? '\x1B[31m' : '';
|
|
|
|
final String green = hasColor ? '\x1B[32m' : '';
|
|
|
|
final String yellow = hasColor ? '\x1B[33m' : '';
|
|
|
|
final String cyan = hasColor ? '\x1B[36m' : '';
|
|
|
|
final String reset = hasColor ? '\x1B[0m' : '';
|
2017-02-14 18:21:33 +00:00
|
|
|
|
2017-06-16 00:54:45 +00:00
|
|
|
const Map<String, ShardRunner> _kShards = const <String, ShardRunner>{
|
|
|
|
'docs': _generateDocs,
|
|
|
|
'analyze': _analyzeRepo,
|
|
|
|
'tests': _runTests,
|
|
|
|
'coverage': _runCoverage,
|
|
|
|
};
|
|
|
|
|
2017-02-14 18:21:33 +00:00
|
|
|
/// When you call this, you can set FLUTTER_TEST_ARGS to pass custom
|
|
|
|
/// arguments to flutter test. For example, you might want to call this
|
|
|
|
/// script using FLUTTER_TEST_ARGS=--local-engine=host_debug_unopt to
|
|
|
|
/// use your own build of the engine.
|
2017-03-20 23:16:34 +00:00
|
|
|
///
|
|
|
|
/// To run the analysis part, run it with SHARD=analyze
|
|
|
|
///
|
|
|
|
/// For example:
|
|
|
|
/// SHARD=analyze bin/cache/dart-sdk/bin/dart dev/bots/test.dart
|
|
|
|
/// FLUTTER_TEST_ARGS=--local-engine=host_debug_unopt bin/cache/dart-sdk/bin/dart dev/bots/test.dart
|
2017-02-14 18:21:33 +00:00
|
|
|
Future<Null> main() async {
|
2017-06-16 00:54:45 +00:00
|
|
|
final String shard = Platform.environment['SHARD'] ?? 'tests';
|
|
|
|
if (!_kShards.containsKey(shard))
|
|
|
|
throw new ArgumentError('Invalid shard: $shard');
|
|
|
|
await _kShards[shard]();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Null> _generateDocs() async {
|
|
|
|
print('${bold}DONE: test.dart does nothing in the docs shard.$reset');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Null> _analyzeRepo() async {
|
2017-06-30 21:42:22 +00:00
|
|
|
await _verifyNoBadImports(flutterRoot);
|
|
|
|
|
2017-06-16 00:54:45 +00:00
|
|
|
// Analyze all the Dart code in the repo.
|
|
|
|
await _runFlutterAnalyze(flutterRoot,
|
|
|
|
options: <String>['--flutter-repo'],
|
|
|
|
);
|
|
|
|
|
|
|
|
// Analyze all the sample code in the repo
|
|
|
|
await _runCommand(dart, <String>[path.join(flutterRoot, 'dev', 'bots', 'analyze-sample-code.dart')],
|
|
|
|
workingDirectory: flutterRoot,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Try with the --watch analyzer, to make sure it returns success also.
|
|
|
|
// The --benchmark argument exits after one run.
|
|
|
|
await _runFlutterAnalyze(flutterRoot,
|
|
|
|
options: <String>['--flutter-repo', '--watch', '--benchmark'],
|
|
|
|
);
|
|
|
|
|
|
|
|
// Try an analysis against a big version of the gallery.
|
|
|
|
await _runCommand(dart, <String>[path.join(flutterRoot, 'dev', 'tools', 'mega_gallery.dart')],
|
|
|
|
workingDirectory: flutterRoot,
|
|
|
|
);
|
|
|
|
await _runFlutterAnalyze(path.join(flutterRoot, 'dev', 'benchmarks', 'mega_gallery'),
|
|
|
|
options: <String>['--watch', '--benchmark'],
|
|
|
|
);
|
|
|
|
|
|
|
|
print('${bold}DONE: Analysis successful.$reset');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Null> _runTests() async {
|
|
|
|
// Verify that the tests actually return failure on failure and success on success.
|
|
|
|
final String automatedTests = path.join(flutterRoot, 'dev', 'automated_tests');
|
|
|
|
await _runFlutterTest(automatedTests,
|
|
|
|
script: path.join('test_smoke_test', 'fail_test.dart'),
|
|
|
|
expectFailure: true,
|
|
|
|
printOutput: false,
|
|
|
|
);
|
|
|
|
await _runFlutterTest(automatedTests,
|
|
|
|
script: path.join('test_smoke_test', 'pass_test.dart'),
|
|
|
|
printOutput: false,
|
|
|
|
);
|
|
|
|
await _runFlutterTest(automatedTests,
|
|
|
|
script: path.join('test_smoke_test', 'crash1_test.dart'),
|
|
|
|
expectFailure: true,
|
|
|
|
printOutput: false,
|
|
|
|
);
|
|
|
|
await _runFlutterTest(automatedTests,
|
|
|
|
script: path.join('test_smoke_test', 'crash2_test.dart'),
|
|
|
|
expectFailure: true,
|
|
|
|
printOutput: false,
|
|
|
|
);
|
|
|
|
await _runFlutterTest(automatedTests,
|
|
|
|
script: path.join('test_smoke_test', 'syntax_error_test.broken_dart'),
|
|
|
|
expectFailure: true,
|
|
|
|
printOutput: false,
|
|
|
|
);
|
|
|
|
await _runFlutterTest(automatedTests,
|
|
|
|
script: path.join('test_smoke_test', 'missing_import_test.broken_dart'),
|
|
|
|
expectFailure: true,
|
|
|
|
printOutput: false,
|
|
|
|
);
|
|
|
|
await _runCommand(flutter, <String>['drive', '--use-existing-app', '-t', path.join('test_driver', 'failure.dart')],
|
|
|
|
workingDirectory: path.join(flutterRoot, 'packages', 'flutter_driver'),
|
|
|
|
expectFailure: true,
|
|
|
|
printOutput: false,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Run tests.
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'));
|
|
|
|
await _pubRunTest(path.join(flutterRoot, 'packages', 'flutter_tools'));
|
|
|
|
|
|
|
|
await _runAllDartTests(path.join(flutterRoot, 'dev', 'devicelab'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'dev', 'manual_tests'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'examples', 'hello_world'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'examples', 'stocks'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'examples', 'flutter_gallery'));
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'examples', 'catalog'));
|
|
|
|
|
|
|
|
print('${bold}DONE: All tests successful.$reset');
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Null> _runCoverage() async {
|
|
|
|
if (Platform.environment['TRAVIS'] == null ||
|
|
|
|
Platform.environment['TRAVIS_PULL_REQUEST'] != 'false') {
|
|
|
|
print('${bold}DONE: test.dart does not run coverage for Travis pull requests');
|
|
|
|
return;
|
2017-02-17 04:40:07 +00:00
|
|
|
}
|
2017-06-16 00:54:45 +00:00
|
|
|
|
|
|
|
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter'),
|
|
|
|
options: const <String>['--coverage'],
|
|
|
|
);
|
|
|
|
|
|
|
|
print('${bold}DONE: Coverage collection successful.$reset');
|
2017-02-14 18:21:33 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 20:58:31 +00:00
|
|
|
Future<Null> _pubRunTest(
|
|
|
|
String workingDirectory, {
|
|
|
|
String testPath,
|
|
|
|
}) {
|
2017-06-12 21:50:04 +00:00
|
|
|
final List<String> args = <String>['run', 'test', '-j1', '-rexpanded'];
|
2017-03-09 20:58:31 +00:00
|
|
|
if (testPath != null)
|
|
|
|
args.add(testPath);
|
2017-04-13 17:22:41 +00:00
|
|
|
return _runCommand(pub, args, workingDirectory: workingDirectory);
|
2017-03-09 20:58:31 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 17:22:41 +00:00
|
|
|
Future<Null> _runCommand(String executable, List<String> arguments, {
|
2017-02-17 04:40:07 +00:00
|
|
|
String workingDirectory,
|
|
|
|
Map<String, String> environment,
|
|
|
|
bool expectFailure: false,
|
|
|
|
bool printOutput: true,
|
|
|
|
bool skip: false,
|
2017-02-14 18:21:33 +00:00
|
|
|
}) async {
|
2017-04-13 17:22:41 +00:00
|
|
|
final String commandDescription = '${path.relative(executable, from: workingDirectory)} ${arguments.join(' ')}';
|
|
|
|
final String relativeWorkingDir = path.relative(workingDirectory);
|
2017-02-14 18:21:33 +00:00
|
|
|
if (skip) {
|
2017-04-13 17:22:41 +00:00
|
|
|
_printProgress('SKIPPING', relativeWorkingDir, commandDescription);
|
2017-02-14 18:21:33 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-04-13 17:22:41 +00:00
|
|
|
_printProgress('RUNNING', relativeWorkingDir, commandDescription);
|
2017-02-14 18:21:33 +00:00
|
|
|
|
2017-03-04 02:06:08 +00:00
|
|
|
final Process process = await Process.start(executable, arguments,
|
2017-02-17 04:40:07 +00:00
|
|
|
workingDirectory: workingDirectory,
|
|
|
|
environment: environment,
|
2017-02-14 18:21:33 +00:00
|
|
|
);
|
|
|
|
|
2017-04-13 17:22:41 +00:00
|
|
|
Future<List<List<int>>> savedStdout, savedStderr;
|
2017-02-14 18:21:33 +00:00
|
|
|
if (printOutput) {
|
|
|
|
stdout.addStream(process.stdout);
|
|
|
|
stderr.addStream(process.stderr);
|
2017-04-13 17:22:41 +00:00
|
|
|
} else {
|
|
|
|
savedStdout = process.stdout.toList();
|
|
|
|
savedStderr = process.stderr.toList();
|
2017-02-14 18:21:33 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 02:06:08 +00:00
|
|
|
final int exitCode = await process.exitCode;
|
2017-02-14 18:21:33 +00:00
|
|
|
if ((exitCode == 0) == expectFailure) {
|
2017-04-13 17:22:41 +00:00
|
|
|
if (!printOutput) {
|
|
|
|
print(UTF8.decode((await savedStdout).expand((List<int> ints) => ints).toList()));
|
|
|
|
print(UTF8.decode((await savedStderr).expand((List<int> ints) => ints).toList()));
|
|
|
|
}
|
2017-02-14 18:21:33 +00:00
|
|
|
print(
|
2017-04-13 17:22:41 +00:00
|
|
|
'$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset\n'
|
|
|
|
'${bold}ERROR:$red Last command exited with $exitCode (expected: ${expectFailure ? 'non-zero' : 'zero'}).$reset\n'
|
|
|
|
'$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset'
|
2017-02-14 18:21:33 +00:00
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Null> _runFlutterTest(String workingDirectory, {
|
|
|
|
String script,
|
|
|
|
bool expectFailure: false,
|
|
|
|
bool printOutput: true,
|
|
|
|
List<String> options: const <String>[],
|
|
|
|
bool skip: false,
|
|
|
|
}) {
|
2017-03-04 02:06:08 +00:00
|
|
|
final List<String> args = <String>['test']..addAll(options);
|
2017-04-13 17:22:41 +00:00
|
|
|
if (flutterTestArgs != null && flutterTestArgs.isNotEmpty)
|
2017-02-14 18:21:33 +00:00
|
|
|
args.add(flutterTestArgs);
|
|
|
|
if (script != null)
|
|
|
|
args.add(script);
|
2017-04-13 17:22:41 +00:00
|
|
|
return _runCommand(flutter, args,
|
2017-02-17 04:40:07 +00:00
|
|
|
workingDirectory: workingDirectory,
|
|
|
|
expectFailure: expectFailure,
|
|
|
|
printOutput: printOutput,
|
|
|
|
skip: skip || Platform.isWindows, // TODO(goderbauer): run on Windows when sky_shell is available
|
2017-02-14 18:21:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Null> _runAllDartTests(String workingDirectory, {
|
2017-02-17 04:40:07 +00:00
|
|
|
Map<String, String> environment,
|
2017-02-14 18:21:33 +00:00
|
|
|
}) {
|
2017-04-13 17:22:41 +00:00
|
|
|
final List<String> args = <String>['--checked', path.join('test', 'all.dart')];
|
|
|
|
return _runCommand(dart, args,
|
2017-02-17 04:40:07 +00:00
|
|
|
workingDirectory: workingDirectory,
|
|
|
|
environment: environment,
|
2017-02-14 18:21:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Null> _runFlutterAnalyze(String workingDirectory, {
|
2017-02-17 04:40:07 +00:00
|
|
|
List<String> options: const <String>[]
|
2017-02-14 18:21:33 +00:00
|
|
|
}) {
|
2017-04-13 17:22:41 +00:00
|
|
|
return _runCommand(flutter, <String>['analyze']..addAll(options),
|
2017-02-17 04:40:07 +00:00
|
|
|
workingDirectory: workingDirectory,
|
2017-02-14 18:21:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-30 21:42:22 +00:00
|
|
|
Future<Null> _verifyNoBadImports(String workingDirectory) async {
|
|
|
|
final List<String> errors = <String>[];
|
|
|
|
final String libPath = path.join(workingDirectory, 'packages', 'flutter', 'lib');
|
|
|
|
final String srcPath = path.join(workingDirectory, 'packages', 'flutter', 'lib', 'src');
|
|
|
|
// Verify there's one libPath/*.dart for each srcPath/*/.
|
|
|
|
<String>[];
|
|
|
|
final List<String> packages = new Directory(libPath).listSync()
|
|
|
|
.where((FileSystemEntity entity) => entity is File && path.extension(entity.path) == '.dart')
|
|
|
|
.map<String>((FileSystemEntity entity) => path.basenameWithoutExtension(entity.path))
|
|
|
|
.toList()..sort();
|
|
|
|
final List<String> directories = new Directory(srcPath).listSync()
|
|
|
|
.where((FileSystemEntity entity) => entity is Directory)
|
|
|
|
.map<String>((FileSystemEntity entity) => path.basename(entity.path))
|
|
|
|
.toList()..sort();
|
|
|
|
if (!_matches(packages, directories)) {
|
|
|
|
errors.add(
|
|
|
|
'flutter/lib/*.dart does not match flutter/lib/src/*/:\n'
|
|
|
|
'These are the exported packages:\n' +
|
|
|
|
packages.map((String path) => ' lib/$path.dart').join('\n') +
|
|
|
|
'These are the directories:\n' +
|
|
|
|
directories.map((String path) => ' lib/src/$path/').join('\n')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Verify that the imports are well-ordered.
|
|
|
|
final Map<String, Set<String>> dependencyMap = new Map<String, Set<String>>.fromIterable(
|
|
|
|
directories,
|
|
|
|
key: (String directory) => directory,
|
|
|
|
value: (String directory) => _findDependencies(path.join(srcPath, directory), errors, checkForMeta: directory != 'foundation'),
|
|
|
|
);
|
|
|
|
for (String package in dependencyMap.keys) {
|
|
|
|
if (dependencyMap[package].contains(package)) {
|
|
|
|
errors.add(
|
|
|
|
'One of the files in the $yellow$package$reset package imports that package recursively.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (String package in dependencyMap.keys) {
|
|
|
|
final List<String> loop = _deepSearch(dependencyMap, package);
|
|
|
|
if (loop != null) {
|
|
|
|
errors.add(
|
|
|
|
'${yellow}Dependency loop:$reset ' +
|
|
|
|
loop.join(' depends on ')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fail if any errors
|
|
|
|
if (errors.isNotEmpty) {
|
|
|
|
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset');
|
|
|
|
if (errors.length == 1) {
|
|
|
|
print('${bold}An error was detected when looking at import dependencies within the Flutter package:$reset\n');
|
|
|
|
} else {
|
|
|
|
print('${bold}Multiple errors were detected when looking at import dependencies within the Flutter package:$reset\n');
|
|
|
|
}
|
|
|
|
print(errors.join('\n\n'));
|
|
|
|
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset\n');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _matches<T>(List<T> a, List<T> b) {
|
|
|
|
assert(a != null);
|
|
|
|
assert(b != null);
|
|
|
|
if (a.length != b.length)
|
|
|
|
return false;
|
|
|
|
for (int index = 0; index < a.length; index += 1) {
|
|
|
|
if (a[index] != b[index])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final RegExp _importPattern = new RegExp(r"import 'package:flutter/([^.]+)\.dart'");
|
|
|
|
final RegExp _importMetaPattern = new RegExp(r"import 'package:meta/meta.dart'");
|
|
|
|
|
|
|
|
Set<String> _findDependencies(String srcPath, List<String> errors, { bool checkForMeta: false }) {
|
|
|
|
return new Directory(srcPath).listSync().where((FileSystemEntity entity) {
|
|
|
|
return entity is File && path.extension(entity.path) == '.dart';
|
|
|
|
}).map<Set<String>>((FileSystemEntity entity) {
|
|
|
|
final Set<String> result = new Set<String>();
|
|
|
|
final File file = entity;
|
|
|
|
for (String line in file.readAsLinesSync()) {
|
|
|
|
Match match = _importPattern.firstMatch(line);
|
|
|
|
if (match != null)
|
|
|
|
result.add(match.group(1));
|
|
|
|
if (checkForMeta) {
|
|
|
|
match = _importMetaPattern.firstMatch(line);
|
|
|
|
if (match != null) {
|
|
|
|
errors.add(
|
|
|
|
'${file.path}\nThis package imports the ${yellow}meta$reset package.\n'
|
|
|
|
'You should instead import the "foundation.dart" library.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}).reduce((Set<String> value, Set<String> element) {
|
|
|
|
value ??= new Set<String>();
|
|
|
|
value.addAll(element);
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
List<T> _deepSearch<T>(Map<T, Set<T>> map, T start, [ Set<T> seen ]) {
|
|
|
|
for (T key in map[start]) {
|
|
|
|
if (key == start)
|
|
|
|
continue; // we catch these separately
|
|
|
|
if (seen != null && seen.contains(key))
|
|
|
|
return <T>[start, key];
|
|
|
|
final List<T> result = _deepSearch(
|
|
|
|
map,
|
|
|
|
key,
|
|
|
|
(seen == null ? new Set<T>.from(<T>[start]) : new Set<T>.from(seen))..add(key),
|
|
|
|
);
|
|
|
|
if (result != null) {
|
|
|
|
result.insert(0, start);
|
|
|
|
// Only report the shortest chains.
|
|
|
|
// For example a->b->a, rather than c->a->b->a.
|
|
|
|
// Since we visit every node, we know the shortest chains are those
|
|
|
|
// that start and end on the loop.
|
|
|
|
if (result.first == result.last)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-13 17:22:41 +00:00
|
|
|
void _printProgress(String action, String workingDir, String command) {
|
|
|
|
const String arrow = '⏩';
|
|
|
|
print('$arrow $action: cd $cyan$workingDir$reset; $yellow$command$reset');
|
2017-02-14 18:21:33 +00:00
|
|
|
}
|