From f59b185be47db20a63ba0a8c04cc9a48a5f006d8 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 30 Mar 2021 11:39:02 -0700 Subject: [PATCH] [flutter_tools] do not make drive require pub if --no-pub is requested (#79379) --- .../flutter_tools/lib/src/commands/drive.dart | 10 ++++- .../commands.shard/hermetic/drive_test.dart | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 044eaea7d80..f297101f8e8 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -147,9 +147,15 @@ class DriveCommand extends RunCommandBase { } // `pub` must always be run due to the test script running from source, - // even if an application binary is used. + // even if an application binary is used. Default to true unless the user explicitly + // specified not to. @override - bool get shouldRunPub => true; + bool get shouldRunPub { + if (argResults.wasParsed('pub') && !boolArg('pub')) { + return false; + } + return true; + } FlutterDriverFactory _flutterDriverFactory; final FileSystem _fileSystem; diff --git a/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart index b142815917a..73ab79e0c9c 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/drive_test.dart @@ -8,11 +8,15 @@ import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/platform.dart'; +import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/commands/drive.dart'; +import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/device.dart'; import 'package:test/fake.dart'; import '../../src/common.dart'; +import '../../src/context.dart'; +import '../../src/fakes.dart'; void main() { FileSystem fileSystem; @@ -25,6 +29,15 @@ void main() { platform = FakePlatform(operatingSystem: 'linux'); }); + setUpAll(() { + Cache.disableLocking(); + }); + + tearDownAll(() { + Cache.enableLocking(); + }); + + testWithoutContext('drive --screenshot writes to expected output', () async { final Device screenshotDevice = ScreenshotDevice(); @@ -60,6 +73,33 @@ void main() { expect(logger.statusText, isEmpty); expect(logger.errorText, contains('Error taking screenshot: FileSystemException: Not a directory')); }); + + testUsingContext('shouldRunPub is true unless user specifies --no-pub', () async { + final DriveCommand command = DriveCommand(fileSystem: fileSystem, logger: logger, platform: platform); + fileSystem.file('lib/main.dart').createSync(recursive: true); + fileSystem.file('test_driver/main_test.dart').createSync(recursive: true); + fileSystem.file('pubspec.yaml').createSync(); + + try { + await createTestCommandRunner(command).run(const ['drive', '--no-pub']); + } on Exception { + // Expected to throw + } + + expect(command.shouldRunPub, false); + + try { + await createTestCommandRunner(command).run(const ['drive']); + } on Exception { + // Expected to throw + } + + expect(command.shouldRunPub, true); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => FakeProcessManager.any(), + Pub: () => FakePub(), + }); } class ScreenshotDevice extends Fake implements Device {