Unverified Commit b7214a9a authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] fix null check in crash reporter (#80382)

parent ce3c3d2a
...@@ -28,9 +28,6 @@ class BotDetector { ...@@ -28,9 +28,6 @@ class BotDetector {
final PersistentToolState _persistentToolState; final PersistentToolState _persistentToolState;
Future<bool> get isRunningOnBot async { Future<bool> get isRunningOnBot async {
if (_persistentToolState.isRunningOnBot != null) {
return _persistentToolState.isRunningOnBot!;
}
if ( if (
// Explicitly stated to not be a bot. // Explicitly stated to not be a bot.
_platform.environment['BOT'] == 'false' _platform.environment['BOT'] == 'false'
...@@ -43,6 +40,10 @@ class BotDetector { ...@@ -43,6 +40,10 @@ class BotDetector {
return _persistentToolState.runningOnBot = false; return _persistentToolState.runningOnBot = false;
} }
if (_persistentToolState.isRunningOnBot != null) {
return _persistentToolState.isRunningOnBot!;
}
return _persistentToolState.runningOnBot = _platform.environment['BOT'] == 'true' return _persistentToolState.runningOnBot = _platform.environment['BOT'] == 'true'
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables // https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
......
...@@ -125,6 +125,12 @@ class UpdatePackagesCommand extends FlutterCommand { ...@@ -125,6 +125,12 @@ class UpdatePackagesCommand extends FlutterCommand {
help: 'Use cached packages instead of accessing the network.', help: 'Use cached packages instead of accessing the network.',
defaultsTo: false, defaultsTo: false,
negatable: false, negatable: false,
)
..addFlag(
'crash',
help: 'For Flutter CLI testing only, forces this command to throw an unhandled exception.',
defaultsTo: false,
negatable: false,
); );
} }
...@@ -179,6 +185,11 @@ class UpdatePackagesCommand extends FlutterCommand { ...@@ -179,6 +185,11 @@ class UpdatePackagesCommand extends FlutterCommand {
final bool isVerifyOnly = boolArg('verify-only'); final bool isVerifyOnly = boolArg('verify-only');
final bool isConsumerOnly = boolArg('consumer-only'); final bool isConsumerOnly = boolArg('consumer-only');
final bool offline = boolArg('offline'); final bool offline = boolArg('offline');
final bool crash = boolArg('crash');
if (crash) {
throw StateError('test crash please ignore.');
}
if (upgrade && offline) { if (upgrade && offline) {
throwToolExit( throwToolExit(
......
...@@ -29,7 +29,7 @@ import 'version.dart'; ...@@ -29,7 +29,7 @@ import 'version.dart';
Cache get cache => context.get<Cache>()!; Cache get cache => context.get<Cache>()!;
Config get config => context.get<Config>()!; Config get config => context.get<Config>()!;
HttpClientFactory get httpClientFactory => context.get<HttpClientFactory>()!; HttpClientFactory? get httpClientFactory => context.get<HttpClientFactory>();
Logger get logger => context.get<Logger>()!; Logger get logger => context.get<Logger>()!;
OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!; OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!;
Signals get signals => context.get<Signals>() ?? LocalSignals.instance; Signals get signals => context.get<Signals>() ?? LocalSignals.instance;
......
...@@ -45,6 +45,24 @@ void main() { ...@@ -45,6 +45,24 @@ void main() {
expect(persistentToolState.isRunningOnBot, isFalse); expect(persistentToolState.isRunningOnBot, isFalse);
}); });
testWithoutContext('does not cache BOT environment variable', () async {
fakePlatform.environment['BOT'] = 'true';
final BotDetector botDetector = BotDetector(
platform: fakePlatform,
httpClientFactory: () => FakeHttpClient.any(),
persistentToolState: persistentToolState,
);
expect(await botDetector.isRunningOnBot, isTrue);
expect(persistentToolState.isRunningOnBot, isTrue);
fakePlatform.environment['BOT'] = 'false';
expect(await botDetector.isRunningOnBot, isFalse);
expect(persistentToolState.isRunningOnBot, isFalse);
});
testWithoutContext('returns false unconditionally if FLUTTER_HOST is set', () async { testWithoutContext('returns false unconditionally if FLUTTER_HOST is set', () async {
fakePlatform.environment['FLUTTER_HOST'] = 'foo'; fakePlatform.environment['FLUTTER_HOST'] = 'foo';
fakePlatform.environment['TRAVIS'] = 'true'; fakePlatform.environment['TRAVIS'] = 'true';
......
...@@ -221,4 +221,22 @@ void main() { ...@@ -221,4 +221,22 @@ void main() {
expect(result.exitCode, isNot(0)); expect(result.exitCode, isNot(0));
expect(result.stderr, contains('Could not find an option named "release"')); expect(result.stderr, contains('Could not find an option named "release"'));
}); });
testWithoutContext('flutter can report crashes', () async {
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await processManager.run(<String>[
flutterBin,
...getLocalEngineArguments(),
'update-packages',
'--crash',
], environment: <String, String>{
'BOT': 'false',
});
expect(result.exitCode, isNot(0));
expect(result.stderr, contains(
'Oops; flutter has exited unexpectedly: "Bad state: test crash please ignore.".\n'
'A crash report has been written to',
));
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment