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
fb5632dc
Unverified
Commit
fb5632dc
authored
Jan 16, 2020
by
Jonah Williams
Committed by
GitHub
Jan 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Only remove ProcessUtils from injection (#48975)
parent
d0161464
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
72 deletions
+68
-72
android_device_test.dart
...tools/test/general.shard/android/android_device_test.dart
+31
-50
fuchsia_device_test.dart
...tools/test/general.shard/fuchsia/fuchsia_device_test.dart
+11
-14
testbed_test.dart
packages/flutter_tools/test/general.shard/testbed_test.dart
+10
-0
web_fs_test.dart
...ges/flutter_tools/test/general.shard/web/web_fs_test.dart
+8
-8
context.dart
packages/flutter_tools/test/src/context.dart
+4
-0
testbed.dart
packages/flutter_tools/test/src/testbed.dart
+4
-0
No files found.
packages/flutter_tools/test/general.shard/android/android_device_test.dart
View file @
fb5632dc
...
...
@@ -13,7 +13,6 @@ import 'package:flutter_tools/src/android/android_sdk.dart';
import
'package:flutter_tools/src/application_package.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/project.dart'
;
...
...
@@ -44,45 +43,6 @@ class MockAndroidApk extends Mock implements AndroidApk {
File
get
file
=>
MockFile
();
}
class
MockProcessUtils
extends
Mock
implements
ProcessUtils
{
@override
Future
<
RunResult
>
run
(
List
<
String
>
cmd
,
{
bool
throwOnError
=
false
,
RunResultChecker
whiteListFailures
,
String
workingDirectory
,
bool
allowReentrantFlutter
=
false
,
Map
<
String
,
String
>
environment
,
Duration
timeout
,
int
timeoutRetries
=
0
,
})
async
{
if
(
cmd
.
contains
(
'version'
))
{
return
RunResult
(
ProcessResult
(
0
,
0
,
'Android Debug Bridge version 1.0.41'
,
''
),
cmd
);
}
if
(
cmd
.
contains
(
'android.intent.action.RUN'
))
{
_runCmd
=
cmd
;
}
return
RunResult
(
ProcessResult
(
0
,
0
,
''
,
''
),
cmd
);
}
@override
Future
<
int
>
stream
(
List
<
String
>
cmd
,
{
String
workingDirectory
,
bool
allowReentrantFlutter
=
false
,
String
prefix
=
''
,
bool
trace
=
false
,
RegExp
filter
,
StringConverter
mapFunction
,
Map
<
String
,
String
>
environment
,
})
async
{
return
0
;
}
List
<
String
>
_runCmd
;
List
<
String
>
get
runCmd
=>
_runCmd
;
}
class
MockAndroidSdkVersion
extends
Mock
implements
AndroidSdkVersion
{}
void
main
(
)
{
...
...
@@ -97,13 +57,11 @@ void main() {
MockAndroidApk
mockApk
;
MockProcessManager
mockProcessManager
;
MockAndroidSdk
mockAndroidSdk
;
MockProcessUtils
mockProcessUtils
;
setUp
(()
{
mockApk
=
MockAndroidApk
();
mockProcessManager
=
MockProcessManager
();
mockAndroidSdk
=
MockAndroidSdk
();
mockProcessUtils
=
MockProcessUtils
();
});
testUsingContext
(
'succeeds with --cache-sksl'
,
()
async
{
...
...
@@ -124,6 +82,20 @@ void main() {
)).
thenAnswer
((
_
)
async
{
return
ProcessResult
(
0
,
0
,
'[ro.build.version.sdk]: [24]'
,
''
);
});
when
(
mockProcessManager
.
run
(
any
,
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
)
)).
thenAnswer
((
_
)
async
{
return
ProcessResult
(
0
,
0
,
''
,
''
);
});
when
(
mockProcessManager
.
start
(
any
,
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
)
)).
thenAnswer
((
_
)
async
{
return
FakeProcess
();
});
final
LaunchResult
launchResult
=
await
device
.
startApp
(
mockApk
,
...
...
@@ -134,18 +106,14 @@ void main() {
),
platformArgs:
<
String
,
dynamic
>{},
);
expect
(
launchResult
.
started
,
isTrue
);
final
int
cmdIndex
=
mockProcessUtils
.
runCmd
.
indexOf
(
'cache-sksl'
);
expect
(
mockProcessUtils
.
runCmd
.
sublist
(
cmdIndex
-
1
,
cmdIndex
+
2
),
equals
(<
String
>[
'--ez'
,
'cache-sksl'
,
'true'
]),
);
expect
(
launchResult
.
started
,
isTrue
);
expect
(
verify
(
mockProcessManager
.
run
(
captureAny
)).
captured
.
last
.
join
(
','
),
contains
(<
String
>[
'--ez'
,
'cache-sksl'
,
'true'
].
join
(
','
)));
},
overrides:
<
Type
,
Generator
>{
AndroidSdk:
()
=>
mockAndroidSdk
,
FileSystem:
()
=>
MemoryFileSystem
(),
ProcessManager:
()
=>
mockProcessManager
,
ProcessUtils:
()
=>
mockProcessUtils
,
});
testUsingContext
(
'can run a release build on x64'
,
()
async
{
...
...
@@ -166,6 +134,20 @@ void main() {
)).
thenAnswer
((
_
)
async
{
return
ProcessResult
(
0
,
0
,
'[ro.build.version.sdk]: [24]
\n
[ro.product.cpu.abi]: [x86_64]'
,
''
);
});
when
(
mockProcessManager
.
run
(
any
,
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
)
)).
thenAnswer
((
_
)
async
{
return
ProcessResult
(
0
,
0
,
''
,
''
);
});
when
(
mockProcessManager
.
start
(
any
,
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
)
)).
thenAnswer
((
_
)
async
{
return
FakeProcess
();
});
final
LaunchResult
launchResult
=
await
device
.
startApp
(
mockApk
,
...
...
@@ -180,7 +162,6 @@ void main() {
AndroidSdk:
()
=>
mockAndroidSdk
,
FileSystem:
()
=>
MemoryFileSystem
(),
ProcessManager:
()
=>
mockProcessManager
,
ProcessUtils:
()
=>
mockProcessUtils
,
});
});
});
...
...
packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart
View file @
fb5632dc
...
...
@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/base/common.dart';
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/base/time.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
...
...
@@ -30,8 +29,8 @@ import 'package:flutter_tools/src/project.dart';
import
'package:flutter_tools/src/vmservice.dart'
;
import
'package:meta/meta.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'package:platform/platform.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -40,11 +39,10 @@ void main() {
group
(
'fuchsia device'
,
()
{
MemoryFileSystem
memoryFileSystem
;
MockFile
sshConfig
;
MockProcessUtils
mockProcessUtils
;
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
();
sshConfig
=
MockFile
();
mockProcessUtils
=
MockProcessUtils
();
when
(
sshConfig
.
absolute
).
thenReturn
(
sshConfig
);
});
...
...
@@ -118,27 +116,27 @@ void main() {
});
testUsingContext
(
'targetPlatform arm64 works'
,
()
async
{
when
(
mockProcessUtils
.
run
(
any
)).
thenAnswer
((
Invocation
_
)
{
return
Future
<
RunResult
>.
value
(
RunResult
(
ProcessResult
(
1
,
0
,
'aarch64'
,
''
),
<
String
>[
''
])
);
when
(
globals
.
processManager
.
run
(
any
)).
thenAnswer
((
Invocation
_
)
async
{
return
ProcessResult
(
1
,
0
,
'aarch64'
,
''
);
});
final
FuchsiaDevice
device
=
FuchsiaDevice
(
'123'
);
expect
(
await
device
.
targetPlatform
,
TargetPlatform
.
fuchsia_arm64
);
},
overrides:
<
Type
,
Generator
>{
FuchsiaArtifacts:
()
=>
FuchsiaArtifacts
(
sshConfig:
sshConfig
),
FuchsiaSdk:
()
=>
MockFuchsiaSdk
(),
Process
Utils:
()
=>
mockProcessUtils
,
Process
Manager:
()
=>
MockProcessManager
()
,
});
testUsingContext
(
'targetPlatform x64 works'
,
()
async
{
when
(
mockProcessUtils
.
run
(
any
)).
thenAnswer
((
Invocation
_
)
{
return
Future
<
RunResult
>.
value
(
RunResult
(
ProcessResult
(
1
,
0
,
'x86_64'
,
''
),
<
String
>[
''
])
);
when
(
globals
.
processManager
.
run
(
any
)).
thenAnswer
((
Invocation
_
)
async
{
return
ProcessResult
(
1
,
0
,
'x86_64'
,
''
);
});
final
FuchsiaDevice
device
=
FuchsiaDevice
(
'123'
);
expect
(
await
device
.
targetPlatform
,
TargetPlatform
.
fuchsia_x64
);
},
overrides:
<
Type
,
Generator
>{
FuchsiaArtifacts:
()
=>
FuchsiaArtifacts
(
sshConfig:
sshConfig
),
FuchsiaSdk:
()
=>
MockFuchsiaSdk
(),
Process
Utils:
()
=>
mockProcessUtils
,
Process
Manager:
()
=>
MockProcessManager
()
,
});
});
...
...
@@ -326,8 +324,8 @@ void main() {
});
});
group
(
'screenshot'
,
()
{
MockProcessManager
mockProcessManager
;
group
(
'screenshot'
,
()
{
MockProcessManager
mockProcessManager
;
setUp
(()
{
mockProcessManager
=
MockProcessManager
();
...
...
@@ -550,6 +548,7 @@ void main() {
},
testOn:
'posix'
);
});
group
(
FuchsiaIsolateDiscoveryProtocol
,
()
{
MockPortForwarder
portForwarder
;
MockVMService
vmService
;
...
...
@@ -960,8 +959,6 @@ class MockProcessManager extends Mock implements ProcessManager {}
class
MockProcessResult
extends
Mock
implements
ProcessResult
{}
class
MockProcessUtils
extends
Mock
implements
ProcessUtils
{}
class
MockFile
extends
Mock
implements
File
{}
class
MockProcess
extends
Mock
implements
Process
{}
...
...
packages/flutter_tools/test/general.shard/testbed_test.dart
View file @
fb5632dc
...
...
@@ -10,9 +10,11 @@ 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/error_handling_file_system.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/testbed.dart'
;
void
main
(
)
{
...
...
@@ -87,6 +89,14 @@ void main() {
timer
.
cancel
();
});
});
test
(
'Throws if ProcessUtils is injected'
,()
{
final
Testbed
testbed
=
Testbed
(
overrides:
<
Type
,
Generator
>{
ProcessUtils:
()
=>
null
,
});
expect
(()
=>
testbed
.
run
(()
{}),
throwsA
(
isInstanceOf
<
StateError
>()));
});
});
}
...
...
packages/flutter_tools/test/general.shard/web/web_fs_test.dart
View file @
fb5632dc
...
...
@@ -8,7 +8,6 @@ import 'package:built_collection/built_collection.dart';
import
'package:dwds/asset_handler.dart'
;
import
'package:dwds/dwds.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/dart/pub.dart'
;
import
'package:flutter_tools/src/project.dart'
;
...
...
@@ -18,8 +17,10 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import
'package:http_multi_server/http_multi_server.dart'
;
import
'package:meta/meta.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'../../src/common.dart'
;
import
'../../src/mocks.dart'
;
import
'../../src/testbed.dart'
;
void
main
(
)
{
...
...
@@ -30,7 +31,7 @@ void main() {
MockHttpMultiServer
mockHttpMultiServer
;
MockBuildDaemonClient
mockBuildDaemonClient
;
MockOperatingSystemUtils
mockOperatingSystemUtils
;
MockProcess
Utils
mockProcessUtils
;
MockProcess
Manager
mockProcessManager
;
bool
lastInitializePlatform
;
dynamic
lastAddress
;
int
lastPort
;
...
...
@@ -45,7 +46,7 @@ void main() {
mockBuildDaemonClient
=
MockBuildDaemonClient
();
mockOperatingSystemUtils
=
MockOperatingSystemUtils
();
mockDwds
=
MockDwds
();
mockProcess
Utils
=
MockProcessUtils
();
mockProcess
Manager
=
MockProcessManager
();
when
(
mockBuildDaemonCreator
.
startBuildDaemon
(
any
,
release:
anyNamed
(
'release'
),
initializePlatform:
anyNamed
(
'initializePlatform'
)))
.
thenAnswer
((
Invocation
invocation
)
async
{
lastInitializePlatform
=
invocation
.
namedArguments
[
#initializePlatform
]
as
bool
;
...
...
@@ -54,15 +55,14 @@ void main() {
when
(
mockOperatingSystemUtils
.
findFreePort
()).
thenAnswer
((
Invocation
_
)
async
{
return
1234
;
});
when
(
mockProcess
Utils
.
stream
(
when
(
mockProcess
Manager
.
start
(
any
,
workingDirectory:
anyNamed
(
'workingDirectory'
),
mapFunction:
anyNamed
(
'mapFunction'
),
environment:
anyNamed
(
'environment'
),
)).
thenAnswer
((
Invocation
invocation
)
async
{
final
String
workingDirectory
=
invocation
.
namedArguments
[
#workingDirectory
]
as
String
;
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
workingDirectory
,
'.packages'
)).
createSync
(
recursive:
true
);
return
0
;
return
FakeProcess
()
;
});
when
(
mockBuildDaemonClient
.
buildResults
).
thenAnswer
((
Invocation
_
)
{
return
Stream
<
BuildResults
>.
fromFuture
(
Future
<
BuildResults
>.
value
(
...
...
@@ -93,7 +93,7 @@ void main() {
OperatingSystemUtils:
()
=>
mockOperatingSystemUtils
,
BuildDaemonCreator:
()
=>
mockBuildDaemonCreator
,
ChromeLauncher:
()
=>
mockChromeLauncher
,
Process
Utils:
()
=>
mockProcessUtils
,
Process
Manager:
()
=>
mockProcessManager
,
HttpMultiServerFactory:
()
=>
(
dynamic
address
,
int
port
)
async
{
lastAddress
=
address
;
lastPort
=
port
;
...
...
@@ -226,5 +226,5 @@ class MockDwds extends Mock implements Dwds {}
class
MockHttpMultiServer
extends
Mock
implements
HttpMultiServer
{}
class
MockChromeLauncher
extends
Mock
implements
ChromeLauncher
{}
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{}
class
MockProcessUtils
extends
Mock
implements
ProcessUtils
{}
class
MockPub
extends
Mock
implements
Pub
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
packages/flutter_tools/test/src/context.dart
View file @
fb5632dc
...
...
@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/base/signals.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/base/time.dart'
;
...
...
@@ -63,6 +64,9 @@ void testUsingContext(
'that you are dealing with in your test.'
);
}
if
(
overrides
.
containsKey
(
ProcessUtils
))
{
throw
StateError
(
'Do not inject ProcessUtils for testing, use ProcessManager instead.'
);
}
// Ensure we don't rely on the default [Config] constructor which will
// leak a sticky $HOME/.flutter_settings behind!
...
...
packages/flutter_tools/test/src/testbed.dart
View file @
fb5632dc
...
...
@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/base/process.dart'
;
import
'package:flutter_tools/src/base/signals.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
...
...
@@ -113,6 +114,9 @@ class Testbed {
// Add the test-specific overrides
...?
overrides
,
};
if
(
testOverrides
.
containsKey
(
ProcessUtils
))
{
throw
StateError
(
'Do not inject ProcessUtils for testing, use ProcessManager instead.'
);
}
// Cache the original flutter root to restore after the test case.
final
String
originalFlutterRoot
=
Cache
.
flutterRoot
;
// Track pending timers to verify that they were correctly cleaned up.
...
...
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