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
4c6d7fd4
Unverified
Commit
4c6d7fd4
authored
May 19, 2021
by
Jonah Williams
Committed by
GitHub
May 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mocks from compile expression unit test (#82875)
parent
15b87226
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
33 deletions
+43
-33
compile_expression_test.dart
...ter_tools/test/general.shard/compile_expression_test.dart
+43
-33
No files found.
packages/flutter_tools/test/general.shard/compile_expression_test.dart
View file @
4c6d7fd4
...
...
@@ -15,18 +15,17 @@ import 'package:flutter_tools/src/base/platform.dart';
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/compile.dart'
;
import
'package:flutter_tools/src/convert.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:package_config/package_config.dart'
;
import
'package:process/process.dart'
;
import
'package:test/fake.dart'
;
import
'../src/common.dart'
;
import
'../src/fake_process_manager.dart'
;
import
'../src/fakes.dart'
;
void
main
(
)
{
ProcessManager
mockP
rocessManager
;
FakeProcessManager
p
rocessManager
;
ResidentCompiler
generator
;
MockProcess
mockFrontendServer
;
MemoryIOSink
frontendServerStdIn
;
StreamController
<
String
>
stdErrStreamController
;
BufferLogger
testLogger
;
...
...
@@ -34,33 +33,22 @@ void main() {
setUp
(()
{
testLogger
=
BufferLogger
.
test
();
mockProcessManager
=
MockProcessManager
();
mockFrontendServer
=
MockProcess
();
processManager
=
FakeProcessManager
();
frontendServerStdIn
=
MemoryIOSink
();
fileSystem
=
MemoryFileSystem
.
test
();
generator
=
ResidentCompiler
(
'sdkroot'
,
buildMode:
BuildMode
.
debug
,
artifacts:
Artifacts
.
test
(),
processManager:
mockP
rocessManager
,
processManager:
p
rocessManager
,
logger:
testLogger
,
platform:
FakePlatform
(
operatingSystem:
'linux'
),
fileSystem:
fileSystem
,
);
stdErrStreamController
=
StreamController
<
String
>();
when
(
mockFrontendServer
.
stdin
).
thenReturn
(
frontendServerStdIn
);
when
(
mockFrontendServer
.
stderr
)
.
thenAnswer
((
Invocation
invocation
)
=>
stdErrStreamController
.
stream
.
transform
(
utf8
.
encoder
));
when
(
mockFrontendServer
.
exitCode
).
thenAnswer
((
Invocation
invocation
)
{
return
Completer
<
int
>().
future
;
});
when
(
mockProcessManager
.
canRun
(
any
)).
thenReturn
(
true
);
when
(
mockProcessManager
.
start
(
any
)).
thenAnswer
(
(
Invocation
invocation
)
=>
Future
<
Process
>.
value
(
mockFrontendServer
)
);
processManager
.
process
.
stdin
=
frontendServerStdIn
;
processManager
.
process
.
stderr
=
stdErrStreamController
.
stream
.
transform
(
utf8
.
encoder
);
});
testWithoutContext
(
'compile expression fails if not previously compiled'
,
()
async
{
...
...
@@ -79,13 +67,10 @@ void main() {
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(<
int
>[
1
,
2
,
3
,
4
]);
when
(
mockFrontendServer
.
stdout
)
.
thenAnswer
((
Invocation
invocation
)
=>
Stream
<
List
<
int
>>.
fromFutures
(
processManager
.
process
.
stdout
=
Stream
<
List
<
int
>>.
fromFutures
(
<
Future
<
List
<
int
>>>[
compileResponseCompleter
.
future
,
compileExpressionResponseCompleter
.
future
]));
compileExpressionResponseCompleter
.
future
]);
compileResponseCompleter
.
complete
(
Future
<
List
<
int
>>.
value
(
utf8
.
encode
(
'result abc
\n
line1
\n
line2
\n
abc
\n
abc /path/to/main.dart.dill 0
\n
'
)));
...
...
@@ -123,14 +108,14 @@ void main() {
final
Completer
<
List
<
int
>>
compileExpressionResponseCompleter1
=
Completer
<
List
<
int
>>();
final
Completer
<
List
<
int
>>
compileExpressionResponseCompleter2
=
Completer
<
List
<
int
>>();
when
(
mockFrontendServer
.
stdout
)
.
thenAnswer
((
Invocation
invocation
)
=>
Stream
<
List
<
int
>>.
fromFutures
(
<
Future
<
List
<
int
>>>[
compileResponseCompleter
.
future
,
compileExpressionResponseCompleter1
.
future
,
compileExpressionResponseCompleter2
.
future
,
])
);
processManager
.
process
.
stdout
=
Stream
<
List
<
int
>>.
fromFutures
(
<
Future
<
List
<
int
>>>[
compileResponseCompleter
.
future
,
compileExpressionResponseCompleter1
.
future
,
compileExpressionResponseCompleter2
.
future
,
]
);
// The test manages timing via completers.
unawaited
(
...
...
@@ -192,5 +177,30 @@ void main() {
});
}
class
MockProcess
extends
Mock
implements
Process
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
FakeProcess
extends
Fake
implements
Process
{
@override
Stream
<
List
<
int
>>
stdout
;
@override
Stream
<
List
<
int
>>
stderr
;
@override
IOSink
stdin
;
@override
Future
<
int
>
get
exitCode
=>
Completer
<
int
>().
future
;
}
class
FakeProcessManager
extends
Fake
implements
ProcessManager
{
final
FakeProcess
process
=
FakeProcess
();
@override
bool
canRun
(
dynamic
executable
,
{
String
workingDirectory
})
{
return
true
;
}
@override
Future
<
Process
>
start
(
List
<
Object
>
command
,
{
String
workingDirectory
,
Map
<
String
,
String
>
environment
,
bool
includeParentEnvironment
=
true
,
bool
runInShell
=
false
,
ProcessStartMode
mode
=
ProcessStartMode
.
normal
})
async
{
return
process
;
}
}
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