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
2c15e3ca
Unverified
Commit
2c15e3ca
authored
Jun 16, 2022
by
Jonah Williams
Committed by
GitHub
Jun 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] update test/src to null safety (#106064)
parent
f104be7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
34 deletions
+31
-34
context.dart
packages/flutter_tools/test/src/context.dart
+22
-23
testbed.dart
packages/flutter_tools/test/src/testbed.dart
+9
-11
No files found.
packages/flutter_tools/test/src/context.dart
View file @
2c15e3ca
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'package:flutter_tools/src/android/android_workflow.dart'
;
...
...
@@ -36,6 +34,7 @@ import 'package:flutter_tools/src/reporting/crash_reporting.dart';
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:flutter_tools/src/version.dart'
;
import
'package:meta/meta.dart'
;
import
'package:test/fake.dart'
;
import
'common.dart'
;
import
'fake_http_client.dart'
;
...
...
@@ -48,9 +47,9 @@ export 'package:flutter_tools/src/base/context.dart' show Generator;
export
'fake_process_manager.dart'
show
ProcessManager
,
FakeProcessManager
,
FakeCommand
;
/// Return the test logger. This assumes that the current Logger is a BufferLogger.
BufferLogger
get
testLogger
=>
context
.
get
<
Logger
>()
as
BufferLogger
;
BufferLogger
get
testLogger
=>
context
.
get
<
Logger
>()
!
as
BufferLogger
;
FakeDeviceManager
get
testDeviceManager
=>
context
.
get
<
DeviceManager
>()
as
FakeDeviceManager
;
FakeDeviceManager
get
testDeviceManager
=>
context
.
get
<
DeviceManager
>()
!
as
FakeDeviceManager
;
@isTest
void
testUsingContext
(
...
...
@@ -58,8 +57,8 @@ void testUsingContext(
dynamic
Function
()
testMethod
,
{
Map
<
Type
,
Generator
>
overrides
=
const
<
Type
,
Generator
>{},
bool
initializeFlutterRoot
=
true
,
String
testOn
,
bool
skip
,
// should default to `false`, but https://github.com/dart-lang/test/issues/545 doesn't allow this
String
?
testOn
,
bool
?
skip
,
// should default to `false`, but https://github.com/dart-lang/test/issues/545 doesn't allow this
})
{
if
(
overrides
[
FileSystem
]
!=
null
&&
overrides
[
ProcessManager
]
==
null
)
{
throw
StateError
(
...
...
@@ -74,10 +73,10 @@ void testUsingContext(
// Ensure we don't rely on the default [Config] constructor which will
// leak a sticky $HOME/.flutter_settings behind!
Directory
configDir
;
Directory
?
configDir
;
tearDown
(()
{
if
(
configDir
!=
null
)
{
tryToDelete
(
configDir
);
tryToDelete
(
configDir
!
);
configDir
=
null
;
}
});
...
...
@@ -92,7 +91,7 @@ void testUsingContext(
PersistentToolState
buildPersistentToolState
(
FileSystem
fs
)
{
configDir
??=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_config_dir_test.'
);
return
PersistentToolState
.
test
(
directory:
configDir
,
directory:
configDir
!
,
logger:
globals
.
logger
,
);
}
...
...
@@ -172,7 +171,7 @@ void testUsingContext(
void
_printBufferedErrors
(
AppContext
testContext
)
{
if
(
testContext
.
get
<
Logger
>()
is
BufferLogger
)
{
final
BufferLogger
bufferLogger
=
testContext
.
get
<
Logger
>()
as
BufferLogger
;
final
BufferLogger
bufferLogger
=
testContext
.
get
<
Logger
>()
!
as
BufferLogger
;
if
(
bufferLogger
.
errorText
.
isNotEmpty
)
{
// This is where the logger outputting errors is implemented, so it has
// to use `print`.
...
...
@@ -185,10 +184,10 @@ void _printBufferedErrors(AppContext testContext) {
class
FakeDeviceManager
implements
DeviceManager
{
List
<
Device
>
devices
=
<
Device
>[];
String
_specifiedDeviceId
;
String
?
_specifiedDeviceId
;
@override
String
get
specifiedDeviceId
{
String
?
get
specifiedDeviceId
{
if
(
_specifiedDeviceId
==
null
||
_specifiedDeviceId
==
'all'
)
{
return
null
;
}
...
...
@@ -196,7 +195,7 @@ class FakeDeviceManager implements DeviceManager {
}
@override
set
specifiedDeviceId
(
String
id
)
{
set
specifiedDeviceId
(
String
?
id
)
{
_specifiedDeviceId
=
id
;
}
...
...
@@ -212,7 +211,7 @@ class FakeDeviceManager implements DeviceManager {
Future
<
List
<
Device
>>
getAllConnectedDevices
()
async
=>
devices
;
@override
Future
<
List
<
Device
>>
refreshAllConnectedDevices
({
Duration
timeout
})
async
=>
devices
;
Future
<
List
<
Device
>>
refreshAllConnectedDevices
({
Duration
?
timeout
})
async
=>
devices
;
@override
Future
<
List
<
Device
>>
getDevicesById
(
String
deviceId
)
async
{
...
...
@@ -222,7 +221,7 @@ class FakeDeviceManager implements DeviceManager {
@override
Future
<
List
<
Device
>>
getDevices
()
{
return
hasSpecifiedDeviceId
?
getDevicesById
(
specifiedDeviceId
)
?
getDevicesById
(
specifiedDeviceId
!
)
:
getAllConnectedDevices
();
}
...
...
@@ -238,17 +237,17 @@ class FakeDeviceManager implements DeviceManager {
List
<
DeviceDiscovery
>
get
deviceDiscoverers
=>
<
DeviceDiscovery
>[];
@override
bool
isDeviceSupportedForProject
(
Device
device
,
FlutterProject
flutterProject
)
{
return
device
.
isSupportedForProject
(
flutterProject
);
bool
isDeviceSupportedForProject
(
Device
device
,
FlutterProject
?
flutterProject
)
{
return
device
.
isSupportedForProject
(
flutterProject
!
);
}
@override
Future
<
List
<
Device
>>
findTargetDevices
(
FlutterProject
flutterProject
,
{
Duration
timeout
})
async
{
Future
<
List
<
Device
>>
findTargetDevices
(
FlutterProject
?
flutterProject
,
{
Duration
?
timeout
})
async
{
return
devices
;
}
}
class
FakeAndroidLicenseValidator
extends
AndroidLicenseValidator
{
class
FakeAndroidLicenseValidator
extends
Fake
implements
AndroidLicenseValidator
{
@override
Future
<
LicensesAccepted
>
get
licensesAccepted
async
=>
LicensesAccepted
.
all
;
}
...
...
@@ -302,7 +301,7 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter {
@override
Future
<
Map
<
String
,
String
>>
getBuildSettings
(
String
projectPath
,
{
XcodeProjectBuildContext
buildContext
,
XcodeProjectBuildContext
?
buildContext
,
Duration
timeout
=
const
Duration
(
minutes:
1
),
})
async
{
return
<
String
,
String
>{};
...
...
@@ -313,14 +312,14 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter {
Directory
podXcodeProject
,
{
Duration
timeout
=
const
Duration
(
minutes:
1
),
})
async
{
return
null
;
return
''
;
}
@override
Future
<
void
>
cleanWorkspace
(
String
workspacePath
,
String
scheme
,
{
bool
verbose
=
false
})
async
{
}
@override
Future
<
XcodeProjectInfo
>
getInfo
(
String
projectPath
,
{
String
projectFilename
})
async
{
Future
<
XcodeProjectInfo
>
getInfo
(
String
projectPath
,
{
String
?
projectFilename
})
async
{
return
XcodeProjectInfo
(
<
String
>[
'Runner'
],
<
String
>[
'Debug'
,
'Release'
],
...
...
@@ -358,7 +357,7 @@ class LocalFileSystemBlockingSetCurrentDirectory extends LocalFileSystem {
class
FakeSignals
implements
Signals
{
@override
Object
addHandler
(
ProcessSignal
signal
,
SignalHandler
handler
)
{
return
null
;
return
Object
()
;
}
@override
...
...
packages/flutter_tools/test/src/testbed.dart
View file @
2c15e3ca
...
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import
'dart:async'
;
import
'dart:io'
;
...
...
@@ -81,18 +79,18 @@ class Testbed {
/// `overrides` provides more overrides in addition to the test defaults.
/// `setup` may be provided to apply mocks within the tool managed zone,
/// including any specified overrides.
Testbed
({
FutureOr
<
void
>
Function
()
setup
,
Map
<
Type
,
Generator
>
overrides
})
Testbed
({
FutureOr
<
void
>
Function
()
?
setup
,
Map
<
Type
,
Generator
>?
overrides
})
:
_setup
=
setup
,
_overrides
=
overrides
;
final
FutureOr
<
void
>
Function
()
_setup
;
final
Map
<
Type
,
Generator
>
_overrides
;
final
FutureOr
<
void
>
Function
()
?
_setup
;
final
Map
<
Type
,
Generator
>
?
_overrides
;
/// Runs `test` within a tool zone.
///
/// `overrides` may be used to provide new context values for the single test
/// case or override any context values from the setup.
Future
<
T
>
run
<
T
>(
FutureOr
<
T
>
Function
()
test
,
{
Map
<
Type
,
Generator
>
overrides
})
{
Future
<
T
?>
run
<
T
>(
FutureOr
<
T
>
Function
()
test
,
{
Map
<
Type
,
Generator
>?
overrides
})
{
final
Map
<
Type
,
Generator
>
testOverrides
=
<
Type
,
Generator
>{
...
_testbedDefaults
,
// Add the initial setUp overrides
...
...
@@ -104,13 +102,13 @@ class Testbed {
throw
StateError
(
'Do not inject ProcessUtils for testing, use ProcessManager instead.'
);
}
// Cache the original flutter root to restore after the test case.
final
String
originalFlutterRoot
=
Cache
.
flutterRoot
;
final
String
?
originalFlutterRoot
=
Cache
.
flutterRoot
;
// Track pending timers to verify that they were correctly cleaned up.
final
Map
<
Timer
,
StackTrace
>
timers
=
<
Timer
,
StackTrace
>{};
return
HttpOverrides
.
runZoned
(()
{
return
runInContext
<
T
>(()
{
return
context
.
run
<
T
>(
return
runInContext
<
T
?
>(()
{
return
context
.
run
<
T
?
>(
name:
'testbed'
,
overrides:
testOverrides
,
zoneSpecification:
ZoneSpecification
(
...
...
@@ -128,7 +126,7 @@ class Testbed {
body:
()
async
{
Cache
.
flutterRoot
=
''
;
if
(
_setup
!=
null
)
{
await
_setup
();
await
_setup
?.
call
();
}
await
test
();
Cache
.
flutterRoot
=
originalFlutterRoot
;
...
...
@@ -140,6 +138,6 @@ class Testbed {
return
null
;
});
});
},
createHttpClient:
(
SecurityContext
c
)
=>
FakeHttpClient
.
any
());
},
createHttpClient:
(
SecurityContext
?
c
)
=>
FakeHttpClient
.
any
());
}
}
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