diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 1e225dd5f1..640eb06783 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -587,7 +587,9 @@ class AppDomain extends Domain { 'trace': '$trace', }); } finally { - globals.fs.currentDirectory = cwd; + // If the full directory is used instead of the path then this causes + // a TypeError with the ErrorHandlingFileSystem. + globals.fs.currentDirectory = cwd.path; _apps.remove(app); } }); diff --git a/packages/flutter_tools/test/general.shard/base/error_handling_file_system_test.dart b/packages/flutter_tools/test/general.shard/base/error_handling_file_system_test.dart index 6ec5ed64b5..6922ac1569 100644 --- a/packages/flutter_tools/test/general.shard/base/error_handling_file_system_test.dart +++ b/packages/flutter_tools/test/general.shard/base/error_handling_file_system_test.dart @@ -4,6 +4,7 @@ import 'package:file/file.dart'; import 'package:flutter_tools/src/base/error_handling_file_system.dart'; +import 'package:flutter_tools/src/base/file_system.dart'; import 'package:mockito/mockito.dart'; import 'package:platform/platform.dart'; import 'package:path/path.dart' as path; // ignore: package_path_import @@ -14,8 +15,13 @@ import '../../src/testbed.dart'; class MockFile extends Mock implements File {} class MockFileSystem extends Mock implements FileSystem {} -class MockPlatform extends Mock implements Platform {} class MockPathContext extends Mock implements path.Context {} +class MockDirectory extends Mock implements Directory {} + +final Platform windowsPlatform = FakePlatform( + operatingSystem: 'windows', + environment: {} +); void main() { group('throws ToolExit on Windows', () { @@ -23,17 +29,11 @@ void main() { const int kUserMappedSectionOpened = 1224; Testbed testbed; MockFileSystem mockFileSystem; - MockPlatform windowsPlatform; ErrorHandlingFileSystem fs; setUp(() { mockFileSystem = MockFileSystem(); fs = ErrorHandlingFileSystem(mockFileSystem); - - windowsPlatform = MockPlatform(); - when(windowsPlatform.isWindows).thenReturn(true); - when(windowsPlatform.isLinux).thenReturn(false); - when(windowsPlatform.isMacOS).thenReturn(false); when(mockFileSystem.path).thenReturn(MockPathContext()); testbed = Testbed(overrides: { Platform: () => windowsPlatform, @@ -119,6 +119,14 @@ void main() { expect(identical(firstPath, fs.path), false); }); + test('Throws type error if Directory type is set to curentDirectory with LocalFileSystem', () { + final FileSystem fs = ErrorHandlingFileSystem(const LocalFileSystem()); + final MockDirectory directory = MockDirectory(); + when(directory.path).thenReturn('path'); + + expect(() => fs.currentDirectory = directory, throwsA(isA())); + }); + group('toString() gives toString() of delegate', () { test('ErrorHandlingFileSystem', () { final MockFileSystem mockFileSystem = MockFileSystem();