Commit 31b95837 authored by xster's avatar xster Committed by GitHub

Report flutter doctor success/failure (#9664)

* record doctor failures

* fully mock out analytics dependencies
parent c74225e0
...@@ -15,7 +15,8 @@ class DoctorCommand extends FlutterCommand { ...@@ -15,7 +15,8 @@ class DoctorCommand extends FlutterCommand {
final String description = 'Show information about the installed tooling.'; final String description = 'Show information about the installed tooling.';
@override @override
Future<Null> runCommand() async { Future<FlutterCommandResult> runCommand() async {
await doctor.diagnose(); final bool success = await doctor.diagnose();
return new FlutterCommandResult(success ? ExitStatus.success : ExitStatus.warning);
} }
} }
...@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/cache.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart'; import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/commands/config.dart'; import 'package:flutter_tools/src/commands/config.dart';
import 'package:flutter_tools/src/commands/doctor.dart'; import 'package:flutter_tools/src/commands/doctor.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/usage.dart'; import 'package:flutter_tools/src/usage.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:quiver/time.dart'; import 'package:quiver/time.dart';
...@@ -80,12 +81,14 @@ void main() { ...@@ -80,12 +81,14 @@ void main() {
group('analytics with mocks', () { group('analytics with mocks', () {
Usage mockUsage; Usage mockUsage;
Clock mockClock; Clock mockClock;
Doctor mockDoctor;
List<int> mockTimes; List<int> mockTimes;
setUp(() { setUp(() {
mockUsage = new MockUsage(); mockUsage = new MockUsage();
when(mockUsage.isFirstRun).thenReturn(false); when(mockUsage.isFirstRun).thenReturn(false);
mockClock = new MockClock(); mockClock = new MockClock();
mockDoctor = new MockDoctor();
when(mockClock.now()).thenAnswer( when(mockClock.now()).thenAnswer(
(Invocation _) => new DateTime.fromMillisecondsSinceEpoch(mockTimes.removeAt(0)) (Invocation _) => new DateTime.fromMillisecondsSinceEpoch(mockTimes.removeAt(0))
); );
...@@ -93,6 +96,7 @@ void main() { ...@@ -93,6 +96,7 @@ void main() {
testUsingContext('flutter commands send timing events', () async { testUsingContext('flutter commands send timing events', () async {
mockTimes = <int>[1000, 2000]; mockTimes = <int>[1000, 2000];
when(mockDoctor.diagnose()).thenReturn(true);
final DoctorCommand command = new DoctorCommand(); final DoctorCommand command = new DoctorCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command); final CommandRunner<Null> runner = createTestCommandRunner(command);
await runner.run(<String>['doctor']); await runner.run(<String>['doctor']);
...@@ -101,10 +105,30 @@ void main() { ...@@ -101,10 +105,30 @@ void main() {
expect( expect(
verify(mockUsage.sendTiming(captureAny, captureAny, captureAny, label: captureAny)).captured, verify(mockUsage.sendTiming(captureAny, captureAny, captureAny, label: captureAny)).captured,
<dynamic>['flutter', 'doctor', const Duration(milliseconds: 1000), null] <dynamic>['flutter', 'doctor', const Duration(milliseconds: 1000), 'success']
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Clock: () => mockClock, Clock: () => mockClock,
Doctor: () => mockDoctor,
Usage: () => mockUsage,
});
testUsingContext('doctor fail sends warning', () async {
mockTimes = <int>[1000, 2000];
when(mockDoctor.diagnose()).thenReturn(false);
final DoctorCommand command = new DoctorCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command);
await runner.run(<String>['doctor']);
verify(mockClock.now()).called(2);
expect(
verify(mockUsage.sendTiming(captureAny, captureAny, captureAny, label: captureAny)).captured,
<dynamic>['flutter', 'doctor', const Duration(milliseconds: 1000), 'warning']
);
}, overrides: <Type, Generator>{
Clock: () => mockClock,
Doctor: () => mockDoctor,
Usage: () => mockUsage, Usage: () => mockUsage,
}); });
}); });
...@@ -126,3 +150,5 @@ void main() { ...@@ -126,3 +150,5 @@ void main() {
} }
class MockUsage extends Mock implements Usage {} class MockUsage extends Mock implements Usage {}
class MockDoctor extends Mock implements Doctor {}
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