@@ -11,6 +11,7 @@ import 'package:analyzer/file_system/file_system.dart' show ResourceProvider;
1111import 'package:analyzer/file_system/memory_file_system.dart' ;
1212import 'package:analyzer/file_system/physical_file_system.dart' ;
1313import 'package:analyzer/source/line_info.dart' ;
14+ import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart' ;
1415import 'package:analyzer/src/test_utilities/mock_sdk.dart' as mock_sdk;
1516import 'package:args/args.dart' ;
1617import 'package:cli_util/cli_logging.dart' ;
@@ -112,6 +113,10 @@ class _MigrationCliRunner extends MigrationCliRunner {
112113 _runWhilePreviewServerActive = null ;
113114 }
114115
116+ @override
117+ Set <String > computePathsToProcess (DriverBasedAnalysisContext context) =>
118+ cli._test.overridePathsToProcess ?? super .computePathsToProcess (context);
119+
115120 @override
116121 NonNullableFix createNonNullableFix (DartFixListener listener,
117122 ResourceProvider resourceProvider, LineInfo getLineInfo (String path),
@@ -139,6 +144,11 @@ class _MigrationCliRunner extends MigrationCliRunner {
139144 fail ('Preview server never started' );
140145 }
141146 }
147+
148+ @override
149+ bool shouldBeMigrated (DriverBasedAnalysisContext context, String path) =>
150+ cli._test.overrideShouldBeMigrated? .call (path) ??
151+ super .shouldBeMigrated (context, path);
142152}
143153
144154abstract class _MigrationCliTestBase {
@@ -148,6 +158,12 @@ abstract class _MigrationCliTestBase {
148158 /// encounters a reference to the `print` function.
149159 bool injectArtificialException = false ;
150160
161+ /// If non-null, this is injected as the return value for
162+ /// [_MigrationCliRunner.computePathsToProcess] .
163+ Set <String > overridePathsToProcess;
164+
165+ bool Function (String ) overrideShouldBeMigrated;
166+
151167 void set logger (_TestLogger logger);
152168
153169 _MockProcessManager get processManager;
@@ -690,6 +706,52 @@ int? f() => null
690706 assertProjectContents (projectDir, projectContents);
691707 }
692708
709+ test_lifecycle_override_paths () async {
710+ Map <String , String > makeProject ({bool migrated = false }) {
711+ var projectContents = simpleProject (migrated: migrated);
712+ projectContents['lib/test.dart' ] = '''
713+ import 'skip.dart';
714+ import 'analyze_but_do_not_migrate.dart';
715+ void f(int x) {}
716+ void g(int${migrated ? '?' : '' } x) {}
717+ void h(int${migrated ? '?' : '' } x) {}
718+ void call_h() => h(null);
719+ ''' ;
720+ projectContents['lib/skip.dart' ] = '''
721+ import 'test.dart';
722+ void call_f() => f(null);
723+ ''' ;
724+ projectContents['lib/analyze_but_do_not_migrate.dart' ] = '''
725+ import 'test.dart';
726+ void call_g() => g(null);
727+ ''' ;
728+ return projectContents;
729+ }
730+
731+ var projectContents = makeProject ();
732+ var projectDir = await createProjectDir (projectContents);
733+ var testPath =
734+ resourceProvider.pathContext.join (projectDir, 'lib' , 'test.dart' );
735+ var analyzeButDoNotMigratePath = resourceProvider.pathContext
736+ .join (projectDir, 'lib' , 'analyze_but_do_not_migrate.dart' );
737+ overridePathsToProcess = {testPath, analyzeButDoNotMigratePath};
738+ overrideShouldBeMigrated = (path) => path == testPath;
739+ var cliRunner = _createCli ().decodeCommandLineArgs (
740+ _parseArgs (['--no-web-preview' , '--apply-changes' , projectDir]));
741+ await cliRunner.run ();
742+ assertNormalExit (cliRunner);
743+ // Check that a summary was printed
744+ expect (logger.stdoutBuffer.toString (), contains ('Applying changes' ));
745+ // And that it refers to test.dart and pubspec.yaml
746+ expect (logger.stdoutBuffer.toString (), contains ('test.dart' ));
747+ expect (logger.stdoutBuffer.toString (), contains ('pubspec.yaml' ));
748+ // And that it does not tell the user they can rerun with `--apply-changes`
749+ expect (logger.stdoutBuffer.toString (), isNot (contains ('--apply-changes' )));
750+ // Changes should have been made only to test.dart, and only accounting for
751+ // the calls coming from analyze_but_do_not_migrate.dart and test.dart
752+ assertProjectContents (projectDir, makeProject (migrated: true ));
753+ }
754+
693755 test_lifecycle_preview () async {
694756 var projectContents = simpleProject ();
695757 var projectDir = await createProjectDir (projectContents);
0 commit comments