From 2f6155bf188911bc0630b1b2e6786e968a570fe7 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Wed, 3 Oct 2018 19:07:04 +0100 Subject: [PATCH] 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. --- packages/flutter_tools/test/src/context.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index e91e1559af..e458d93667 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -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.'; + } +}