Migration: make sure new CLI detects when run with an old SDK

Change-Id: I7b279788e34d3d2e86df58ff4ef7c86b58e154e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145644
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2020-04-30 21:50:12 +00:00 committed by commit-bot@chromium.org
parent c33f4ad9fc
commit ff53bd8d4a
2 changed files with 30 additions and 2 deletions

View file

@ -218,8 +218,13 @@ class MigrationCli {
preferredPort: options.previewPort,
enablePreview: options.webPreview);
fixCodeProcessor.registerCodeTask(nonNullableFix);
await fixCodeProcessor.runFirstPhase();
_checkForErrors();
try {
await fixCodeProcessor.runFirstPhase();
_checkForErrors();
} on StateError catch (e) {
logger.stdout(e.toString());
exitCode = 1;
}
if (exitCode != null) return;
previewUrls = await fixCodeProcessor.runLaterPhases();
});

View file

@ -159,6 +159,29 @@ int${migrated ? '?' : ''} f() => null;
expect(MigrationCli(binaryName: 'nnbd_migration').logger, isNotNull);
}
test_detect_old_sdk() async {
var cli = _createCli();
// Alter the mock SDK, changing the signature of Object.operator== to match
// the signature that was present prior to NNBD. (This is what the
// migration tool uses to detect an old SDK).
var coreLib = resourceProvider.getFile(
resourceProvider.convertPath('${mock_sdk.sdkRoot}/lib/core/core.dart'));
var oldCoreLibText = coreLib.readAsStringSync();
var newCoreLibText = oldCoreLibText.replaceAll(
'external bool operator ==(Object other)',
'external bool operator ==(dynamic other)');
expect(newCoreLibText, isNot(oldCoreLibText));
coreLib.writeAsStringSync(newCoreLibText);
var projectDir = await createProjectDir(simpleProject());
await cli.run([projectDir]);
assertErrorExit(cli, withUsage: false);
var output = logger.stdoutBuffer.toString();
expect(
output,
contains(
'Bad state: Analysis seems to have an SDK without NNBD enabled'));
}
test_flag_apply_changes_default() {
expect(assertParseArgsSuccess([]).applyChanges, isFalse);
}