Move flutter tests from packages/unit to packages/flutter/test

This commit is contained in:
Ian Hickson
2015-12-15 22:32:45 -08:00
parent 1d39db6959
commit 7151fdd054
109 changed files with 74 additions and 72 deletions

View File

@@ -62,42 +62,11 @@ class AnalyzeCommand extends FlutterCommand {
}
}
bool foundTest = false;
Directory flutterDir = new Directory(path.join(ArtifactStore.flutterRoot, 'packages/unit')); // See https://github.com/flutter/flutter/issues/50
// .../packages/unit/test/*/*_test.dart
Directory tests = new Directory(path.join(flutterDir.path, 'test'));
for (FileSystemEntity entry in tests.listSync()) {
if (entry is Directory) {
for (FileSystemEntity subentry in entry.listSync()) {
if (subentry is File && subentry.path.endsWith('_test.dart')) {
dartFiles.add(subentry.path);
foundTest = true;
}
}
}
}
// .../packages/unit/benchmark/*/*_bench.dart
Directory benchmarks = new Directory(path.join(flutterDir.path, 'benchmark'));
for (FileSystemEntity entry in benchmarks.listSync()) {
if (entry is Directory) {
for (FileSystemEntity subentry in entry.listSync()) {
if (subentry is File && subentry.path.endsWith('_bench.dart')) {
dartFiles.add(subentry.path);
foundTest = true;
}
}
}
}
if (foundTest)
pubSpecDirectories.add(flutterDir.path);
// .../packages/*/bin/*.dart
// .../packages/*/lib/main.dart
// .../packages/*/test/*_test.dart
// .../packages/*/test/*/*_test.dart
// .../packages/*/benchmark/*/*_bench.dart
Directory packages = new Directory(path.join(ArtifactStore.flutterRoot, 'packages'));
for (FileSystemEntity entry in packages.listSync()) {
if (entry is Directory) {
@@ -126,12 +95,29 @@ class AnalyzeCommand extends FlutterCommand {
for (FileSystemEntity subentry in entry.listSync()) {
if (subentry is File && subentry.path.endsWith('_test.dart')) {
dartFiles.add(subentry.path);
foundTest = true;
foundOne = true;
}
}
} else if (entry is File && entry.path.endsWith('_test.dart')) {
dartFiles.add(entry.path);
foundTest = true;
foundOne = true;
}
}
}
Directory benchmarkDirectory = new Directory(path.join(entry.path, 'benchmark'));
if (benchmarkDirectory.existsSync()) {
for (FileSystemEntity entry in benchmarkDirectory.listSync()) {
if (entry is Directory) {
for (FileSystemEntity subentry in entry.listSync()) {
if (subentry is File && subentry.path.endsWith('_bench.dart')) {
dartFiles.add(subentry.path);
foundOne = true;
}
}
} else if (entry is File && entry.path.endsWith('_bench.dart')) {
dartFiles.add(entry.path);
foundOne = true;
}
}
}

View File

@@ -16,14 +16,16 @@ import '../test/loader.dart' as loader;
class TestCommand extends FlutterCommand {
String get name => 'test';
String get description => 'Runs Flutter unit tests for the current project. At least one of --debug and --release must be set.';
String get description => 'Runs Flutter unit tests for the current project.';
bool get requiresProjectRoot => false;
String get projectRootValidationErrorMessage {
return 'Error: No pubspec.yaml file found.\n'
'If you wish to run the tests in the flutter repo, pass --flutter-repo before\n'
'any test paths. Otherwise, run this command from the root of your project.';
'If you wish to run the tests in the Flutter repository\'s \'flutter\' package,\n'
'pass --flutter-repo before any test paths. Otherwise, run this command from the\n'
'root of your project. Test files must be called *_test.dart and must reside in\n'
'the package\'s \'test\' directory (or one of its subdirectories).';
}
Future<String> _getShellPath(BuildConfiguration config) async {
@@ -44,7 +46,7 @@ class TestCommand extends FlutterCommand {
}
TestCommand() {
argParser.addFlag('flutter-repo', help: 'Run tests from the Flutter repository instead of the current directory.', defaultsTo: false);
argParser.addFlag('flutter-repo', help: 'Run tests from the \'flutter\' package in the Flutter repository instead of the current directory.', defaultsTo: false);
}
Iterable<String> _findTests(Directory directory) {
@@ -54,7 +56,13 @@ class TestCommand extends FlutterCommand {
}
Directory get _flutterUnitTestDir {
return new Directory(path.join(ArtifactStore.flutterRoot, 'packages', 'unit', 'test'));
return new Directory(path.join(ArtifactStore.flutterRoot, 'packages', 'flutter', 'test'));
}
Directory get _currentPackageTestDir {
// We don't scan the entire package, only the test/ subdirectory, so that
// files with names like like "hit_test.dart" don't get run.
return new Directory('test');
}
Future<int> _runTests(List<String> testArgs, Directory testDirectory) async {
@@ -76,11 +84,11 @@ class TestCommand extends FlutterCommand {
return 1;
// If we're running the flutter tests, we want to use the packages directory
// from the unit package in order to find the proper shell binary.
// from the flutter package in order to find the proper shell binary.
if (runFlutterTests && ArtifactStore.packageRoot == 'packages')
ArtifactStore.packageRoot = path.join(ArtifactStore.flutterRoot, 'packages', 'unit', 'packages');
ArtifactStore.packageRoot = path.join(ArtifactStore.flutterRoot, 'packages', 'flutter', 'packages');
Directory testDir = runFlutterTests ? _flutterUnitTestDir : Directory.current;
Directory testDir = runFlutterTests ? _flutterUnitTestDir : _currentPackageTestDir;
if (testArgs.isEmpty)
testArgs.addAll(_findTests(testDir));

View File

@@ -16,12 +16,18 @@ dependencies:
mustache4dart: ^1.0.0
path: ^1.3.0
stack_trace: ^1.4.0
test: 0.12.6+1
test: 0.12.6+1 # see note below
yaml: ^2.1.3
flx:
path: ../flx
# A note about 'test':
# We depend on very specific internal implementation details of the
# 'test' package, which change between versions, so here we pin it
# precisely. This is also pinned in the 'flutter' package.
# See also https://github.com/dart-lang/test/pull/320
# A note about 'analyzer':
# We don't actually depend on 'analyzer', but 'test' does. We aren't
# compatible with some older versions of 'analyzer'. We lie here,