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
7263c127
Unverified
Commit
7263c127
authored
May 30, 2019
by
Jonah Williams
Committed by
GitHub
May 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add local overrides to testbed and provide more defaults (#33264)
parent
da600bac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
3 deletions
+77
-3
testbed.dart
packages/flutter_tools/test/src/testbed.dart
+19
-3
testbed_test.dart
packages/flutter_tools/test/testbed_test.dart
+58
-0
No files found.
packages/flutter_tools/test/src/testbed.dart
View file @
7263c127
...
...
@@ -8,14 +8,22 @@ import 'package:file/memory.dart';
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/context_runner.dart'
;
import
'context.dart'
;
export
'package:flutter_tools/src/base/context.dart'
show
Generator
;
// A default value should be provided if one of the following criteria is met:
// - The vast majority of tests should use this provider. For example,
// [BufferLogger], [MemoryFileSystem].
// - More TBD.
final
Map
<
Type
,
Generator
>
_testbedDefaults
=
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
Logger:
()
=>
BufferLogger
(),
FileSystem:
()
=>
MemoryFileSystem
(),
// Keeps tests fast by avoid actual file system.
Logger:
()
=>
BufferLogger
(),
// Allows reading logs and prevents stdout.
OutputPreferences:
()
=>
OutputPreferences
(
showColor:
false
),
// configures BufferLogger to avoid color codes.
};
/// Manages interaction with the tool injection and runner system.
...
...
@@ -61,11 +69,19 @@ class Testbed {
final
Map
<
Type
,
Generator
>
_overrides
;
/// Runs `test` within a tool zone.
FutureOr
<
T
>
run
<
T
>(
FutureOr
<
T
>
Function
()
test
)
{
///
/// `overrides` may be used to provide new context values for the single test
/// case or override any context values from the setup.
FutureOr
<
T
>
run
<
T
>(
FutureOr
<
T
>
Function
()
test
,
{
Map
<
Type
,
Generator
>
overrides
})
{
final
Map
<
Type
,
Generator
>
testOverrides
=
Map
<
Type
,
Generator
>.
from
(
_testbedDefaults
);
// Add the initial setUp overrides
if
(
_overrides
!=
null
)
{
testOverrides
.
addAll
(
_overrides
);
}
// Add the test-specific overrides
if
(
overrides
!=
null
)
{
testOverrides
.
addAll
(
overrides
);
}
// Cache the original flutter root to restore after the test case.
final
String
originalFlutterRoot
=
Cache
.
flutterRoot
;
return
runInContext
<
T
>(()
{
...
...
packages/flutter_tools/test/testbed_test.dart
0 → 100644
View file @
7263c127
// Copyright 2019 The Chromium 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:file/memory.dart'
;
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'src/common.dart'
;
import
'src/testbed.dart'
;
void
main
(
)
{
group
(
'Testbed'
,
()
{
test
(
'Can provide default interfaces'
,
()
async
{
final
Testbed
testbed
=
Testbed
();
FileSystem
localFileSystem
;
await
testbed
.
run
(()
{
localFileSystem
=
fs
;
});
expect
(
localFileSystem
,
isA
<
MemoryFileSystem
>());
});
test
(
'Can provide setup interfaces'
,
()
async
{
final
Testbed
testbed
=
Testbed
(
overrides:
<
Type
,
Generator
>{
A:
()
=>
A
(),
});
A
instance
;
await
testbed
.
run
(()
{
instance
=
context
.
get
<
A
>();
});
expect
(
instance
,
isA
<
A
>());
});
test
(
'Can provide local overrides'
,
()
async
{
final
Testbed
testbed
=
Testbed
(
overrides:
<
Type
,
Generator
>{
A:
()
=>
A
(),
});
A
instance
;
await
testbed
.
run
(()
{
instance
=
context
.
get
<
A
>();
},
overrides:
<
Type
,
Generator
>{
A:
()
=>
B
(),
});
expect
(
instance
,
isA
<
B
>());
});
});
}
class
A
{}
class
B
extends
A
{}
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