Unverified Commit 2f6155bf authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

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.
parent d44f0030
......@@ -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.';
}
}
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