Unverified Commit 8e492fa8 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] fix type error with AppDomain current directory (#53181)

parent b5cd3ce8
...@@ -587,7 +587,9 @@ class AppDomain extends Domain { ...@@ -587,7 +587,9 @@ class AppDomain extends Domain {
'trace': '$trace', 'trace': '$trace',
}); });
} finally { } 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); _apps.remove(app);
} }
}); });
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:flutter_tools/src/base/error_handling_file_system.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:mockito/mockito.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'package:path/path.dart' as path; // ignore: package_path_import import 'package:path/path.dart' as path; // ignore: package_path_import
...@@ -14,8 +15,13 @@ import '../../src/testbed.dart'; ...@@ -14,8 +15,13 @@ import '../../src/testbed.dart';
class MockFile extends Mock implements File {} class MockFile extends Mock implements File {}
class MockFileSystem extends Mock implements FileSystem {} class MockFileSystem extends Mock implements FileSystem {}
class MockPlatform extends Mock implements Platform {}
class MockPathContext extends Mock implements path.Context {} class MockPathContext extends Mock implements path.Context {}
class MockDirectory extends Mock implements Directory {}
final Platform windowsPlatform = FakePlatform(
operatingSystem: 'windows',
environment: <String, String>{}
);
void main() { void main() {
group('throws ToolExit on Windows', () { group('throws ToolExit on Windows', () {
...@@ -23,17 +29,11 @@ void main() { ...@@ -23,17 +29,11 @@ void main() {
const int kUserMappedSectionOpened = 1224; const int kUserMappedSectionOpened = 1224;
Testbed testbed; Testbed testbed;
MockFileSystem mockFileSystem; MockFileSystem mockFileSystem;
MockPlatform windowsPlatform;
ErrorHandlingFileSystem fs; ErrorHandlingFileSystem fs;
setUp(() { setUp(() {
mockFileSystem = MockFileSystem(); mockFileSystem = MockFileSystem();
fs = ErrorHandlingFileSystem(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()); when(mockFileSystem.path).thenReturn(MockPathContext());
testbed = Testbed(overrides: <Type, Generator>{ testbed = Testbed(overrides: <Type, Generator>{
Platform: () => windowsPlatform, Platform: () => windowsPlatform,
...@@ -119,6 +119,14 @@ void main() { ...@@ -119,6 +119,14 @@ void main() {
expect(identical(firstPath, fs.path), false); 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<TypeError>()));
});
group('toString() gives toString() of delegate', () { group('toString() gives toString() of delegate', () {
test('ErrorHandlingFileSystem', () { test('ErrorHandlingFileSystem', () {
final MockFileSystem mockFileSystem = MockFileSystem(); final MockFileSystem mockFileSystem = MockFileSystem();
......
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