diff --git a/pkg/dartdev/test/commands/migrate_test.dart b/pkg/dartdev/test/commands/migrate_test.dart index ceb960b46e1..1294f88a909 100644 --- a/pkg/dartdev/test/commands/migrate_test.dart +++ b/pkg/dartdev/test/commands/migrate_test.dart @@ -16,6 +16,8 @@ void main() { bool _nnbdIsEnabled = false; void defineMigrateTests() { + final didYouForgetToRunPubGet = contains('Did you forget to run "pub get"?'); + TestProject p; tearDown(() => p?.dispose()); @@ -67,4 +69,22 @@ void defineMigrateTests() { contains('not found; please provide a path to a package or directory')); expect(result.stdout, isEmpty); }); + + test('pub get needs running', () { + p = project(mainSrc: 'import "package:foo/foo.dart";\n'); + var result = p.runSync('migrate', + ['--server-path=${p.absolutePathToAnalysisServerFile}', p.dirPath]); + expect(result.exitCode, 1); + expect(result.stderr, isEmpty); + expect(result.stdout, didYouForgetToRunPubGet); + }); + + test('non-pub-related error', () { + p = project(mainSrc: 'var missing = "semicolon"\n'); + var result = p.runSync('migrate', + ['--server-path=${p.absolutePathToAnalysisServerFile}', p.dirPath]); + expect(result.exitCode, 1); + expect(result.stderr, isEmpty); + expect(result.stdout, isNot(didYouForgetToRunPubGet)); + }); } diff --git a/pkg/dartfix/lib/src/migrate/migrate.dart b/pkg/dartfix/lib/src/migrate/migrate.dart index 6e86551e4f4..ceddcce4428 100644 --- a/pkg/dartfix/lib/src/migrate/migrate.dart +++ b/pkg/dartfix/lib/src/migrate/migrate.dart @@ -158,12 +158,14 @@ class MigrateCommand extends Command { fileErrors.values.map((list) => list.length).reduce((a, b) => a + b); logger.stdout( '$issueCount analysis ${pluralize('issue', issueCount)} found:'); + List allErrors = fileErrors.values + .fold([], (list, element) => list..addAll(element)); _displayIssues( logger, options.directory, - fileErrors.values - .fold([], (list, element) => list..addAll(element)), + allErrors, ); + var importErrorCount = allErrors.where(_isUriError).length; logger.stdout(''); logger.stdout( @@ -172,9 +174,14 @@ class MigrateCommand extends Command { if (options.ignoreErrors) { logger.stdout('Continuing with migration suggestions due to the use of ' '--${MigrateOptions.ignoreErrorsOption}.'); - } else if (!options.ignoreErrors) { + } else { // Fail with how to continue. logger.stdout(''); + if (importErrorCount != 0) { + logger.stdout( + 'Unresolved URIs found. Did you forget to run "pub get"?'); + logger.stdout(''); + } logger.stdout( 'Please fix the analysis issues (or, force generation of migration ' 'suggestions by re-running with ' @@ -371,6 +378,8 @@ the tool with --${MigrateOptions.applyChangesOption}). } } + bool _isUriError(AnalysisError error) => error.code == 'uri_does_not_exist'; + /// Parse and validate the user's options; throw a UsageException if there are /// issues, and return an [MigrateOptions] result otherwise. MigrateOptions _parseAndValidateOptions() {