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
90531179
Unverified
Commit
90531179
authored
Feb 18, 2021
by
Jenn Magder
Committed by
GitHub
Feb 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MockProcessManager -> FakeProcessManager in os_test (#76264)
parent
d65c98b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
50 deletions
+83
-50
os_test.dart
packages/flutter_tools/test/general.shard/base/os_test.dart
+83
-50
No files found.
packages/flutter_tools/test/general.shard/base/os_test.dart
View file @
90531179
...
...
@@ -12,8 +12,6 @@ import 'package:flutter_tools/src/base/logger.dart';
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -23,11 +21,9 @@ const String kPath1 = '/bar/bin/$kExecutable';
const
String
kPath2
=
'/another/bin/
$kExecutable
'
;
void
main
(
)
{
MockProcessManager
mockProcessManager
;
FakeProcessManager
fakeProcessManager
;
setUp
(()
{
mockProcessManager
=
MockProcessManager
();
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
});
...
...
@@ -90,13 +86,21 @@ void main() {
group
(
'which on Windows'
,
()
{
testWithoutContext
(
'throws tool exit if where throws an argument error'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'where'
,
kExecutable
]))
.
thenThrow
(
ArgumentError
(
'Cannot find executable for where'
));
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
const
<
String
>[
'where'
,
kExecutable
,
],
exception:
ArgumentError
(
'Cannot find executable for where'
),
),
);
final
OperatingSystemUtils
utils
=
OperatingSystemUtils
(
fileSystem:
MemoryFileSystem
.
test
(),
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'windows'
),
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
);
expect
(()
=>
utils
.
which
(
kExecutable
),
throwsA
(
isA
<
ToolExit
>()));
...
...
@@ -416,58 +420,87 @@ void main() {
);
});
testWithoutContext
(
'If unzip throws an ArgumentError, display an install message'
,
()
{
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
when
(
mockProcessManager
.
runSync
(
<
String
>[
'unzip'
,
'-o'
,
'-q'
,
'foo.zip'
,
'-d'
,
fileSystem
.
currentDirectory
.
path
],
)).
thenThrow
(
ArgumentError
());
group
(
'display an install message when unzip throws an ArgumentError'
,
()
{
testWithoutContext
(
'Linux'
,
()
{
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'unzip'
,
'-o'
,
'-q'
,
'foo.zip'
,
'-d'
,
fileSystem
.
currentDirectory
.
path
,
],
exception:
ArgumentError
(),
),
);
final
OperatingSystemUtils
linuxOsUtils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'linux'
),
processManager:
mock
ProcessManager
,
);
final
OperatingSystemUtils
linuxOsUtils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'linux'
),
processManager:
fake
ProcessManager
,
);
expect
(
()
=>
linuxOsUtils
.
unzip
(
fileSystem
.
file
(
'foo.zip'
),
fileSystem
.
currentDirectory
),
throwsToolExit
(
message:
'Missing "unzip" tool. Unable to extract foo.zip.
\n
'
'Consider running "sudo apt-get install unzip".'
),
);
expect
(
()
=>
linuxOsUtils
.
unzip
(
fileSystem
.
file
(
'foo.zip'
),
fileSystem
.
currentDirectory
),
throwsToolExit
(
message:
'Missing "unzip" tool. Unable to extract foo.zip.
\n
'
'Consider running "sudo apt-get install unzip".'
),
);
});
final
OperatingSystemUtils
macOSUtils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'macos'
),
processManager:
mockProcessManager
,
);
testWithoutContext
(
'macOS'
,
()
{
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'unzip'
,
'-o'
,
'-q'
,
'foo.zip'
,
'-d'
,
fileSystem
.
currentDirectory
.
path
,
],
exception:
ArgumentError
(),
),
);
expect
(
()
=>
macOSUtils
.
unzip
(
fileSystem
.
file
(
'foo.zip'
),
fileSystem
.
currentDirectory
)
,
throwsToolExit
(
message:
'Missing "unzip" tool. Unable to extract foo.zip.
\n
'
'Consider running "brew install unzip".'
)
,
);
final
OperatingSystemUtils
macOSUtils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'macos'
),
processManager:
fakeProcessManager
,
);
final
OperatingSystemUtils
unknownOsUtils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'fuchsia'
),
processManager:
mockProcessManager
,
);
expect
(
()
=>
macOSUtils
.
unzip
(
fileSystem
.
file
(
'foo.zip'
),
fileSystem
.
currentDirectory
),
throwsToolExit
(
message:
'Missing "unzip" tool. Unable to extract foo.zip.
\n
'
'Consider running "brew install unzip".'
),
);
});
expect
(
()
=>
unknownOsUtils
.
unzip
(
fileSystem
.
file
(
'foo.zip'
),
fileSystem
.
currentDirectory
),
throwsToolExit
(
message:
'Missing "unzip" tool. Unable to extract foo.zip.
\n
'
'Please install unzip.'
),
);
testWithoutContext
(
'unknown OS'
,
()
{
final
FileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fakeProcessManager
.
addCommand
(
FakeCommand
(
command:
<
String
>[
'unzip'
,
'-o'
,
'-q'
,
'foo.zip'
,
'-d'
,
fileSystem
.
currentDirectory
.
path
,
],
exception:
ArgumentError
(),
),
);
final
OperatingSystemUtils
unknownOsUtils
=
OperatingSystemUtils
(
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'fuchsia'
),
processManager:
fakeProcessManager
,
);
expect
(
()
=>
unknownOsUtils
.
unzip
(
fileSystem
.
file
(
'foo.zip'
),
fileSystem
.
currentDirectory
),
throwsToolExit
(
message:
'Missing "unzip" tool. Unable to extract foo.zip.
\n
'
'Please install unzip.'
),
);
});
});
testWithoutContext
(
'stream compression level'
,
()
{
expect
(
OperatingSystemUtils
.
gzipLevel1
.
level
,
equals
(
1
));
});
}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
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