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
34674fd5
Unverified
Commit
34674fd5
authored
Apr 27, 2021
by
Jonah Williams
Committed by
GitHub
Apr 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mocks from test_compiler test (#81312)
parent
a0831048
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
32 deletions
+43
-32
test_compiler_test.dart
...ter_tools/test/general.shard/test/test_compiler_test.dart
+43
-32
No files found.
packages/flutter_tools/test/general.shard/test/test_compiler_test.dart
View file @
34674fd5
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
// @dart = 2.8
// @dart = 2.8
import
'package:file/memory.dart'
;
import
'package:file/memory.dart'
;
import
'package:file_testing/file_testing.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
...
@@ -13,8 +12,8 @@ import 'package:flutter_tools/src/build_info.dart';
...
@@ -13,8 +12,8 @@ import 'package:flutter_tools/src/build_info.dart';
import
'package:flutter_tools/src/compile.dart'
;
import
'package:flutter_tools/src/compile.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/test/test_compiler.dart'
;
import
'package:flutter_tools/src/test/test_compiler.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:package_config/package_config_types.dart'
;
import
'package:package_config/package_config_types.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/context.dart'
;
...
@@ -34,36 +33,25 @@ final BuildInfo debugBuild = BuildInfo(
...
@@ -34,36 +33,25 @@ final BuildInfo debugBuild = BuildInfo(
);
);
void
main
(
)
{
void
main
(
)
{
Mock
ResidentCompiler
residentCompiler
;
Fake
ResidentCompiler
residentCompiler
;
FileSystem
fileSystem
;
FileSystem
fileSystem
;
setUp
(()
{
setUp
(()
{
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'test/foo.dart'
).
createSync
(
recursive:
true
);
fileSystem
.
file
(
'test/foo.dart'
).
createSync
(
recursive:
true
);
residentCompiler
=
MockResidentCompiler
(
);
residentCompiler
=
FakeResidentCompiler
(
fileSystem
);
});
});
testUsingContext
(
'TestCompiler reports a dill file when compile is successful'
,
()
async
{
testUsingContext
(
'TestCompiler reports a dill file when compile is successful'
,
()
async
{
residentCompiler
.
compilerOutput
=
const
CompilerOutput
(
'abc.dill'
,
0
,
<
Uri
>[]);
final
FakeTestCompiler
testCompiler
=
FakeTestCompiler
(
final
FakeTestCompiler
testCompiler
=
FakeTestCompiler
(
debugBuild
,
debugBuild
,
FlutterProject
.
fromDirectoryTest
(
fileSystem
.
currentDirectory
),
FlutterProject
.
fromDirectoryTest
(
fileSystem
.
currentDirectory
),
residentCompiler
,
residentCompiler
,
);
);
when
(
residentCompiler
.
recompile
(
any
,
<
Uri
>[
Uri
.
parse
(
'test/foo.dart'
)],
outputPath:
testCompiler
.
outputDill
.
path
,
packageConfig:
anyNamed
(
'packageConfig'
),
projectRootPath:
anyNamed
(
'projectRootPath'
),
fs:
anyNamed
(
'fs'
),
)).
thenAnswer
((
Invocation
invocation
)
async
{
fileSystem
.
file
(
'abc.dill'
).
createSync
();
return
const
CompilerOutput
(
'abc.dill'
,
0
,
<
Uri
>[]);
});
expect
(
await
testCompiler
.
compile
(
Uri
.
parse
(
'test/foo.dart'
)),
'test/foo.dart.dill'
);
expect
(
await
testCompiler
.
compile
(
Uri
.
parse
(
'test/foo.dart'
)),
'test/foo.dart.dill'
);
expect
(
fileSystem
.
file
(
'test/foo.dart.dill'
),
exists
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
FileSystem:
()
=>
fileSystem
,
Platform:
()
=>
linuxPlatform
,
Platform:
()
=>
linuxPlatform
,
...
@@ -72,26 +60,15 @@ void main() {
...
@@ -72,26 +60,15 @@ void main() {
});
});
testUsingContext
(
'TestCompiler reports null when a compile fails'
,
()
async
{
testUsingContext
(
'TestCompiler reports null when a compile fails'
,
()
async
{
residentCompiler
.
compilerOutput
=
const
CompilerOutput
(
'abc.dill'
,
1
,
<
Uri
>[]);
final
FakeTestCompiler
testCompiler
=
FakeTestCompiler
(
final
FakeTestCompiler
testCompiler
=
FakeTestCompiler
(
debugBuild
,
debugBuild
,
FlutterProject
.
fromDirectoryTest
(
fileSystem
.
currentDirectory
),
FlutterProject
.
fromDirectoryTest
(
fileSystem
.
currentDirectory
),
residentCompiler
,
residentCompiler
,
);
);
when
(
residentCompiler
.
recompile
(
any
,
<
Uri
>[
Uri
.
parse
(
'test/foo.dart'
)],
outputPath:
testCompiler
.
outputDill
.
path
,
packageConfig:
anyNamed
(
'packageConfig'
),
projectRootPath:
anyNamed
(
'projectRootPath'
),
fs:
anyNamed
(
'fs'
),
)).
thenAnswer
((
Invocation
invocation
)
async
{
fileSystem
.
file
(
'abc.dill'
).
createSync
();
return
const
CompilerOutput
(
'abc.dill'
,
1
,
<
Uri
>[]);
});
expect
(
await
testCompiler
.
compile
(
Uri
.
parse
(
'test/foo.dart'
)),
null
);
expect
(
await
testCompiler
.
compile
(
Uri
.
parse
(
'test/foo.dart'
)),
null
);
expect
(
fileSystem
.
file
(
'test/foo.dart.dill'
),
isNot
(
exists
));
expect
(
residentCompiler
.
didShutdown
,
true
);
verify
(
residentCompiler
.
shutdown
()).
called
(
1
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
FileSystem:
()
=>
fileSystem
,
Platform:
()
=>
linuxPlatform
,
Platform:
()
=>
linuxPlatform
,
...
@@ -112,7 +89,7 @@ void main() {
...
@@ -112,7 +89,7 @@ void main() {
await
testCompiler
.
dispose
();
await
testCompiler
.
dispose
();
expect
(
testCompiler
.
compilerController
.
isClosed
,
true
);
expect
(
testCompiler
.
compilerController
.
isClosed
,
true
);
verify
(
residentCompiler
.
shutdown
()).
called
(
1
);
expect
(
residentCompiler
.
didShutdown
,
true
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
FileSystem:
()
=>
fileSystem
,
Platform:
()
=>
linuxPlatform
,
Platform:
()
=>
linuxPlatform
,
...
@@ -129,7 +106,7 @@ class FakeTestCompiler extends TestCompiler {
...
@@ -129,7 +106,7 @@ class FakeTestCompiler extends TestCompiler {
this
.
residentCompiler
,
this
.
residentCompiler
,
)
:
super
(
buildInfo
,
flutterProject
);
)
:
super
(
buildInfo
,
flutterProject
);
final
Mock
ResidentCompiler
residentCompiler
;
final
Fake
ResidentCompiler
residentCompiler
;
@override
@override
Future
<
ResidentCompiler
>
createCompiler
()
async
{
Future
<
ResidentCompiler
>
createCompiler
()
async
{
...
@@ -137,4 +114,38 @@ class FakeTestCompiler extends TestCompiler {
...
@@ -137,4 +114,38 @@ class FakeTestCompiler extends TestCompiler {
}
}
}
}
class
MockResidentCompiler
extends
Mock
implements
ResidentCompiler
{}
class
FakeResidentCompiler
extends
Fake
implements
ResidentCompiler
{
FakeResidentCompiler
(
this
.
fileSystem
);
final
FileSystem
fileSystem
;
CompilerOutput
compilerOutput
;
bool
didShutdown
=
false
;
@override
Future
<
CompilerOutput
>
recompile
(
Uri
mainUri
,
List
<
Uri
>
invalidatedFiles
,
{
String
outputPath
,
PackageConfig
packageConfig
,
String
projectRootPath
,
FileSystem
fs
,
bool
suppressErrors
=
false
,
})
async
{
if
(
compilerOutput
!=
null
)
{
fileSystem
.
file
(
compilerOutput
.
outputFilename
).
createSync
(
recursive:
true
);
}
return
compilerOutput
;
}
@override
void
accept
()
{
}
@override
void
reset
()
{
}
@override
Future
<
void
>
shutdown
()
async
{
didShutdown
=
true
;
}
}
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