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
4436334f
Unverified
Commit
4436334f
authored
Feb 18, 2021
by
Jenn Magder
Committed by
GitHub
Feb 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adopt TestUsage in flutter_command_test (#76282)
parent
04182572
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
109 deletions
+84
-109
flutter_command_test.dart
...tools/test/general.shard/runner/flutter_command_test.dart
+84
-102
utils.dart
packages/flutter_tools/test/general.shard/runner/utils.dart
+0
-7
No files found.
packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart
View file @
4436334f
...
...
@@ -30,15 +30,15 @@ import 'utils.dart';
void
main
(
)
{
group
(
'Flutter Command'
,
()
{
Mock
ito
Cache
cache
;
Mockito
Usage
usage
;
MockCache
cache
;
Test
Usage
usage
;
FakeClock
clock
;
MockProcessInfo
mockProcessInfo
;
setUp
(()
{
Cache
.
disableLocking
();
cache
=
Mock
ito
Cache
();
usage
=
Mockito
Usage
();
cache
=
MockCache
();
usage
=
Test
Usage
();
clock
=
FakeClock
();
mockProcessInfo
=
MockProcessInfo
();
...
...
@@ -160,24 +160,19 @@ void main() {
);
await
flutterCommand
.
run
();
verify
(
usage
.
sendCommand
(
'dummy'
,
parameters:
anyNamed
(
'parameters'
),
));
verify
(
usage
.
sendEvent
(
'tool-command-result'
,
'dummy'
,
label:
'success'
,
parameters:
anyNamed
(
'parameters'
),
));
expect
(
verify
(
usage
.
sendEvent
(
expect
(
usage
.
events
,
<
TestUsageEvent
>[
const
TestUsageEvent
(
'tool-command-result'
,
'dummy'
,
label:
'success'
,
),
const
TestUsageEvent
(
'tool-command-max-rss'
,
'dummy'
,
label:
'success'
,
value:
captureAnyNamed
(
'value'
),
)).
captured
[
0
],
10
,
);
value:
10
,
),
]);
});
testUsingCommandContext
(
'reports command that results in warning'
,
()
async
{
...
...
@@ -191,24 +186,19 @@ void main() {
);
await
flutterCommand
.
run
();
verify
(
usage
.
sendCommand
(
'dummy'
,
parameters:
anyNamed
(
'parameters'
),
));
verify
(
usage
.
sendEvent
(
'tool-command-result'
,
'dummy'
,
label:
'warning'
,
parameters:
anyNamed
(
'parameters'
),
));
expect
(
verify
(
usage
.
sendEvent
(
expect
(
usage
.
events
,
<
TestUsageEvent
>[
const
TestUsageEvent
(
'tool-command-result'
,
'dummy'
,
label:
'warning'
,
),
const
TestUsageEvent
(
'tool-command-max-rss'
,
'dummy'
,
label:
'warning'
,
value:
captureAnyNamed
(
'value'
),
)).
captured
[
0
],
10
,
);
value:
10
,
),
]);
});
testUsingCommandContext
(
'reports command that results in failure'
,
()
async
{
...
...
@@ -255,29 +245,23 @@ void main() {
return
null
;
// unreachable
}
);
try
{
await
flutterCommand
.
run
();
fail
(
'Mock should make this fail'
);
}
on
ToolExit
{
verify
(
usage
.
sendCommand
(
'dummy'
,
parameters:
anyNamed
(
'parameters'
),
));
verify
(
usage
.
sendEvent
(
'tool-command-result'
,
'dummy'
,
label:
'fail'
,
parameters:
anyNamed
(
'parameters'
),
));
expect
(
verify
(
usage
.
sendEvent
(
expect
(
usage
.
events
,
<
TestUsageEvent
>[
const
TestUsageEvent
(
'tool-command-result'
,
'dummy'
,
label:
'fail'
,
),
const
TestUsageEvent
(
'tool-command-max-rss'
,
'dummy'
,
label:
'fail'
,
value:
captureAnyNamed
(
'value'
),
)).
captured
[
0
],
10
,
);
value:
10
,
),
]);
}
});
...
...
@@ -366,24 +350,19 @@ void main() {
signalController
.
add
(
mockSignal
);
await
completer
.
future
;
verify
(
usage
.
sendCommand
(
'dummy'
,
parameters:
anyNamed
(
'parameters'
),
));
verify
(
usage
.
sendEvent
(
'tool-command-result'
,
'dummy'
,
label:
'killed'
,
parameters:
anyNamed
(
'parameters'
),
));
expect
(
verify
(
usage
.
sendEvent
(
expect
(
usage
.
events
,
<
TestUsageEvent
>[
const
TestUsageEvent
(
'tool-command-result'
,
'dummy'
,
label:
'killed'
,
),
const
TestUsageEvent
(
'tool-command-max-rss'
,
'dummy'
,
label:
'killed'
,
value:
captureAnyNamed
(
'value'
),
)).
captured
[
0
],
10
,
);
value:
10
,
),
]);
},
overrides:
<
Type
,
Generator
>{
ProcessInfo:
()
=>
mockProcessInfo
,
Signals:
()
=>
FakeSignals
(
...
...
@@ -439,17 +418,13 @@ void main() {
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
();
await
flutterCommand
.
run
();
expect
(
verify
(
usage
.
sendTiming
(
captureAny
,
captureAny
,
captureAny
,
label:
captureAnyNamed
(
'label'
))).
captured
,
<
dynamic
>[
expect
(
usage
.
timings
,
contains
(
const
TestTimingEvent
(
'flutter'
,
'dummy'
,
const
Duration
(
milliseconds:
1000
),
'fail'
,
],
);
Duration
(
milliseconds:
1000
),
label:
'fail'
,
)));
});
testUsingCommandContext
(
'no timing report without usagePath'
,
()
async
{
...
...
@@ -459,9 +434,8 @@ void main() {
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
(
noUsagePath:
true
);
await
flutterCommand
.
run
();
verifyNever
(
usage
.
sendTiming
(
any
,
any
,
any
,
label:
anyNamed
(
'label'
)));
expect
(
usage
.
timings
,
isEmpty
);
});
testUsingCommandContext
(
'report additional FlutterCommandResult data'
,
()
async
{
...
...
@@ -479,17 +453,14 @@ void main() {
commandFunction:
()
async
=>
commandResult
);
await
flutterCommand
.
run
();
expect
(
verify
(
usage
.
sendTiming
(
captureAny
,
captureAny
,
captureAny
,
label:
captureAnyNamed
(
'label'
))).
captured
,
<
dynamic
>[
expect
(
usage
.
timings
,
contains
(
const
TestTimingEvent
(
'flutter'
,
'dummy'
,
const
Duration
(
milliseconds:
500
),
// FlutterCommandResult's end time used instead.
'success-blah1-blah2-blah3'
,
],
);
Duration
(
milliseconds:
500
),
label:
'success-blah1-blah2-blah3'
,
)));
});
testUsingCommandContext
(
'report failed execution timing too'
,
()
async
{
...
...
@@ -507,18 +478,13 @@ void main() {
await
flutterCommand
.
run
();
fail
(
'Mock should make this fail'
);
}
on
ToolExit
{
expect
(
verify
(
usage
.
sendTiming
(
captureAny
,
captureAny
,
captureAny
,
label:
captureAnyNamed
(
'label'
))).
captured
,
<
dynamic
>[
expect
(
usage
.
timings
,
contains
(
const
TestTimingEvent
(
'flutter'
,
'dummy'
,
const
Duration
(
milliseconds:
1000
),
'fail'
,
],
);
Duration
(
milliseconds:
1000
),
label:
'fail'
,
)));
}
});
...
...
@@ -551,14 +517,28 @@ void main() {
await
runner
.
run
(<
String
>[
'test'
]);
verify
(
globals
.
flutterUsage
.
sendEvent
(
NullSafetyAnalysisEvent
.
kNullSafetyCategory
,
'runtime-mode'
,
label:
'NullSafetyMode.sound'
)).
called
(
1
);
verify
(
globals
.
flutterUsage
.
sendEvent
(
NullSafetyAnalysisEvent
.
kNullSafetyCategory
,
'stats'
,
parameters:
<
String
,
String
>{
'cd49'
:
'1'
,
'cd50'
:
'1'
,
})).
called
(
1
);
verify
(
globals
.
flutterUsage
.
sendEvent
(
NullSafetyAnalysisEvent
.
kNullSafetyCategory
,
'language-version'
,
label:
'2.12'
)).
called
(
1
);
expect
(
usage
.
events
,
containsAll
(<
TestUsageEvent
>[
const
TestUsageEvent
(
NullSafetyAnalysisEvent
.
kNullSafetyCategory
,
'runtime-mode'
,
label:
'NullSafetyMode.sound'
,
),
const
TestUsageEvent
(
NullSafetyAnalysisEvent
.
kNullSafetyCategory
,
'stats'
,
parameters:
<
String
,
String
>{
'cd49'
:
'1'
,
'cd50'
:
'1'
,
},
),
const
TestUsageEvent
(
NullSafetyAnalysisEvent
.
kNullSafetyCategory
,
'language-version'
,
label:
'2.12'
,
),
]));
},
overrides:
<
Type
,
Generator
>{
Pub:
()
=>
FakePub
(),
Usage:
()
=>
MockitoUsage
()
,
Usage:
()
=>
usage
,
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
...
...
@@ -681,3 +661,5 @@ class FakeClock extends Fake implements SystemClock {
return
DateTime
.
fromMillisecondsSinceEpoch
(
times
.
removeAt
(
0
));
}
}
class
MockCache
extends
Mock
implements
Cache
{}
packages/flutter_tools/test/general.shard/runner/utils.dart
View file @
4436334f
...
...
@@ -4,10 +4,7 @@
// @dart = 2.8
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:flutter_tools/src/runner/flutter_command.dart'
;
import
'package:mockito/mockito.dart'
;
typedef
CommandFunction
=
Future
<
FlutterCommandResult
>
Function
();
...
...
@@ -39,7 +36,3 @@ class DummyFlutterCommand extends FlutterCommand {
return
commandFunction
==
null
?
FlutterCommandResult
.
fail
()
:
await
commandFunction
();
}
}
class
MockitoCache
extends
Mock
implements
Cache
{}
class
MockitoUsage
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