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
2bf560b4
Unverified
Commit
2bf560b4
authored
Jan 27, 2021
by
Jenn Magder
Committed by
GitHub
Jan 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace MockProcessManager with FakeProcessManager in process_test where possible (#74834)
parent
1747adb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
57 deletions
+104
-57
process_test.dart
...s/flutter_tools/test/general.shard/base/process_test.dart
+104
-57
No files found.
packages/flutter_tools/test/general.shard/base/process_test.dart
View file @
2bf560b4
...
@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/base/platform.dart';
...
@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/base/platform.dart';
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'package:fake_async/fake_async.dart'
;
import
'package:fake_async/fake_async.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/context.dart'
;
...
@@ -21,20 +20,25 @@ import '../../src/mocks.dart' show MockProcess,
...
@@ -21,20 +20,25 @@ import '../../src/mocks.dart' show MockProcess,
void
main
(
)
{
void
main
(
)
{
group
(
'process exceptions'
,
()
{
group
(
'process exceptions'
,
()
{
ProcessManager
mock
ProcessManager
;
FakeProcessManager
fake
ProcessManager
;
ProcessUtils
processUtils
;
ProcessUtils
processUtils
;
setUp
(()
{
setUp
(()
{
mockProcessManager
=
PlainMockProcessManager
(
);
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]
);
processUtils
=
ProcessUtils
(
processUtils
=
ProcessUtils
(
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
logger:
BufferLogger
.
test
(),
logger:
BufferLogger
.
test
(),
);
);
});
});
testWithoutContext
(
'runAsync throwOnError: exceptions should be ProcessException objects'
,
()
async
{
testWithoutContext
(
'runAsync throwOnError: exceptions should be ProcessException objects'
,
()
async
{
when
(
mockProcessManager
.
run
(<
String
>[
'false'
])).
thenAnswer
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
(
Invocation
invocation
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
1
,
''
,
''
)));
command:
<
String
>[
'false'
,
],
exitCode:
1
,
));
expect
(()
async
=>
await
processUtils
.
run
(<
String
>[
'false'
],
throwOnError:
true
),
expect
(()
async
=>
await
processUtils
.
run
(<
String
>[
'false'
],
throwOnError:
true
),
throwsA
(
isA
<
ProcessException
>()));
throwsA
(
isA
<
ProcessException
>()));
});
});
...
@@ -119,7 +123,7 @@ void main() {
...
@@ -119,7 +123,7 @@ void main() {
group
(
'run'
,
()
{
group
(
'run'
,
()
{
const
Duration
delay
=
Duration
(
seconds:
2
);
const
Duration
delay
=
Duration
(
seconds:
2
);
MockProcessManager
flakyProcessManager
;
MockProcessManager
flakyProcessManager
;
ProcessManager
mock
ProcessManager
;
FakeProcessManager
fake
ProcessManager
;
ProcessUtils
processUtils
;
ProcessUtils
processUtils
;
ProcessUtils
flakyProcessUtils
;
ProcessUtils
flakyProcessUtils
;
...
@@ -127,9 +131,9 @@ void main() {
...
@@ -127,9 +131,9 @@ void main() {
// MockProcessManager has an implementation of start() that returns the
// MockProcessManager has an implementation of start() that returns the
// result of processFactory.
// result of processFactory.
flakyProcessManager
=
MockProcessManager
();
flakyProcessManager
=
MockProcessManager
();
mockProcessManager
=
MockProcessManager
(
);
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]
);
processUtils
=
ProcessUtils
(
processUtils
=
ProcessUtils
(
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
logger:
BufferLogger
.
test
(),
logger:
BufferLogger
.
test
(),
);
);
flakyProcessUtils
=
ProcessUtils
(
flakyProcessUtils
=
ProcessUtils
(
...
@@ -139,31 +143,42 @@ void main() {
...
@@ -139,31 +143,42 @@ void main() {
});
});
testWithoutContext
(
' succeeds on success'
,
()
async
{
testWithoutContext
(
' succeeds on success'
,
()
async
{
when
(
mockProcessManager
.
run
(<
String
>[
'whoohoo'
])).
thenAnswer
((
_
)
{
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
return
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
0
,
''
,
''
));
command:
<
String
>[
});
'whoohoo'
,
],
));
expect
((
await
processUtils
.
run
(<
String
>[
'whoohoo'
])).
exitCode
,
0
);
expect
((
await
processUtils
.
run
(<
String
>[
'whoohoo'
])).
exitCode
,
0
);
});
});
testWithoutContext
(
' fails on failure'
,
()
async
{
testWithoutContext
(
' fails on failure'
,
()
async
{
when
(
mockProcessManager
.
run
(<
String
>[
'boohoo'
])).
thenAnswer
((
_
)
{
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
return
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
1
,
''
,
''
));
command:
<
String
>[
});
'boohoo'
,
],
exitCode:
1
,
));
expect
((
await
processUtils
.
run
(<
String
>[
'boohoo'
])).
exitCode
,
1
);
expect
((
await
processUtils
.
run
(<
String
>[
'boohoo'
])).
exitCode
,
1
);
});
});
testWithoutContext
(
' throws on failure with throwOnError'
,
()
async
{
testWithoutContext
(
' throws on failure with throwOnError'
,
()
async
{
when
(
mockProcessManager
.
run
(<
String
>[
'kaboom'
])).
thenAnswer
((
_
)
{
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
return
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
1
,
''
,
''
));
command:
<
String
>[
});
'kaboom'
,
],
exitCode:
1
,
));
expect
(()
=>
processUtils
.
run
(<
String
>[
'kaboom'
],
throwOnError:
true
),
expect
(()
=>
processUtils
.
run
(<
String
>[
'kaboom'
],
throwOnError:
true
),
throwsA
(
isA
<
ProcessException
>()));
throwsA
(
isA
<
ProcessException
>()));
});
});
testWithoutContext
(
' does not throw on allowed Failures'
,
()
async
{
testWithoutContext
(
' does not throw on allowed Failures'
,
()
async
{
when
(
mockProcessManager
.
run
(<
String
>[
'kaboom'
])).
thenAnswer
((
_
)
{
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
return
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
1
,
''
,
''
));
command:
<
String
>[
});
'kaboom'
,
],
exitCode:
1
,
));
expect
(
expect
(
(
await
processUtils
.
run
(
(
await
processUtils
.
run
(
<
String
>[
'kaboom'
],
<
String
>[
'kaboom'
],
...
@@ -175,9 +190,12 @@ void main() {
...
@@ -175,9 +190,12 @@ void main() {
});
});
testWithoutContext
(
' throws on disallowed failure'
,
()
async
{
testWithoutContext
(
' throws on disallowed failure'
,
()
async
{
when
(
mockProcessManager
.
run
(<
String
>[
'kaboom'
])).
thenAnswer
((
_
)
{
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
return
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
2
,
''
,
''
));
command:
<
String
>[
});
'kaboom'
,
],
exitCode:
2
,
));
expect
(
expect
(
()
=>
processUtils
.
run
(
()
=>
processUtils
.
run
(
<
String
>[
'kaboom'
],
<
String
>[
'kaboom'
],
...
@@ -252,12 +270,12 @@ void main() {
...
@@ -252,12 +270,12 @@ void main() {
});
});
group
(
'runSync'
,
()
{
group
(
'runSync'
,
()
{
ProcessManager
mock
ProcessManager
;
FakeProcessManager
fake
ProcessManager
;
ProcessUtils
processUtils
;
ProcessUtils
processUtils
;
BufferLogger
testLogger
;
BufferLogger
testLogger
;
setUp
(()
{
setUp
(()
{
mockProcessManager
=
MockProcessManager
(
);
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]
);
testLogger
=
BufferLogger
(
testLogger
=
BufferLogger
(
terminal:
AnsiTerminal
(
terminal:
AnsiTerminal
(
stdio:
MockStdio
(),
stdio:
MockStdio
(),
...
@@ -266,30 +284,39 @@ void main() {
...
@@ -266,30 +284,39 @@ void main() {
outputPreferences:
OutputPreferences
(
wrapText:
true
,
wrapColumn:
40
),
outputPreferences:
OutputPreferences
(
wrapText:
true
,
wrapColumn:
40
),
);
);
processUtils
=
ProcessUtils
(
processUtils
=
ProcessUtils
(
processManager:
mock
ProcessManager
,
processManager:
fake
ProcessManager
,
logger:
testLogger
,
logger:
testLogger
,
);
);
});
});
testWithoutContext
(
' succeeds on success'
,
()
async
{
testWithoutContext
(
' succeeds on success'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'whoohoo'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
0
,
''
,
''
)
command:
<
String
>[
);
'whoohoo'
,
],
));
expect
(
processUtils
.
runSync
(<
String
>[
'whoohoo'
]).
exitCode
,
0
);
expect
(
processUtils
.
runSync
(<
String
>[
'whoohoo'
]).
exitCode
,
0
);
});
});
testWithoutContext
(
' fails on failure'
,
()
async
{
testWithoutContext
(
' fails on failure'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'boohoo'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
1
,
''
,
''
)
command:
<
String
>[
);
'boohoo'
,
],
exitCode:
1
,
));
expect
(
processUtils
.
runSync
(<
String
>[
'boohoo'
]).
exitCode
,
1
);
expect
(
processUtils
.
runSync
(<
String
>[
'boohoo'
]).
exitCode
,
1
);
});
});
testWithoutContext
(
'throws on failure with throwOnError'
,
()
async
{
testWithoutContext
(
'throws on failure with throwOnError'
,
()
async
{
const
String
stderr
=
'Something went wrong.'
;
const
String
stderr
=
'Something went wrong.'
;
when
(
mockProcessManager
.
runSync
(<
String
>[
'kaboom'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
1
,
''
,
stderr
),
command:
<
String
>[
);
'kaboom'
,
],
exitCode:
1
,
stderr:
stderr
,
));
try
{
try
{
processUtils
.
runSync
(<
String
>[
'kaboom'
],
throwOnError:
true
);
processUtils
.
runSync
(<
String
>[
'kaboom'
],
throwOnError:
true
);
fail
(
'ProcessException expected.'
);
fail
(
'ProcessException expected.'
);
...
@@ -301,9 +328,13 @@ void main() {
...
@@ -301,9 +328,13 @@ void main() {
testWithoutContext
(
'throws with stderr in exception on failure with verboseExceptions'
,
()
async
{
testWithoutContext
(
'throws with stderr in exception on failure with verboseExceptions'
,
()
async
{
const
String
stderr
=
'Something went wrong.'
;
const
String
stderr
=
'Something went wrong.'
;
when
(
mockProcessManager
.
runSync
(<
String
>[
'verybad'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
1
,
''
,
stderr
),
command:
<
String
>[
);
'verybad'
,
],
exitCode:
1
,
stderr:
stderr
,
));
expect
(
expect
(
()
=>
processUtils
.
runSync
(
()
=>
processUtils
.
runSync
(
<
String
>[
'verybad'
],
<
String
>[
'verybad'
],
...
@@ -315,9 +346,12 @@ void main() {
...
@@ -315,9 +346,12 @@ void main() {
});
});
testWithoutContext
(
' does not throw on allowed Failures'
,
()
async
{
testWithoutContext
(
' does not throw on allowed Failures'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'kaboom'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
1
,
''
,
''
)
command:
<
String
>[
);
'kaboom'
,
],
exitCode:
1
,
));
expect
(
expect
(
processUtils
.
runSync
(
processUtils
.
runSync
(
<
String
>[
'kaboom'
],
<
String
>[
'kaboom'
],
...
@@ -328,9 +362,12 @@ void main() {
...
@@ -328,9 +362,12 @@ void main() {
});
});
testWithoutContext
(
' throws on disallowed failure'
,
()
async
{
testWithoutContext
(
' throws on disallowed failure'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'kaboom'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
2
,
''
,
''
)
command:
<
String
>[
);
'kaboom'
,
],
exitCode:
2
,
));
expect
(
expect
(
()
=>
processUtils
.
runSync
(
()
=>
processUtils
.
runSync
(
<
String
>[
'kaboom'
],
<
String
>[
'kaboom'
],
...
@@ -341,18 +378,27 @@ void main() {
...
@@ -341,18 +378,27 @@ void main() {
});
});
testWithoutContext
(
' prints stdout and stderr to trace on success'
,
()
async
{
testWithoutContext
(
' prints stdout and stderr to trace on success'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'whoohoo'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
0
,
'stdout'
,
'stderr'
)
command:
<
String
>[
);
'whoohoo'
,
],
stdout:
'stdout'
,
stderr:
'stderr'
,
));
expect
(
processUtils
.
runSync
(<
String
>[
'whoohoo'
]).
exitCode
,
0
);
expect
(
processUtils
.
runSync
(<
String
>[
'whoohoo'
]).
exitCode
,
0
);
expect
(
testLogger
.
traceText
,
contains
(
'stdout'
));
expect
(
testLogger
.
traceText
,
contains
(
'stdout'
));
expect
(
testLogger
.
traceText
,
contains
(
'stderr'
));
expect
(
testLogger
.
traceText
,
contains
(
'stderr'
));
});
});
testWithoutContext
(
' prints stdout to status and stderr to error on failure with throwOnError'
,
()
async
{
testWithoutContext
(
' prints stdout to status and stderr to error on failure with throwOnError'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'kaboom'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
1
,
'stdout'
,
'stderr'
)
command:
<
String
>[
);
'kaboom'
,
],
exitCode:
1
,
stdout:
'stdout'
,
stderr:
'stderr'
,
));
expect
(()
=>
processUtils
.
runSync
(<
String
>[
'kaboom'
],
throwOnError:
true
),
expect
(()
=>
processUtils
.
runSync
(<
String
>[
'kaboom'
],
throwOnError:
true
),
throwsA
(
isA
<
ProcessException
>()));
throwsA
(
isA
<
ProcessException
>()));
expect
(
testLogger
.
statusText
,
contains
(
'stdout'
));
expect
(
testLogger
.
statusText
,
contains
(
'stdout'
));
...
@@ -360,9 +406,13 @@ void main() {
...
@@ -360,9 +406,13 @@ void main() {
});
});
testWithoutContext
(
' does not print stdout with hideStdout'
,
()
async
{
testWithoutContext
(
' does not print stdout with hideStdout'
,
()
async
{
when
(
mockProcessManager
.
runSync
(<
String
>[
'whoohoo'
])).
thenReturn
(
fakeProcessManager
.
addCommand
(
const
FakeCommand
(
ProcessResult
(
0
,
0
,
'stdout'
,
'stderr'
)
command:
<
String
>[
);
'whoohoo'
,
],
stdout:
'stdout'
,
stderr:
'stderr'
,
));
expect
(
processUtils
.
runSync
(<
String
>[
'whoohoo'
],
hideStdout:
true
).
exitCode
,
0
);
expect
(
processUtils
.
runSync
(<
String
>[
'whoohoo'
],
hideStdout:
true
).
exitCode
,
0
);
expect
(
testLogger
.
traceText
.
contains
(
'stdout'
),
isFalse
);
expect
(
testLogger
.
traceText
.
contains
(
'stdout'
),
isFalse
);
expect
(
testLogger
.
traceText
,
contains
(
'stderr'
));
expect
(
testLogger
.
traceText
,
contains
(
'stderr'
));
...
@@ -472,7 +522,4 @@ void main() {
...
@@ -472,7 +522,4 @@ void main() {
);
);
});
});
});
});
}
}
class
PlainMockProcessManager
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