@@ -75,21 +75,17 @@ class _ExceptionGeneratingNonNullableFix extends NonNullableFix {
75
75
}
76
76
77
77
class _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;
81
79
82
- _MigrationCli (_MigrationCliTestBase test,
83
- {this .injectArtificialException = false ,
84
- Map <String , String > environmentVariables})
80
+ _MigrationCli (this ._test)
85
81
: super (
86
82
binaryName: 'nnbd_migration' ,
87
- loggerFactory: (isVerbose) => test .logger = _TestLogger (isVerbose),
83
+ loggerFactory: (isVerbose) => _test .logger = _TestLogger (isVerbose),
88
84
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);
93
89
94
90
_MigrationCliRunner decodeCommandLineArgs (ArgResults argResults,
95
91
{bool isVerbose}) {
@@ -122,7 +118,7 @@ class _MigrationCliRunner extends MigrationCliRunner {
122
118
{List <String > included = const < String > [],
123
119
int preferredPort,
124
120
String summaryPath}) {
125
- if (cli.injectArtificialException) {
121
+ if (cli._test. injectArtificialException) {
126
122
return _ExceptionGeneratingNonNullableFix (
127
123
listener, resourceProvider, getLineInfo,
128
124
included: included,
@@ -146,6 +142,12 @@ class _MigrationCliRunner extends MigrationCliRunner {
146
142
}
147
143
148
144
abstract 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
+
149
151
void set logger (_TestLogger logger);
150
152
151
153
_MockProcessManager get processManager;
@@ -157,8 +159,6 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
157
159
@override
158
160
/*late*/ _TestLogger logger;
159
161
160
- Map <String , String > environmentVariables = {};
161
-
162
162
final hasVerboseHelpMessage = contains ('for verbose help output' );
163
163
164
164
final hasUsageText = contains ('Usage: nnbd_migration' );
@@ -576,8 +576,8 @@ linter:
576
576
test_lifecycle_exception_handling () async {
577
577
var projectContents = simpleProject (sourceText: 'main() { print(0); }' );
578
578
var projectDir = await createProjectDir (projectContents);
579
- var cli = _createCli (injectArtificialException : true ) ;
580
- await assertRunFailure ([projectDir], cli : cli );
579
+ injectArtificialException = true ;
580
+ await assertRunFailure ([projectDir]);
581
581
var errorOutput = logger.stderrBuffer.toString ();
582
582
expect (errorOutput, contains ('Artificial exception triggered' ));
583
583
expect (
@@ -588,7 +588,8 @@ linter:
588
588
test_lifecycle_exception_handling_ignore () async {
589
589
var projectContents = simpleProject (sourceText: 'main() { print(0); }' );
590
590
var projectDir = await createProjectDir (projectContents);
591
- var cli = _createCli (injectArtificialException: true );
591
+ injectArtificialException = true ;
592
+ var cli = _createCli ();
592
593
await runWithPreviewServer (cli, ['--ignore-exceptions' , projectDir],
593
594
(url) async {
594
595
var output = logger.stdoutBuffer.toString ();
@@ -608,8 +609,8 @@ linter:
608
609
var projectContents =
609
610
simpleProject (sourceText: 'main() { print(0); print(1); }' );
610
611
var projectDir = await createProjectDir (projectContents);
611
- var cli = _createCli (injectArtificialException : true ) ;
612
- await assertRunFailure ([projectDir], cli : cli );
612
+ injectArtificialException = true ;
613
+ await assertRunFailure ([projectDir]);
613
614
var errorOutput = logger.stderrBuffer.toString ();
614
615
expect (
615
616
'Artificial exception triggered' .allMatches (errorOutput), hasLength (1 ));
@@ -622,8 +623,8 @@ linter:
622
623
var projectContents =
623
624
simpleProject (sourceText: 'main() { print(0); unresolved; }' );
624
625
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]);
627
628
var errorOutput = logger.stderrBuffer.toString ();
628
629
expect (errorOutput, contains ('Artificial exception triggered' ));
629
630
expect (errorOutput, contains ('try to fix errors in the source code' ));
@@ -1594,11 +1595,9 @@ name: test
1594
1595
headers: {'Content-Type' : 'application/json; charset=UTF-8' });
1595
1596
}
1596
1597
1597
- _MigrationCli _createCli ({ bool injectArtificialException = false } ) {
1598
+ _MigrationCli _createCli () {
1598
1599
mock_sdk.MockSdk (resourceProvider: resourceProvider);
1599
- return _MigrationCli (this ,
1600
- injectArtificialException: injectArtificialException,
1601
- environmentVariables: environmentVariables);
1600
+ return _MigrationCli (this );
1602
1601
}
1603
1602
1604
1603
String _getHelpText ({@required bool verbose}) {
0 commit comments