Unverified Commit 5cfcae00 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] fix tests that depend on correct cache existance (#60241)

These tests will hit the real Cache, failing if the flutter root has been modified
parent a0334fb5
...@@ -7,6 +7,7 @@ import 'dart:convert'; ...@@ -7,6 +7,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:flutter_tools/src/android/android_sdk.dart'; import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/devices.dart'; import 'package:flutter_tools/src/commands/devices.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
...@@ -23,9 +24,19 @@ void main() { ...@@ -23,9 +24,19 @@ void main() {
Cache.disableLocking(); Cache.disableLocking();
}); });
MockCache cache;
setUp(() {
cache = MockCache();
when(cache.dyLdLibEntry).thenReturn(const MapEntry<String, String>('foo', 'bar'));
});
testUsingContext('returns 0 when called', () async { testUsingContext('returns 0 when called', () async {
final DevicesCommand command = DevicesCommand(); final DevicesCommand command = DevicesCommand();
await createTestCommandRunner(command).run(<String>['devices']); await createTestCommandRunner(command).run(<String>['devices']);
}, overrides: <Type, Generator>{
Cache: () => cache,
Artifacts: () => Artifacts.test(),
}); });
testUsingContext('no error when no connected devices', () async { testUsingContext('no error when no connected devices', () async {
...@@ -36,6 +47,8 @@ void main() { ...@@ -36,6 +47,8 @@ void main() {
AndroidSdk: () => null, AndroidSdk: () => null,
DeviceManager: () => NoDevicesManager(), DeviceManager: () => NoDevicesManager(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Cache: () => cache,
Artifacts: () => Artifacts.test(),
}); });
testUsingContext('get devices\' platform types', () async { testUsingContext('get devices\' platform types', () async {
...@@ -46,6 +59,8 @@ void main() { ...@@ -46,6 +59,8 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(), DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Cache: () => cache,
Artifacts: () => Artifacts.test(),
}); });
testUsingContext('Outputs parsable JSON with --machine flag', () async { testUsingContext('Outputs parsable JSON with --machine flag', () async {
...@@ -93,6 +108,8 @@ void main() { ...@@ -93,6 +108,8 @@ void main() {
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
DeviceManager: () => _FakeDeviceManager(), DeviceManager: () => _FakeDeviceManager(),
ProcessManager: () => MockProcessManager(), ProcessManager: () => MockProcessManager(),
Cache: () => cache,
Artifacts: () => Artifacts.test(),
}); });
testUsingContext('available devices and diagnostics', () async { testUsingContext('available devices and diagnostics', () async {
...@@ -169,3 +186,5 @@ class NoDevicesManager extends DeviceManager { ...@@ -169,3 +186,5 @@ class NoDevicesManager extends DeviceManager {
Future<List<Device>> refreshAllConnectedDevices({Duration timeout}) => Future<List<Device>> refreshAllConnectedDevices({Duration timeout}) =>
getAllConnectedDevices(); getAllConnectedDevices();
} }
class MockCache extends Mock implements Cache {}
...@@ -6,6 +6,7 @@ import 'dart:async'; ...@@ -6,6 +6,7 @@ import 'dart:async';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
...@@ -18,6 +19,13 @@ import '../src/fake_devices.dart'; ...@@ -18,6 +19,13 @@ import '../src/fake_devices.dart';
import '../src/mocks.dart'; import '../src/mocks.dart';
void main() { void main() {
MockCache cache;
setUp(() {
cache = MockCache();
when(cache.dyLdLibEntry).thenReturn(const MapEntry<String, String>('foo', 'bar'));
});
group('DeviceManager', () { group('DeviceManager', () {
testUsingContext('getDevices', () async { testUsingContext('getDevices', () async {
final FakeDevice device1 = FakeDevice('Nexus 5', '0553790d0a4e726f'); final FakeDevice device1 = FakeDevice('Nexus 5', '0553790d0a4e726f');
...@@ -28,6 +36,7 @@ void main() { ...@@ -28,6 +36,7 @@ void main() {
expect(await deviceManager.getDevices(), devices); expect(await deviceManager.getDevices(), devices);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('getDeviceById', () async { testUsingContext('getDeviceById', () async {
...@@ -48,6 +57,7 @@ void main() { ...@@ -48,6 +57,7 @@ void main() {
await expectDevice('Nexus', <Device>[device1, device2]); await expectDevice('Nexus', <Device>[device1, device2]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('getAllConnectedDevices caches', () async { testUsingContext('getAllConnectedDevices caches', () async {
...@@ -60,6 +70,7 @@ void main() { ...@@ -60,6 +70,7 @@ void main() {
expect(await deviceManager.getAllConnectedDevices(), <Device>[device1]); expect(await deviceManager.getAllConnectedDevices(), <Device>[device1]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('refreshAllConnectedDevices does not cache', () async { testUsingContext('refreshAllConnectedDevices does not cache', () async {
...@@ -72,6 +83,7 @@ void main() { ...@@ -72,6 +83,7 @@ void main() {
expect(await deviceManager.refreshAllConnectedDevices(), <Device>[device2]); expect(await deviceManager.refreshAllConnectedDevices(), <Device>[device2]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
}); });
...@@ -94,6 +106,7 @@ void main() { ...@@ -94,6 +106,7 @@ void main() {
}); });
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
}); });
...@@ -130,6 +143,7 @@ void main() { ...@@ -130,6 +143,7 @@ void main() {
expect(filtered.single, ephemeral); expect(filtered.single, ephemeral);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('does not remove all non-ephemeral', () async { testUsingContext('does not remove all non-ephemeral', () async {
...@@ -147,6 +161,7 @@ void main() { ...@@ -147,6 +161,7 @@ void main() {
]); ]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('Removes a single unsupported device', () async { testUsingContext('Removes a single unsupported device', () async {
...@@ -160,6 +175,7 @@ void main() { ...@@ -160,6 +175,7 @@ void main() {
expect(filtered, <Device>[]); expect(filtered, <Device>[]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('Removes web and fuchsia from --all', () async { testUsingContext('Removes web and fuchsia from --all', () async {
...@@ -175,6 +191,7 @@ void main() { ...@@ -175,6 +191,7 @@ void main() {
expect(filtered, <Device>[]); expect(filtered, <Device>[]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('Removes unsupported devices from --all', () async { testUsingContext('Removes unsupported devices from --all', () async {
...@@ -194,6 +211,7 @@ void main() { ...@@ -194,6 +211,7 @@ void main() {
]); ]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
testUsingContext('uses DeviceManager.isDeviceSupportedForProject instead of device.isSupportedForProject', () async { testUsingContext('uses DeviceManager.isDeviceSupportedForProject instead of device.isSupportedForProject', () async {
...@@ -210,6 +228,7 @@ void main() { ...@@ -210,6 +228,7 @@ void main() {
]); ]);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(), Artifacts: () => Artifacts.test(),
Cache: () => cache,
}); });
}); });
group('ForwardedPort', () { group('ForwardedPort', () {
...@@ -267,3 +286,4 @@ class TestDeviceManager extends DeviceManager { ...@@ -267,3 +286,4 @@ class TestDeviceManager extends DeviceManager {
} }
class MockProcess extends Mock implements Process {} class MockProcess extends Mock implements Process {}
class MockCache extends Mock implements Cache {}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/resident_runner.dart'; import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
...@@ -27,6 +28,7 @@ void main() { ...@@ -27,6 +28,7 @@ void main() {
trackWidgetCreation: false, trackWidgetCreation: false,
treeShakeIcons: false, treeShakeIcons: false,
), ),
generator: MockResidentCompiler(),
), ),
], ],
); );
...@@ -413,12 +415,12 @@ class MockDevice extends Mock implements Device { ...@@ -413,12 +415,12 @@ class MockDevice extends Mock implements Device {
} }
class MockResidentRunner extends Mock implements ResidentRunner {} class MockResidentRunner extends Mock implements ResidentRunner {}
class MockFlutterDevice extends Mock implements FlutterDevice {} class MockFlutterDevice extends Mock implements FlutterDevice {}
class MockResidentCompiler extends Mock implements ResidentCompiler {}
class TestRunner extends ResidentRunner { class TestRunner extends ResidentRunner {
TestRunner(List<FlutterDevice> devices) TestRunner(List<FlutterDevice> devices)
: super(devices); : super(devices, debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug));
bool hasHelpBeenPrinted = false; bool hasHelpBeenPrinted = false;
String receivedCommand; String receivedCommand;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment