Commit a55a745c authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fail tests with an actionable message when FLUTTER_ROOT is not set (#8236)

Also: Fix some analyzer warnings.
parent d7b0f7db
......@@ -140,7 +140,7 @@ class AndroidSdk {
if (platformsDir.existsSync()) {
platforms = platformsDir
.listSync()
.map((FileSystemEntity entity) => fs.path.basename(entity.path))
.map<String>((FileSystemEntity entity) => fs.path.basename(entity.path))
.where((String name) => name.startsWith('android-'))
.toList();
}
......
......@@ -336,8 +336,9 @@ Map<_Asset, List<_Asset>> _parseAssets(
if (manifestDescriptor == null)
return result;
excludeDirs = excludeDirs.map(
(String exclude) => fs.path.absolute(exclude) + fs.path.separator).toList();
excludeDirs = excludeDirs.map<String>(
(String exclude) => fs.path.absolute(exclude) + fs.path.separator
).toList();
if (manifestDescriptor.containsKey('assets')) {
for (String asset in manifestDescriptor['assets']) {
......
......@@ -172,7 +172,7 @@ class TestCommand extends FlutterCommand {
testArgs.add('--');
Directory testDir;
Iterable<String> files = argResults.rest.map((String testPath) => fs.path.absolute(testPath)).toList();
Iterable<String> files = argResults.rest.map<String>((String testPath) => fs.path.absolute(testPath)).toList();
if (argResults['start-paused']) {
if (files.length != 1)
throwToolExit('When using --start-paused, you must specify a single test file to run.', exitCode: 1);
......
......@@ -30,8 +30,7 @@ import 'device_test.dart' as device_test;
import 'devices_test.dart' as devices_test;
import 'doctor_test.dart' as doctor_test;
import 'drive_test.dart' as drive_test;
import 'forbid_dart_io_test.dart' as forbid_dart_io_test;
import 'forbid_package_path_test.dart' as forbid_package_path_test;
import 'forbidden_imports_test.dart' as forbidden_imports_test;
import 'format_test.dart' as format_test;
import 'hot_test.dart' as hot_test;
import 'install_test.dart' as install_test;
......@@ -70,8 +69,7 @@ void main() {
devices_test.main();
doctor_test.main();
drive_test.main();
forbid_dart_io_test.main();
forbid_package_path_test.main();
forbidden_imports_test.main();
format_test.main();
hot_test.main();
install_test.main();
......
// Copyright 2016 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 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:test/test.dart';
void main() {
setUp(() {
String flutterTools = fs.path.join(platform.environment['FLUTTER_ROOT'],
'packages', 'flutter_tools');
assert(fs.path.equals(fs.currentDirectory.path, flutterTools));
});
test('no unauthorized imports of package:path', () {
for (String path in <String>['lib', 'bin', 'test']) {
fs.directory(path)
.listSync(recursive: true)
.where(_isDartFile)
.map(_asFile)
.forEach((File file) {
for (String line in file.readAsLinesSync()) {
if (line.startsWith(new RegExp('import.*package:path/path.dart'))) {
fail("${file.path} imports 'package:path/path.dart'; use 'fs.path' instead");
}
}
}
);
}
});
}
bool _isDartFile(FileSystemEntity entity) => entity is File && entity.path.endsWith('.dart');
File _asFile(FileSystemEntity entity) => entity;
......@@ -8,12 +8,16 @@ import 'package:test/test.dart';
void main() {
setUp(() {
String flutterTools = fs.path.join(platform.environment['FLUTTER_ROOT'],
'packages', 'flutter_tools');
String flutterRoot = platform.environment['FLUTTER_ROOT'];
if (flutterRoot == null)
throw new Exception('Please set FLUTTER_ROOT env var before running tests.');
String flutterTools = fs.path.join(flutterRoot, 'packages', 'flutter_tools');
assert(fs.path.equals(fs.currentDirectory.path, flutterTools));
});
test('no unauthorized imports of dart:io', () {
bool _isNotWhitelisted(FileSystemEntity entity) => entity.path != fs.path.join('lib', 'src', 'base', 'io.dart');
for (String path in <String>['lib', 'bin']) {
fs.directory(path)
.listSync(recursive: true)
......@@ -31,12 +35,25 @@ void main() {
);
}
});
}
bool _isDartFile(FileSystemEntity entity) =>
entity is File && entity.path.endsWith('.dart');
test('no unauthorized imports of package:path', () {
for (String path in <String>['lib', 'bin', 'test']) {
fs.directory(path)
.listSync(recursive: true)
.where(_isDartFile)
.map(_asFile)
.forEach((File file) {
for (String line in file.readAsLinesSync()) {
if (line.startsWith(new RegExp('import.*package:path/path.dart'))) {
fail("${file.path} imports 'package:path/path.dart'; use 'fs.path' instead");
}
}
}
);
}
});
}
bool _isNotWhitelisted(FileSystemEntity entity) =>
entity.path != fs.path.join('lib', 'src', 'base', 'io.dart');
bool _isDartFile(FileSystemEntity entity) => entity is File && entity.path.endsWith('.dart');
File _asFile(FileSystemEntity entity) => entity;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment