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
e53c4896
Unverified
Commit
e53c4896
authored
Jan 29, 2021
by
Jonah Williams
Committed by
GitHub
Jan 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mock SystemClock (#74994)
parent
8db51f66
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
52 deletions
+56
-52
analytics_test.dart
...ages/flutter_tools/test/general.shard/analytics_test.dart
+19
-17
plugins_test.dart
packages/flutter_tools/test/general.shard/plugins_test.dart
+16
-11
flutter_command_test.dart
...tools/test/general.shard/runner/flutter_command_test.dart
+21
-21
context.dart
packages/flutter_tools/test/src/context.dart
+0
-3
No files found.
packages/flutter_tools/test/general.shard/analytics_test.dart
View file @
e53c4896
...
...
@@ -154,23 +154,19 @@ void main() {
MemoryFileSystem
memoryFileSystem
;
MockStdio
mockStdio
;
TestUsage
testUsage
;
SystemClock
mock
Clock
;
FakeClock
fake
Clock
;
Doctor
mockDoctor
;
List
<
int
>
mockTimes
;
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
.
test
();
mockStdio
=
MockStdio
();
testUsage
=
TestUsage
();
mockClock
=
Mock
Clock
();
fakeClock
=
Fake
Clock
();
mockDoctor
=
MockDoctor
();
when
(
mockClock
.
now
()).
thenAnswer
(
(
Invocation
_
)
=>
DateTime
.
fromMillisecondsSinceEpoch
(
mockTimes
.
removeAt
(
0
))
);
});
testUsingContext
(
'flutter commands send timing events'
,
()
async
{
mockT
imes
=
<
int
>[
1000
,
2000
];
fakeClock
.
t
imes
=
<
int
>[
1000
,
2000
];
when
(
mockDoctor
.
diagnose
(
androidLicenses:
false
,
verbose:
false
,
...
...
@@ -180,28 +176,25 @@ void main() {
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'doctor'
]);
verify
(
mockClock
.
now
()).
called
(
2
);
expect
(
testUsage
.
timings
,
contains
(
const
TestTimingEvent
(
'flutter'
,
'doctor'
,
Duration
(
milliseconds:
1000
),
label:
'success'
,
),
));
},
overrides:
<
Type
,
Generator
>{
SystemClock:
()
=>
mock
Clock
,
SystemClock:
()
=>
fake
Clock
,
Doctor:
()
=>
mockDoctor
,
Usage:
()
=>
testUsage
,
});
testUsingContext
(
'doctor fail sends warning'
,
()
async
{
mockT
imes
=
<
int
>[
1000
,
2000
];
fakeClock
.
t
imes
=
<
int
>[
1000
,
2000
];
when
(
mockDoctor
.
diagnose
(
androidLicenses:
false
,
verbose:
false
,
androidLicenseValidator:
anyNamed
(
'androidLicenseValidator'
)))
.
thenAnswer
((
_
)
async
=>
false
);
final
DoctorCommand
command
=
DoctorCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'doctor'
]);
verify
(
mockClock
.
now
()).
called
(
2
);
expect
(
testUsage
.
timings
,
contains
(
const
TestTimingEvent
(
...
...
@@ -209,7 +202,7 @@ void main() {
),
));
},
overrides:
<
Type
,
Generator
>{
SystemClock:
()
=>
mock
Clock
,
SystemClock:
()
=>
fake
Clock
,
Doctor:
()
=>
mockDoctor
,
Usage:
()
=>
testUsage
,
});
...
...
@@ -233,7 +226,7 @@ void main() {
testUsingContext
(
'command sends localtime'
,
()
async
{
const
int
kMillis
=
1000
;
mockT
imes
=
<
int
>[
kMillis
];
fakeClock
.
t
imes
=
<
int
>[
kMillis
];
// Since FLUTTER_ANALYTICS_LOG_FILE is set in the environment, analytics
// will be written to a file.
final
Usage
usage
=
Usage
(
...
...
@@ -252,7 +245,7 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
SystemClock:
()
=>
mock
Clock
,
SystemClock:
()
=>
fake
Clock
,
Platform:
()
=>
FakePlatform
(
environment:
<
String
,
String
>{
'FLUTTER_ANALYTICS_LOG_FILE'
:
'analytics.log'
,
...
...
@@ -263,7 +256,7 @@ void main() {
testUsingContext
(
'event sends localtime'
,
()
async
{
const
int
kMillis
=
1000
;
mockT
imes
=
<
int
>[
kMillis
];
fakeClock
.
t
imes
=
<
int
>[
kMillis
];
// Since FLUTTER_ANALYTICS_LOG_FILE is set in the environment, analytics
// will be written to a file.
final
Usage
usage
=
Usage
(
...
...
@@ -282,7 +275,7 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
SystemClock:
()
=>
mock
Clock
,
SystemClock:
()
=>
fake
Clock
,
Platform:
()
=>
FakePlatform
(
environment:
<
String
,
String
>{
'FLUTTER_ANALYTICS_LOG_FILE'
:
'analytics.log'
,
...
...
@@ -378,3 +371,12 @@ class FakeFlutterCommand extends FlutterCommand {
class
MockDoctor
extends
Mock
implements
Doctor
{}
class
MockFlutterConfig
extends
Mock
implements
Config
{}
class
FakeClock
extends
Fake
implements
SystemClock
{
List
<
int
>
times
=
<
int
>[];
@override
DateTime
now
()
{
return
DateTime
.
fromMillisecondsSinceEpoch
(
times
.
removeAt
(
0
));
}
}
packages/flutter_tools/test/general.shard/plugins_test.dart
View file @
e53c4896
...
...
@@ -37,7 +37,7 @@ void main() {
MockWebProject
webProject
;
MockWindowsProject
windowsProject
;
MockLinuxProject
linuxProject
;
SystemClock
mock
Clock
;
FakeSystemClock
system
Clock
;
FlutterVersion
mockVersion
;
// A Windows-style filesystem. This is not populated by default, so tests
// using it instead of fs must re-run any necessary setup (e.g.,
...
...
@@ -112,16 +112,14 @@ void main() {
setUp
(()
async
{
fs
=
MemoryFileSystem
.
test
();
fsWindows
=
MemoryFileSystem
(
style:
FileSystemStyle
.
windows
);
mockClock
=
MockClock
();
systemClock
=
FakeSystemClock
()
..
currentTime
=
DateTime
(
1970
,
1
,
1
);
mockVersion
=
MockFlutterVersion
();
// Add basic properties to the Flutter project and subprojects
setUpProject
(
fs
);
flutterProject
.
directory
.
childFile
(
'.packages'
).
createSync
(
recursive:
true
);
when
(
mockClock
.
now
()).
thenAnswer
(
(
Invocation
_
)
=>
DateTime
(
1970
,
1
,
1
)
);
when
(
mockVersion
.
frameworkVersion
).
thenAnswer
(
(
Invocation
_
)
=>
'1.0.0'
);
...
...
@@ -425,9 +423,7 @@ dependencies:
when
(
iosProject
.
existsSync
()).
thenReturn
(
true
);
final
DateTime
dateCreated
=
DateTime
(
1970
,
1
,
1
);
when
(
mockClock
.
now
()).
thenAnswer
(
(
Invocation
_
)
=>
dateCreated
);
systemClock
.
currentTime
=
dateCreated
;
const
String
version
=
'1.0.0'
;
when
(
mockVersion
.
frameworkVersion
).
thenAnswer
(
(
Invocation
_
)
=>
version
...
...
@@ -516,7 +512,7 @@ dependencies:
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
SystemClock:
()
=>
mock
Clock
,
SystemClock:
()
=>
system
Clock
,
FlutterVersion:
()
=>
mockVersion
});
...
...
@@ -533,7 +529,7 @@ dependencies:
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
SystemClock:
()
=>
mock
Clock
,
SystemClock:
()
=>
system
Clock
,
FlutterVersion:
()
=>
mockVersion
});
...
...
@@ -556,7 +552,7 @@ dependencies:
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
SystemClock:
()
=>
mock
Clock
,
SystemClock:
()
=>
system
Clock
,
FlutterVersion:
()
=>
mockVersion
});
});
...
...
@@ -1410,3 +1406,12 @@ class MockWebProject extends Mock implements WebProject {}
class
MockWindowsProject
extends
Mock
implements
WindowsProject
{}
class
MockLinuxProject
extends
Mock
implements
LinuxProject
{}
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{}
class
FakeSystemClock
extends
Fake
implements
SystemClock
{
DateTime
currentTime
;
@override
DateTime
now
()
{
return
currentTime
;
}
}
\ No newline at end of file
packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart
View file @
e53c4896
...
...
@@ -31,20 +31,16 @@ void main() {
group
(
'Flutter Command'
,
()
{
MockitoCache
cache
;
MockitoUsage
usage
;
Mock
Clock
clock
;
Fake
Clock
clock
;
MockProcessInfo
mockProcessInfo
;
List
<
int
>
mockTimes
;
setUp
(()
{
Cache
.
disableLocking
();
cache
=
MockitoCache
();
usage
=
MockitoUsage
();
clock
=
Mock
Clock
();
clock
=
Fake
Clock
();
mockProcessInfo
=
MockProcessInfo
();
when
(
clock
.
now
()).
thenAnswer
(
(
Invocation
_
)
=>
DateTime
.
fromMillisecondsSinceEpoch
(
mockTimes
.
removeAt
(
0
))
);
when
(
mockProcessInfo
.
maxRss
).
thenReturn
(
10
);
});
...
...
@@ -154,7 +150,7 @@ void main() {
testUsingCommandContext
(
'reports command that results in success'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
(
commandFunction:
()
async
{
...
...
@@ -185,7 +181,7 @@ void main() {
testUsingCommandContext
(
'reports command that results in warning'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
(
commandFunction:
()
async
{
...
...
@@ -216,7 +212,7 @@ void main() {
testUsingCommandContext
(
'reports command that results in failure'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
(
commandFunction:
()
async
{
...
...
@@ -250,7 +246,7 @@ void main() {
testUsingCommandContext
(
'reports command that results in error'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
(
commandFunction:
()
async
{
...
...
@@ -348,7 +344,7 @@ void main() {
testUsingContext
(
'reports command that is killed'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
Completer
<
void
>
completer
=
Completer
<
void
>();
setExitFunctionForTests
((
int
exitCode
)
{
...
...
@@ -398,7 +394,7 @@ void main() {
});
testUsingContext
(
'command release lock on kill signal'
,
()
async
{
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
Completer
<
void
>
completer
=
Completer
<
void
>();
setExitFunctionForTests
((
int
exitCode
)
{
expect
(
exitCode
,
0
);
...
...
@@ -437,11 +433,10 @@ void main() {
testUsingCommandContext
(
'report execution timing by default'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
();
await
flutterCommand
.
run
();
verify
(
clock
.
now
()).
called
(
2
);
expect
(
verify
(
usage
.
sendTiming
(
...
...
@@ -458,12 +453,11 @@ void main() {
testUsingCommandContext
(
'no timing report without usagePath'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
(
noUsagePath:
true
);
await
flutterCommand
.
run
();
verify
(
clock
.
now
()).
called
(
2
);
verifyNever
(
usage
.
sendTiming
(
any
,
any
,
any
,
label:
anyNamed
(
'label'
)));
...
...
@@ -471,7 +465,7 @@ void main() {
testUsingCommandContext
(
'report additional FlutterCommandResult data'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
FlutterCommandResult
commandResult
=
FlutterCommandResult
(
ExitStatus
.
success
,
...
...
@@ -484,7 +478,6 @@ void main() {
commandFunction:
()
async
=>
commandResult
);
await
flutterCommand
.
run
();
verify
(
clock
.
now
()).
called
(
2
);
expect
(
verify
(
usage
.
sendTiming
(
captureAny
,
captureAny
,
captureAny
,
...
...
@@ -500,7 +493,7 @@ void main() {
testUsingCommandContext
(
'report failed execution timing too'
,
()
async
{
// Crash if called a third time which is unexpected.
mockT
imes
=
<
int
>[
1000
,
2000
];
clock
.
t
imes
=
<
int
>[
1000
,
2000
];
final
DummyFlutterCommand
flutterCommand
=
DummyFlutterCommand
(
commandFunction:
()
async
{
...
...
@@ -513,8 +506,6 @@ void main() {
await
flutterCommand
.
run
();
fail
(
'Mock should make this fail'
);
}
on
ToolExit
{
// Should have still checked time twice.
verify
(
clock
.
now
()).
called
(
2
);
expect
(
verify
(
usage
.
sendTiming
(
...
...
@@ -694,3 +685,12 @@ class FakePub extends Fake implements Pub {
bool
checkUpToDate
=
false
,
})
async
{
}
}
class
FakeClock
extends
Fake
implements
SystemClock
{
List
<
int
>
times
=
<
int
>[];
@override
DateTime
now
()
{
return
DateTime
.
fromMillisecondsSinceEpoch
(
times
.
removeAt
(
0
));
}
}
packages/flutter_tools/test/src/context.dart
View file @
e53c4896
...
...
@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/base/process.dart';
import
'package:flutter_tools/src/base/signals.dart'
;
import
'package:flutter_tools/src/base/template.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/base/time.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/isolated/mustache_template.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
...
...
@@ -421,8 +420,6 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter {
class
MockFlutterVersion
extends
Mock
implements
FlutterVersion
{}
class
MockClock
extends
Mock
implements
SystemClock
{}
class
MockHttpClient
extends
Mock
implements
HttpClient
{}
class
MockCrashReporter
extends
Mock
implements
CrashReporter
{}
...
...
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