Add sanity checks for NNBD state in migration.

Also adds some ability for the migration tool to abort itself on
a few known-fatal errors and armor-plates dartdev tests against
CWD problems.

Bug: https://github.com/dart-lang/sdk/issues/40329
Change-Id: I1cfa2c9dcc7815eed075ecb38c63a74c75889002
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139282
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Janice Collins <jcollins@google.com>
This commit is contained in:
Janice Collins
2020-03-16 18:27:58 +00:00
committed by commit-bot@chromium.org
parent 704e8eae49
commit 34fee361b6
6 changed files with 98 additions and 30 deletions
+22 -8
View File
@@ -7,6 +7,10 @@ import 'package:test/test.dart';
import '../utils.dart';
// TODO(jcollins-g): Set to true and/or remove when when NNBD is enabled in the
// SDK running this test.
bool _nnbdIsEnabled = false;
void main() {
group('migrate', defineMigrateTests);
}
@@ -30,24 +34,34 @@ void defineMigrateTests() {
test('directory implicit', () {
p = project(mainSrc: 'int get foo => 1;\n');
var result =
p.runSync('migrate', ['--no-web-preview'], workingDir: p.dirPath);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
var result = p.runSync(
'migrate',
[
'--no-web-preview',
'--server-path=${p.absolutePathToAnalysisServerFile}'
],
workingDir: p.dirPath);
expect(result.exitCode, _nnbdIsEnabled ? 0 : 2);
expect(result.stderr, _nnbdIsEnabled ? isEmpty : isNotEmpty);
expect(result.stdout, contains('Generating migration suggestions'));
});
test('directory explicit', () {
p = project(mainSrc: 'int get foo => 1;\n');
var result = p.runSync('migrate', ['--no-web-preview', p.dirPath]);
expect(result.exitCode, 0);
expect(result.stderr, isEmpty);
var result = p.runSync('migrate', [
'--no-web-preview',
'--server-path=${p.absolutePathToAnalysisServerFile}',
p.dirPath
]);
expect(result.exitCode, _nnbdIsEnabled ? 0 : 2);
expect(result.stderr, _nnbdIsEnabled ? isEmpty : isNotEmpty);
expect(result.stdout, contains('Generating migration suggestions'));
});
test('bad directory', () {
p = project(mainSrc: 'int get foo => 1;\n');
var result = p.runSync('migrate', ['foo_bar_dir']);
var result = p.runSync('migrate',
['--server-path=${p.absolutePathToAnalysisServerFile}', 'foo_bar_dir']);
expect(result.exitCode, 64);
expect(result.stderr,
contains('not found; please provide a path to a package or directory'));
+27 -11
View File
@@ -63,18 +63,34 @@ class TestProject {
);
}
/// The path relative from `Directory.current.path` to `dartdev.dart` is
/// different when executing these tests locally versus on the Dart
/// buildbots, this if-else captures this change and branches for each case.
String get absolutePathToDartdevFile {
var dartdevFilePathOnBots = path.absolute(path.join(
Directory.current.path, 'pkg', 'dartdev', 'bin', 'dartdev.dart'));
if (File(dartdevFilePathOnBots).existsSync()) {
return dartdevFilePathOnBots;
} else {
return path
.absolute(path.join(Directory.current.path, 'bin', 'dartdev.dart'));
String _sdkRootPath;
/// Return the root of the SDK.
String get sdkRootPath {
if (_sdkRootPath == null) {
// Assumes the script importing this one is somewhere under the SDK.
String current = path.canonicalize(Platform.script.toFilePath());
do {
String tryDir = path.dirname(current);
if (File(path.join(tryDir, 'pkg', 'dartdev', 'bin', 'dartdev.dart'))
.existsSync()) {
_sdkRootPath = tryDir;
return _sdkRootPath;
}
current = tryDir;
} while (path.dirname(current) != current);
throw StateError('can not find SDK repository root');
}
return _sdkRootPath;
}
String get absolutePathToDartdevFile {
return path.join(sdkRootPath, 'pkg', 'dartdev', 'bin', 'dartdev.dart');
}
String get absolutePathToAnalysisServerFile {
return path.join(
sdkRootPath, 'pkg', 'analysis_server', 'bin', 'server.dart');
}
File findFile(String name) {