Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2f43aeaf
Unverified
Commit
2f43aeaf
authored
Jul 02, 2020
by
Jonah Williams
Committed by
GitHub
Jul 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] fix crash if grouped doctor validator crashes (#60658)
parent
84fc52e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
2 deletions
+76
-2
events.dart
packages/flutter_tools/lib/src/reporting/events.dart
+8
-2
events_test.dart
...utter_tools/test/general.shard/reporting/events_test.dart
+68
-0
No files found.
packages/flutter_tools/lib/src/reporting/events.dart
View file @
2f43aeaf
...
...
@@ -103,11 +103,12 @@ class DoctorResultEvent extends UsageEvent {
DoctorResultEvent
({
@required
this
.
validator
,
@required
this
.
result
,
Usage
flutterUsage
,
})
:
super
(
'doctor-result'
,
'
${validator.runtimeType}
'
,
label:
result
.
typeStr
,
flutterUsage:
globals
.
flutterUsage
,
flutterUsage:
flutterUsage
??
globals
.
flutterUsage
,
);
final
DoctorValidator
validator
;
...
...
@@ -120,10 +121,15 @@ class DoctorResultEvent extends UsageEvent {
return
;
}
final
GroupedValidator
group
=
validator
as
GroupedValidator
;
// The validator crashed.
if
(
group
.
subResults
==
null
)
{
flutterUsage
.
sendEvent
(
category
,
parameter
,
label:
label
);
return
;
}
for
(
int
i
=
0
;
i
<
group
.
subValidators
.
length
;
i
++)
{
final
DoctorValidator
v
=
group
.
subValidators
[
i
];
final
ValidationResult
r
=
group
.
subResults
[
i
];
DoctorResultEvent
(
validator:
v
,
result:
r
).
send
();
DoctorResultEvent
(
validator:
v
,
result:
r
,
flutterUsage:
flutterUsage
).
send
();
}
}
}
...
...
packages/flutter_tools/test/general.shard/reporting/events_test.dart
0 → 100644
View file @
2f43aeaf
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter_tools/src/doctor.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../../src/common.dart'
;
void
main
(
)
{
testWithoutContext
(
'DoctorResultEvent sends usage event for each sub validator'
,
()
async
{
final
Usage
usage
=
MockUsage
();
final
GroupedValidator
groupedValidator
=
FakeGroupedValidator
(<
DoctorValidator
>[
FakeDoctorValidator
(
'a'
),
FakeDoctorValidator
(
'b'
),
FakeDoctorValidator
(
'c'
),
]);
final
ValidationResult
result
=
await
groupedValidator
.
validate
();
final
DoctorResultEvent
doctorResultEvent
=
DoctorResultEvent
(
validator:
groupedValidator
,
result:
result
,
flutterUsage:
usage
,
);
expect
(()
=>
doctorResultEvent
.
send
(),
returnsNormally
);
verify
(
usage
.
sendEvent
(
'doctor-result'
,
any
,
label:
anyNamed
(
'label'
))).
called
(
3
);
});
testWithoutContext
(
'DoctorResultEvent does not crash if a synthetic crash result was used instead'
' of validation. This happens when a grouped validator throws an exception, causing subResults to never '
' be instantiated.'
,
()
async
{
final
Usage
usage
=
MockUsage
();
final
GroupedValidator
groupedValidator
=
FakeGroupedValidator
(<
DoctorValidator
>[
FakeDoctorValidator
(
'a'
),
FakeDoctorValidator
(
'b'
),
FakeDoctorValidator
(
'c'
),
]);
final
ValidationResult
result
=
ValidationResult
.
crash
(
Object
());
final
DoctorResultEvent
doctorResultEvent
=
DoctorResultEvent
(
validator:
groupedValidator
,
result:
result
,
flutterUsage:
usage
,
);
expect
(()
=>
doctorResultEvent
.
send
(),
returnsNormally
);
verify
(
usage
.
sendEvent
(
'doctor-result'
,
any
,
label:
anyNamed
(
'label'
))).
called
(
1
);
});
}
class
FakeGroupedValidator
extends
GroupedValidator
{
FakeGroupedValidator
(
List
<
DoctorValidator
>
subValidators
)
:
super
(
subValidators
);
}
class
FakeDoctorValidator
extends
DoctorValidator
{
FakeDoctorValidator
(
String
title
)
:
super
(
title
);
@override
Future
<
ValidationResult
>
validate
()
async
{
return
ValidationResult
.
crash
(
Object
());
}
}
class
MockUsage
extends
Mock
implements
Usage
{}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment