@@ -75,21 +75,17 @@ class _ExceptionGeneratingNonNullableFix extends NonNullableFix {
7575}
7676
7777class _MigrationCli extends MigrationCli {
78- /// If `true` , then an artifical exception should be generated when migration
79- /// encounters a reference to the `print` function.
80- final bool injectArtificialException;
78+ final _MigrationCliTestBase _test;
8179
82- _MigrationCli (_MigrationCliTestBase test,
83- {this .injectArtificialException = false ,
84- Map <String , String > environmentVariables})
80+ _MigrationCli (this ._test)
8581 : super (
8682 binaryName: 'nnbd_migration' ,
87- loggerFactory: (isVerbose) => test .logger = _TestLogger (isVerbose),
83+ loggerFactory: (isVerbose) => _test .logger = _TestLogger (isVerbose),
8884 defaultSdkPathOverride:
89- test .resourceProvider.convertPath (mock_sdk.sdkRoot),
90- resourceProvider: test .resourceProvider,
91- processManager: test .processManager,
92- environmentVariables: environmentVariables);
85+ _test .resourceProvider.convertPath (mock_sdk.sdkRoot),
86+ resourceProvider: _test .resourceProvider,
87+ processManager: _test .processManager,
88+ environmentVariables: _test. environmentVariables);
9389
9490 _MigrationCliRunner decodeCommandLineArgs (ArgResults argResults,
9591 {bool isVerbose}) {
@@ -122,7 +118,7 @@ class _MigrationCliRunner extends MigrationCliRunner {
122118 {List <String > included = const < String > [],
123119 int preferredPort,
124120 String summaryPath}) {
125- if (cli.injectArtificialException) {
121+ if (cli._test. injectArtificialException) {
126122 return _ExceptionGeneratingNonNullableFix (
127123 listener, resourceProvider, getLineInfo,
128124 included: included,
@@ -146,6 +142,12 @@ class _MigrationCliRunner extends MigrationCliRunner {
146142}
147143
148144abstract class _MigrationCliTestBase {
145+ Map <String , String > environmentVariables = {};
146+
147+ /// If `true` , then an artificial exception should be generated when migration
148+ /// encounters a reference to the `print` function.
149+ bool injectArtificialException = false ;
150+
149151 void set logger (_TestLogger logger);
150152
151153 _MockProcessManager get processManager;
@@ -157,8 +159,6 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
157159 @override
158160 /*late*/ _TestLogger logger;
159161
160- Map <String , String > environmentVariables = {};
161-
162162 final hasVerboseHelpMessage = contains ('for verbose help output' );
163163
164164 final hasUsageText = contains ('Usage: nnbd_migration' );
@@ -576,8 +576,8 @@ linter:
576576 test_lifecycle_exception_handling () async {
577577 var projectContents = simpleProject (sourceText: 'main() { print(0); }' );
578578 var projectDir = await createProjectDir (projectContents);
579- var cli = _createCli (injectArtificialException : true ) ;
580- await assertRunFailure ([projectDir], cli : cli );
579+ injectArtificialException = true ;
580+ await assertRunFailure ([projectDir]);
581581 var errorOutput = logger.stderrBuffer.toString ();
582582 expect (errorOutput, contains ('Artificial exception triggered' ));
583583 expect (
@@ -588,7 +588,8 @@ linter:
588588 test_lifecycle_exception_handling_ignore () async {
589589 var projectContents = simpleProject (sourceText: 'main() { print(0); }' );
590590 var projectDir = await createProjectDir (projectContents);
591- var cli = _createCli (injectArtificialException: true );
591+ injectArtificialException = true ;
592+ var cli = _createCli ();
592593 await runWithPreviewServer (cli, ['--ignore-exceptions' , projectDir],
593594 (url) async {
594595 var output = logger.stdoutBuffer.toString ();
@@ -608,8 +609,8 @@ linter:
608609 var projectContents =
609610 simpleProject (sourceText: 'main() { print(0); print(1); }' );
610611 var projectDir = await createProjectDir (projectContents);
611- var cli = _createCli (injectArtificialException : true ) ;
612- await assertRunFailure ([projectDir], cli : cli );
612+ injectArtificialException = true ;
613+ await assertRunFailure ([projectDir]);
613614 var errorOutput = logger.stderrBuffer.toString ();
614615 expect (
615616 'Artificial exception triggered' .allMatches (errorOutput), hasLength (1 ));
@@ -622,8 +623,8 @@ linter:
622623 var projectContents =
623624 simpleProject (sourceText: 'main() { print(0); unresolved; }' );
624625 var projectDir = await createProjectDir (projectContents);
625- var cli = _createCli (injectArtificialException : true ) ;
626- await assertRunFailure (['--ignore-errors' , projectDir], cli : cli );
626+ injectArtificialException = true ;
627+ await assertRunFailure (['--ignore-errors' , projectDir]);
627628 var errorOutput = logger.stderrBuffer.toString ();
628629 expect (errorOutput, contains ('Artificial exception triggered' ));
629630 expect (errorOutput, contains ('try to fix errors in the source code' ));
@@ -1594,11 +1595,9 @@ name: test
15941595 headers: {'Content-Type' : 'application/json; charset=UTF-8' });
15951596 }
15961597
1597- _MigrationCli _createCli ({ bool injectArtificialException = false } ) {
1598+ _MigrationCli _createCli () {
15981599 mock_sdk.MockSdk (resourceProvider: resourceProvider);
1599- return _MigrationCli (this ,
1600- injectArtificialException: injectArtificialException,
1601- environmentVariables: environmentVariables);
1600+ return _MigrationCli (this );
16021601 }
16031602
16041603 String _getHelpText ({@required bool verbose}) {
0 commit comments