Repository navigation
Expand file tree
/
Copy pathtest_command.dart
More file actions
60 lines (48 loc) · 1.73 KB
/
Copy pathtest_command.dart
File metadata and controls
60 lines (48 loc) · 1.73 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// 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.
import 'dart:async';
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:path/path.dart' as p;
import 'common.dart';
class TestCommand extends Command<Null> {
TestCommand(this.packagesDir);
final Directory packagesDir;
@override
final String name = 'test';
@override
final String description = 'Runs the Dart tests for all packages.';
@override
Future<Null> run() async {
final List<String> failingPackages = <String>[];
await for (Directory packageDir in _listAllPackages(packagesDir)) {
final String packageName =
p.relative(packageDir.path, from: packagesDir.path);
if (!new Directory(p.join(packageDir.path, 'test')).existsSync()) {
print('\nSKIPPING $packageName - no test subdirectory');
continue;
}
print('\nRUNNING $packageName tests...');
final int exitCode = await runAndStream(
'flutter', <String>['test', '--color'], packageDir);
if (exitCode != 0) {
failingPackages.add(packageName);
}
}
print('\n\n');
if (failingPackages.isNotEmpty) {
print('Tests for the following packages are failing (see above):');
failingPackages.forEach((String package) {
print(' * $package');
});
throw new ToolExit(1);
}
print('All tests are passing!');
}
Stream<Directory> _listAllPackages(Directory root) => root
.list(recursive: true)
.where((FileSystemEntity entity) =>
entity is File && p.basename(entity.path) == 'pubspec.yaml')
.map((FileSystemEntity entity) => entity.parent);
}