Throw if trying to set fs.currentDirectory in tests (#22037)

* Block setting of fs.currentDirectory in tests

This isn't perfect, it only covers tests using testUsingContext, but that is the huge majority of tests.

* Tweak error message.
This commit is contained in:
Danny Tuppeny
2018-10-03 19:07:04 +01:00
committed by GitHub
parent d44f003079
commit 2f6155bf18

View File

@@ -81,6 +81,7 @@ void testUsingContext(String description, dynamic testMethod(), {
SimControl: () => MockSimControl(),
Usage: () => MockUsage(),
XcodeProjectInterpreter: () => MockXcodeProjectInterpreter(),
FileSystem: () => LocalFileSystemBlockingSetCurrentDirectory(),
},
body: () {
final String flutterRoot = getFlutterRoot();
@@ -300,3 +301,13 @@ class MockFlutterVersion extends Mock implements FlutterVersion {}
class MockClock extends Mock implements Clock {}
class MockHttpClient extends Mock implements HttpClient {}
class LocalFileSystemBlockingSetCurrentDirectory extends LocalFileSystem {
@override
set currentDirectory(dynamic value) {
throw 'fs.currentDirectory should not be set on the local file system during '
'tests as this can cause race conditions with concurrent tests. '
'Consider using a MemoryFileSystem for testing if possible or refactor '
'code to not require setting fs.currentDirectory.';
}
}