diff --git a/packages/flutter_tools/test/general.shard/device_test.dart b/packages/flutter_tools/test/general.shard/device_test.dart index 91031fd38b..c2a27da7a8 100644 --- a/packages/flutter_tools/test/general.shard/device_test.dart +++ b/packages/flutter_tools/test/general.shard/device_test.dart @@ -4,6 +4,7 @@ import 'dart:async'; +import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/base/io.dart'; @@ -25,6 +26,8 @@ void main() { final List devices = [device1, device2, device3]; final DeviceManager deviceManager = TestDeviceManager(devices); expect(await deviceManager.getDevices(), devices); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('getDeviceById', () async { @@ -43,6 +46,8 @@ void main() { await expectDevice('Nexus 5', [device1]); await expectDevice('0553790', [device1]); await expectDevice('Nexus', [device1, device2]); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('getAllConnectedDevices caches', () async { @@ -53,6 +58,8 @@ void main() { final FakeDevice device2 = FakeDevice('Nexus 5X', '01abfc49119c410e'); deviceManager.resetDevices([device2]); expect(await deviceManager.getAllConnectedDevices(), [device1]); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('refreshAllConnectedDevices does not cache', () async { @@ -63,6 +70,8 @@ void main() { final FakeDevice device2 = FakeDevice('Nexus 5X', '01abfc49119c410e'); deviceManager.resetDevices([device2]); expect(await deviceManager.refreshAllConnectedDevices(), [device2]); + }, overrides: { + Artifacts: () => Artifacts.test(), }); }); @@ -83,6 +92,8 @@ void main() { expect(pollingDeviceDiscovery.lastPollingTimeout, const Duration(seconds: 30)); await pollingDeviceDiscovery.stopPolling(); }); + }, overrides: { + Artifacts: () => Artifacts.test(), }); }); @@ -117,6 +128,8 @@ void main() { final List filtered = await deviceManager.findTargetDevices(FlutterProject.current()); expect(filtered.single, ephemeral); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('does not remove all non-ephemeral', () async { @@ -132,6 +145,8 @@ void main() { nonEphemeralOne, nonEphemeralTwo, ]); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('Removes a single unsupported device', () async { @@ -143,6 +158,8 @@ void main() { final List filtered = await deviceManager.findTargetDevices(FlutterProject.current()); expect(filtered, []); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('Removes web and fuchsia from --all', () async { @@ -156,6 +173,8 @@ void main() { final List filtered = await deviceManager.findTargetDevices(FlutterProject.current()); expect(filtered, []); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('Removes unsupported devices from --all', () async { @@ -173,6 +192,8 @@ void main() { nonEphemeralOne, nonEphemeralTwo, ]); + }, overrides: { + Artifacts: () => Artifacts.test(), }); testUsingContext('uses DeviceManager.isDeviceSupportedForProject instead of device.isSupportedForProject', () async { @@ -187,6 +208,8 @@ void main() { expect(filtered, [ unsupported, ]); + }, overrides: { + Artifacts: () => Artifacts.test(), }); }); group('ForwardedPort', () { diff --git a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart index 28f426fecf..89772864dd 100644 --- a/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart +++ b/packages/flutter_tools/test/general.shard/fuchsia/fuchsia_device_test.dart @@ -17,6 +17,7 @@ import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/time.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/fuchsia/amber_ctl.dart'; import 'package:flutter_tools/src/fuchsia/application_package.dart'; @@ -791,28 +792,36 @@ void main() { }); testUsingContext('Correct flutter runner', () async { - expect(globals.artifacts.getArtifactPath( + final MockCache cache = MockCache(); + final FileSystem fileSystem = MemoryFileSystem.test(); + when(cache.getArtifactDirectory('flutter_runner')).thenReturn(fileSystem.directory('fuchsia')); + final CachedArtifacts artifacts = CachedArtifacts( + cache: cache, + fileSystem: fileSystem, + platform: FakePlatform(operatingSystem: 'linux'), + ); + expect(artifacts.getArtifactPath( Artifact.fuchsiaFlutterRunner, platform: TargetPlatform.fuchsia_x64, mode: BuildMode.debug, ), contains('flutter_jit_runner'), ); - expect(globals.artifacts.getArtifactPath( + expect(artifacts.getArtifactPath( Artifact.fuchsiaFlutterRunner, platform: TargetPlatform.fuchsia_x64, mode: BuildMode.profile, ), contains('flutter_aot_runner'), ); - expect(globals.artifacts.getArtifactPath( + expect(artifacts.getArtifactPath( Artifact.fuchsiaFlutterRunner, platform: TargetPlatform.fuchsia_x64, mode: BuildMode.release, ), contains('flutter_aot_product_runner'), ); - expect(globals.artifacts.getArtifactPath( + expect(artifacts.getArtifactPath( Artifact.fuchsiaFlutterRunner, platform: TargetPlatform.fuchsia_x64, mode: BuildMode.jitRelease, @@ -1550,3 +1559,4 @@ class MockFuchsiaSdk extends Mock implements FuchsiaSdk { } class MockFuchsiaWorkflow extends Mock implements FuchsiaWorkflow {} +class MockCache extends Mock implements Cache {} diff --git a/packages/flutter_tools/test/general.shard/hot_test.dart b/packages/flutter_tools/test/general.shard/hot_test.dart index 1f786394b1..2ffd67bc38 100644 --- a/packages/flutter_tools/test/general.shard/hot_test.dart +++ b/packages/flutter_tools/test/general.shard/hot_test.dart @@ -4,6 +4,10 @@ import 'dart:async'; +import 'package:file/memory.dart'; +import 'package:flutter_tools/src/base/file_system.dart'; +import 'package:flutter_tools/src/base/platform.dart'; +import 'package:flutter_tools/src/dart/package_map.dart'; import 'package:vm_service/vm_service.dart' as vm_service; import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/base/io.dart'; @@ -131,7 +135,7 @@ void main() { group('hotRestart', () { final MockResidentCompiler residentCompiler = MockResidentCompiler(); final MockDevFs mockDevFs = MockDevFs(); - MockLocalEngineArtifacts mockArtifacts; + FileSystem fileSystem; when(mockDevFs.update( mainUri: anyNamed('mainUri'), @@ -155,11 +159,13 @@ void main() { when(mockDevFs.lastCompiled).thenReturn(DateTime.now()); setUp(() { - mockArtifacts = MockLocalEngineArtifacts(); - when(mockArtifacts.getArtifactPath(Artifact.flutterPatchedSdkPath)).thenReturn('some/path'); + fileSystem = MemoryFileSystem.test(); }); testUsingContext('Does not hot restart when device does not support it', () async { + fileSystem.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); // Setup mocks final MockDevice mockDevice = MockDevice(); when(mockDevice.supportsHotReload).thenReturn(true); @@ -174,11 +180,17 @@ void main() { expect(result.isOk, false); expect(result.message, 'hotRestart not supported'); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true), + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('Does not hot restart when one of many devices does not support it', () async { + fileSystem.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); // Setup mocks final MockDevice mockDevice = MockDevice(); final MockDevice mockHotDevice = MockDevice(); @@ -196,8 +208,11 @@ void main() { expect(result.isOk, false); expect(result.message, 'hotRestart not supported'); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true), + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('Does hot restarts when all devices support it', () async { @@ -294,11 +309,17 @@ void main() { expect(result.isOk, true); expect(result.message, isNot('hotRestart not supported')); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true), + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('setup function fails', () async { + fileSystem.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); final MockDevice mockDevice = MockDevice(); when(mockDevice.supportsHotReload).thenReturn(true); when(mockDevice.supportsHotRestart).thenReturn(true); @@ -310,11 +331,17 @@ void main() { expect(result.isOk, false); expect(result.message, 'setupHotRestart failed'); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: false), + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('hot restart supported', () async { + fileSystem.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); // Setup mocks final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, @@ -369,8 +396,11 @@ void main() { expect(result.isOk, true); expect(result.message, isNot('setupHotRestart failed')); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true), + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); group('shutdown hook tests', () { @@ -383,6 +413,9 @@ void main() { }); testUsingContext('shutdown hook called after signal', () async { + fileSystem.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); final MockDevice mockDevice = MockDevice(); when(mockDevice.supportsHotReload).thenReturn(true); when(mockDevice.supportsHotRestart).thenReturn(true); @@ -393,11 +426,17 @@ void main() { await HotRunner(devices).cleanupAfterSignal(); expect(shutdownTestingConfig.shutdownHookCalled, true); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => shutdownTestingConfig, + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('shutdown hook called after app stop', () async { + fileSystem.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); final MockDevice mockDevice = MockDevice(); when(mockDevice.supportsHotReload).thenReturn(true); when(mockDevice.supportsHotRestart).thenReturn(true); @@ -408,21 +447,28 @@ void main() { await HotRunner(devices).preExit(); expect(shutdownTestingConfig.shutdownHookCalled, true); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => shutdownTestingConfig, + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); }); }); group('hot attach', () { - MockLocalEngineArtifacts mockArtifacts; + FileSystem fileSystem; setUp(() { - mockArtifacts = MockLocalEngineArtifacts(); + fileSystem = MemoryFileSystem.test(); }); testUsingContext('Exits with code 2 when when HttpException is thrown ' 'during VM service connection', () async { + fileSystem.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); + final MockResidentCompiler residentCompiler = MockResidentCompiler(); final MockDevice mockDevice = MockDevice(); when(mockDevice.supportsHotReload).thenReturn(true); @@ -444,8 +490,11 @@ void main() { ).attach(); expect(exitCode, 2); }, overrides: { - Artifacts: () => mockArtifacts, HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true), + Artifacts: () => Artifacts.test(), + FileSystem: () => fileSystem, + Platform: () => FakePlatform(operatingSystem: 'linux'), + ProcessManager: () => FakeProcessManager.any(), }); }); @@ -482,8 +531,6 @@ void main() { class MockDevFs extends Mock implements DevFS {} -class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {} - class MockDevice extends Mock implements Device { MockDevice() { when(isSupported()).thenReturn(true); diff --git a/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart index 0bae7ec620..4b961dc132 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart @@ -92,6 +92,9 @@ void main() { ); mockXcode = MockXcode(); when(mockXcode.isVersionSatisfactory).thenReturn(true); + fileSystem.file('foo/.packages') + ..createSync(recursive: true) + ..writeAsStringSync('\n'); }); testUsingContext('with buildable app', () async { diff --git a/packages/flutter_tools/test/general.shard/ios/simulators_test.dart b/packages/flutter_tools/test/general.shard/ios/simulators_test.dart index 71dafd946b..72bb8d9e9e 100644 --- a/packages/flutter_tools/test/general.shard/ios/simulators_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/simulators_test.dart @@ -37,6 +37,13 @@ class MockXcode extends Mock implements Xcode {} class MockSimControl extends Mock implements SimControl {} class MockPlistUtils extends Mock implements PlistParser {} +final Platform macosPlatform = FakePlatform( + operatingSystem: 'macos', + environment: { + 'HOME': '/' + }, +); + void main() { FakePlatform osx; FileSystemUtils fsUtils; @@ -458,12 +465,11 @@ void main() { overrides: { ProcessManager: () => mockProcessManager, FileSystem: () => fileSystem, - Platform: () => FakePlatform( - operatingSystem: 'macos', - environment: { - 'HOME': '/' - }, - ), + Platform: () => macosPlatform, + FileSystemUtils: () => FileSystemUtils( + fileSystem: fileSystem, + platform: macosPlatform, + ) }); testUsingContext('unified logging with app name', () async { diff --git a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart index d313014db7..f51f3609a4 100644 --- a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart +++ b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart @@ -43,7 +43,6 @@ void main() { void podsIsInHomeDir() { fileSystem.directory(fileSystem.path.join( - globals.fsUtils.homeDirPath, '.cocoapods', 'repos', 'master', @@ -52,7 +51,6 @@ void main() { String podsIsInCustomDir({String cocoapodsReposDir}) { cocoapodsReposDir ??= fileSystem.path.join( - globals.fsUtils.homeDirPath, 'cache', 'cocoapods', 'repos', @@ -292,6 +290,9 @@ void main() { group('Update xcconfig', () { testUsingContext('includes Pod config in xcconfig files, if the user manually added Pod dependencies without using Flutter plugins', () async { + globals.fs.file(globals.fs.path.join('project', 'foo', '.packages')) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); projectUnderTest.ios.podfile..createSync()..writeAsStringSync('Custom Podfile'); projectUnderTest.ios.podfileLock..createSync()..writeAsStringSync('Podfile.lock from user executed `pod install`'); projectUnderTest.packagesFile..createSync()..writeAsStringSync(''); diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index b0445a0fc3..90ac124ae8 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'package:flutter_tools/src/cache.dart'; +import 'package:flutter_tools/src/dart/package_map.dart'; import 'package:vm_service/vm_service.dart' as vm_service; import 'package:file/memory.dart'; import 'package:file_testing/file_testing.dart'; @@ -92,7 +93,7 @@ void main() { setUp(() { testbed = Testbed(setup: () { - globals.fs.file('.packages').writeAsStringSync('\n'); + globals.fs.file(globalPackagesPath).writeAsStringSync('\n'); globals.fs.file(globals.fs.path.join('build', 'app.dill')) ..createSync(recursive: true) ..writeAsStringSync('ABC'); @@ -844,6 +845,11 @@ void main() { 'data': {'A': 'B'} }); expect(fakeVmServiceHost.hasRemainingExpectations, false); + }, overrides: { + FileSystemUtils: () => FileSystemUtils( + fileSystem: globals.fs, + platform: globals.platform, + ) })); testUsingContext('ResidentRunner can take screenshot on debug device', () => testbed.run(() async { diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index 21faf56cb2..17d0ea3ade 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -16,6 +16,7 @@ import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_runner/devfs_web.dart'; import 'package:flutter_tools/src/build_runner/resident_web_runner.dart'; import 'package:flutter_tools/src/compile.dart'; +import 'package:flutter_tools/src/dart/package_map.dart'; import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/device.dart'; @@ -115,6 +116,9 @@ void main() { }); testbed = Testbed( setup: () { + globals.fs.file(globalPackagesPath) + ..createSync(recursive: true) + ..writeAsStringSync('\n'); residentWebRunner = DwdsWebRunnerFactory().createWebRunner( mockFlutterDevice, flutterProject: FlutterProject.current(), diff --git a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart index 53d4cfb600..e6baf6524e 100644 --- a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart +++ b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart @@ -43,7 +43,9 @@ void main() { MockHttpServer mockHttpServer; setUpAll(() async { - packages = await loadPackageConfigUri(Uri.base.resolve('.packages')); + packages = PackageConfig([ + Package('flutter_tools', Uri.file('/flutter_tools/lib/').normalizePath()) + ]); }); setUp(() {