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
f92ba2d2
Unverified
Commit
f92ba2d2
authored
Oct 08, 2020
by
Jenn Magder
Committed by
GitHub
Oct 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace MockUsage with Usage.test in build tests (#67670)
parent
41325b56
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
61 deletions
+64
-61
usage.dart
packages/flutter_tools/lib/src/reporting/usage.dart
+7
-4
build_linux_test.dart
..._tools/test/commands.shard/hermetic/build_linux_test.dart
+9
-8
build_macos_test.dart
..._tools/test/commands.shard/hermetic/build_macos_test.dart
+10
-8
build_windows_test.dart
...ools/test/commands.shard/hermetic/build_windows_test.dart
+8
-6
daemon_test.dart
...utter_tools/test/commands.shard/hermetic/daemon_test.dart
+3
-8
run_test.dart
.../flutter_tools/test/commands.shard/hermetic/run_test.dart
+15
-27
common.dart
packages/flutter_tools/test/src/common.dart
+12
-0
No files found.
packages/flutter_tools/lib/src/reporting/usage.dart
View file @
f92ba2d2
...
...
@@ -198,6 +198,7 @@ class _DefaultUsage implements Usage {
final
bool
usingLogFile
=
logFilePath
!=
null
&&
logFilePath
.
isNotEmpty
;
analyticsIOFactory
??=
_defaultAnalyticsIOFactory
;
_clock
=
globals
.
systemClock
;
if
(
// To support testing, only allow other signals to supress analytics
// when analytics are not being shunted to a file.
...
...
@@ -272,13 +273,15 @@ class _DefaultUsage implements Usage {
}
_DefaultUsage
.
test
()
:
_suppressAnalytics
=
true
,
_analytics
=
AnalyticsMock
();
_suppressAnalytics
=
false
,
_analytics
=
AnalyticsMock
(
true
),
_clock
=
SystemClock
.
fixed
(
DateTime
(
2020
,
10
,
8
));
Analytics
_analytics
;
bool
_printedWelcome
=
false
;
bool
_suppressAnalytics
=
false
;
SystemClock
_clock
;
@override
bool
get
isFirstRun
=>
_analytics
.
firstRun
;
...
...
@@ -310,7 +313,7 @@ class _DefaultUsage implements Usage {
final
Map
<
String
,
String
>
paramsWithLocalTime
=
<
String
,
String
>{
...?
parameters
,
cdKey
(
CustomDimensions
.
localTime
):
formatDateTime
(
globals
.
systemC
lock
.
now
()),
cdKey
(
CustomDimensions
.
localTime
):
formatDateTime
(
_c
lock
.
now
()),
};
_analytics
.
sendScreenView
(
command
,
parameters:
paramsWithLocalTime
);
}
...
...
@@ -329,7 +332,7 @@ class _DefaultUsage implements Usage {
final
Map
<
String
,
String
>
paramsWithLocalTime
=
<
String
,
String
>{
...?
parameters
,
cdKey
(
CustomDimensions
.
localTime
):
formatDateTime
(
globals
.
systemC
lock
.
now
()),
cdKey
(
CustomDimensions
.
localTime
):
formatDateTime
(
_c
lock
.
now
()),
};
_analytics
.
sendEvent
(
...
...
packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart
View file @
f92ba2d2
...
...
@@ -15,7 +15,6 @@ import 'package:flutter_tools/src/commands/build_linux.dart';
import
'package:flutter_tools/src/features.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
...
...
@@ -45,12 +44,12 @@ void main() {
FileSystem
fileSystem
;
ProcessManager
processManager
;
Mock
Usage
usage
;
Usage
usage
;
setUp
(()
{
fileSystem
=
MemoryFileSystem
.
test
();
Cache
.
flutterRoot
=
_kTestFlutterRoot
;
usage
=
MockUsage
();
usage
=
Usage
.
test
();
});
// Creates the mock files necessary to look like a Flutter project.
...
...
@@ -399,11 +398,15 @@ set(BINARY_NAME "fizz_bar")
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(
List
<
int
>.
filled
(
10000
,
0
));
await
createTestCommandRunner
(
command
).
run
(
// Capture Usage.test() events.
final
StringBuffer
buffer
=
await
capturedConsolePrint
(()
=>
createTestCommandRunner
(
command
).
run
(
const
<
String
>[
'build'
,
'linux'
,
'--no-pub'
,
'--analyze-size'
]
)
);
expect
(
testLogger
.
statusText
,
contains
(
'A summary of your Linux bundle analysis can be found at'
));
verify
(
usage
.
sendEvent
(
'code-size-analysis'
,
'linux'
)).
called
(
1
);
expect
(
buffer
.
toString
(),
contains
(
'event {category: code-size-analysis, action: linux, label: null, value: null, cd33:'
)
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
processManager
,
...
...
@@ -412,5 +415,3 @@ set(BINARY_NAME "fizz_bar")
Usage:
()
=>
usage
,
});
}
class
MockUsage
extends
Mock
implements
Usage
{}
packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart
View file @
f92ba2d2
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'package:args/command_runner.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
...
...
@@ -15,7 +17,6 @@ import 'package:flutter_tools/src/features.dart';
import
'package:flutter_tools/src/ios/xcodeproj.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
...
...
@@ -49,7 +50,7 @@ final Platform notMacosPlatform = FakePlatform(
void
main
(
)
{
FileSystem
fileSystem
;
Mock
Usage
usage
;
Usage
usage
;
setUpAll
(()
{
Cache
.
disableLocking
();
...
...
@@ -57,7 +58,7 @@ void main() {
setUp
(()
{
fileSystem
=
MemoryFileSystem
.
test
();
usage
=
MockUsage
();
usage
=
Usage
.
test
();
});
// Sets up the minimal mock project files necessary to look like a Flutter project.
...
...
@@ -329,12 +330,15 @@ void main() {
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(
List
<
int
>.
generate
(
10000
,
(
int
index
)
=>
0
));
await
createTestCommandRunner
(
command
).
run
(
// Capture Usage.test() events.
final
StringBuffer
buffer
=
await
capturedConsolePrint
(()
=>
createTestCommandRunner
(
command
).
run
(
const
<
String
>[
'build'
,
'macos'
,
'--no-pub'
,
'--analyze-size'
]
)
);
expect
(
testLogger
.
statusText
,
contains
(
'A summary of your macOS bundle analysis can be found at'
));
verify
(
usage
.
sendEvent
(
'code-size-analysis'
,
'macos'
)).
called
(
1
);
expect
(
buffer
.
toString
(),
contains
(
'event {category: code-size-analysis, action: macos, label: null, value: null, cd33:'
)
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
list
(<
FakeCommand
>[
...
...
@@ -360,5 +364,3 @@ void main() {
Usage:
()
=>
usage
,
});
}
class
MockUsage
extends
Mock
implements
Usage
{}
packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart
View file @
f92ba2d2
...
...
@@ -43,7 +43,7 @@ void main() {
ProcessManager
processManager
;
MockVisualStudio
mockVisualStudio
;
Mock
Usage
usage
;
Usage
usage
;
setUpAll
(()
{
Cache
.
disableLocking
();
...
...
@@ -53,7 +53,7 @@ void main() {
fileSystem
=
MemoryFileSystem
.
test
(
style:
FileSystemStyle
.
windows
);
Cache
.
flutterRoot
=
flutterRoot
;
mockVisualStudio
=
MockVisualStudio
();
usage
=
MockUsage
();
usage
=
Usage
.
test
();
});
// Creates the mock files necessary to look like a Flutter project.
...
...
@@ -403,12 +403,15 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
}),
]);
await
createTestCommandRunner
(
command
).
run
(
// Capture Usage.test() events.
final
StringBuffer
buffer
=
await
capturedConsolePrint
(()
=>
createTestCommandRunner
(
command
).
run
(
const
<
String
>[
'windows'
,
'--no-pub'
,
'--analyze-size'
]
)
);
expect
(
testLogger
.
statusText
,
contains
(
'A summary of your Windows bundle analysis can be found at'
));
verify
(
usage
.
sendEvent
(
'code-size-analysis'
,
'windows'
)).
called
(
1
);
expect
(
buffer
.
toString
(),
contains
(
'event {category: code-size-analysis, action: windows, label: null, value: null, cd33:'
)
);
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWindowsEnabled:
true
),
FileSystem:
()
=>
fileSystem
,
...
...
@@ -420,4 +423,3 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
}
class
MockVisualStudio
extends
Mock
implements
VisualStudio
{}
class
MockUsage
extends
Mock
implements
Usage
{}
packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart
View file @
f92ba2d2
...
...
@@ -81,9 +81,7 @@ void main() {
});
testUsingContext
(
'printStatus should log to stdout when logToStdout is enabled'
,
()
async
{
final
StringBuffer
buffer
=
StringBuffer
();
await
runZoned
<
Future
<
void
>>(()
async
{
final
StringBuffer
buffer
=
await
capturedConsolePrint
(()
{
final
StreamController
<
Map
<
String
,
dynamic
>>
commands
=
StreamController
<
Map
<
String
,
dynamic
>>();
final
StreamController
<
Map
<
String
,
dynamic
>>
responses
=
StreamController
<
Map
<
String
,
dynamic
>>();
daemon
=
Daemon
(
...
...
@@ -93,11 +91,8 @@ void main() {
logToStdout:
true
,
);
globals
.
printStatus
(
'daemon.logMessage test'
);
// Service the event loop.
await
Future
<
void
>.
value
();
},
zoneSpecification:
ZoneSpecification
(
print:
(
Zone
self
,
ZoneDelegate
parent
,
Zone
zone
,
String
line
)
{
buffer
.
writeln
(
line
);
}));
return
Future
<
void
>.
value
();
});
expect
(
buffer
.
toString
().
trim
(),
'daemon.logMessage test'
);
},
overrides:
<
Type
,
Generator
>{
...
...
packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
View file @
f92ba2d2
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'package:file/file.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/application_package.dart'
;
...
...
@@ -143,13 +145,13 @@ void main() {
Artifacts
artifacts
;
MockCache
mockCache
;
MockProcessManager
mockProcessManager
;
MockUsage
mockU
sage
;
Usage
u
sage
;
Directory
tempDir
;
setUp
(()
{
artifacts
=
Artifacts
.
test
();
mockCache
=
MockCache
();
mockUsage
=
MockUsage
();
usage
=
Usage
.
test
();
fs
=
MemoryFileSystem
.
test
();
mockProcessManager
=
MockProcessManager
();
...
...
@@ -374,33 +376,19 @@ void main() {
..
writeAsStringSync
(
'# Hello, World'
);
globals
.
fs
.
currentDirectory
=
tempDir
;
try
{
await
createTestCommandRunner
(
command
).
run
(<
String
>[
// Capture Usage.test() events.
final
StringBuffer
buffer
=
await
capturedConsolePrint
(()
=>
expectToolExitLater
(
createTestCommandRunner
(
command
).
run
(<
String
>[
'run'
,
'--no-pub'
,
'--no-hot'
,
]);
fail
(
'Exception expected'
);
}
on
ToolExit
catch
(
e
)
{
// We expect a ToolExit because app does not start
expect
(
e
.
message
,
null
);
}
on
Exception
catch
(
e
)
{
fail
(
'ToolExit expected, got
$e
'
);
}
final
List
<
dynamic
>
captures
=
verify
(
mockUsage
.
sendCommand
(
captureAny
,
parameters:
captureAnyNamed
(
'parameters'
),
)).
captured
;
expect
(
captures
[
0
],
'run'
);
final
Map
<
String
,
String
>
parameters
=
captures
[
1
]
as
Map
<
String
,
String
>;
expect
(
parameters
[
cdKey
(
CustomDimensions
.
commandRunIsEmulator
)],
'false'
);
expect
(
parameters
[
cdKey
(
CustomDimensions
.
commandRunTargetName
)],
'ios'
);
expect
(
parameters
[
cdKey
(
CustomDimensions
.
commandRunProjectHostLanguage
)],
'swift'
);
expect
(
parameters
[
cdKey
(
CustomDimensions
.
commandRunTargetOsVersion
)],
'iOS 13'
);
expect
(
parameters
[
cdKey
(
CustomDimensions
.
commandRunModeName
)],
'debug'
);
expect
(
parameters
[
cdKey
(
CustomDimensions
.
commandRunProjectModule
)],
'false'
);
expect
(
parameters
.
containsKey
(
cdKey
(
CustomDimensions
.
commandRunAndroidEmbeddingVersion
)),
false
);
]),
isNull
)
);
// Allow any CustomDimensions.localTime (cd33) timestamp.
final
RegExp
usageRegexp
=
RegExp
(
'screenView {cd3: false, cd4: ios, cd22: iOS 13, cd23: debug, cd18: false, cd15: swift, cd31: false, cd47: false, cd33: .*, viewName: run'
);
expect
(
buffer
.
toString
(),
matches
(
usageRegexp
));
},
overrides:
<
Type
,
Generator
>{
ApplicationPackageFactory:
()
=>
mockApplicationPackageFactory
,
Artifacts:
()
=>
artifacts
,
...
...
@@ -408,7 +396,7 @@ void main() {
DeviceManager:
()
=>
mockDeviceManager
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
mockProcessManager
,
Usage:
()
=>
mockU
sage
,
Usage:
()
=>
u
sage
,
});
});
...
...
packages/flutter_tools/test/src/common.dart
View file @
f92ba2d2
...
...
@@ -92,6 +92,18 @@ CommandRunner<void> createTestCommandRunner([ FlutterCommand command ]) {
return
runner
;
}
/// Capture console print events into a string buffer.
Future
<
StringBuffer
>
capturedConsolePrint
(
Future
<
void
>
Function
()
body
)
async
{
final
StringBuffer
buffer
=
StringBuffer
();
await
runZoned
<
Future
<
void
>>(()
async
{
// Service the event loop.
await
body
();
},
zoneSpecification:
ZoneSpecification
(
print:
(
Zone
self
,
ZoneDelegate
parent
,
Zone
zone
,
String
line
)
{
buffer
.
writeln
(
line
);
}));
return
buffer
;
}
/// Matcher for functions that throw [AssertionError].
final
Matcher
throwsAssertionError
=
throwsA
(
isA
<
AssertionError
>());
...
...
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