Unverified Commit 7c27db3d authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks and globals from macOS tests (#81401)

parent cbf885b7
...@@ -17,7 +17,7 @@ import 'package:flutter_tools/src/macos/application_package.dart'; ...@@ -17,7 +17,7 @@ import 'package:flutter_tools/src/macos/application_package.dart';
import 'package:flutter_tools/src/macos/macos_device.dart'; import 'package:flutter_tools/src/macos/macos_device.dart';
import 'package:flutter_tools/src/macos/macos_workflow.dart'; import 'package:flutter_tools/src/macos/macos_workflow.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -39,14 +39,14 @@ void main() { ...@@ -39,14 +39,14 @@ void main() {
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
operatingSystemUtils: FakeOperatingSystemUtils(), operatingSystemUtils: FakeOperatingSystemUtils(),
); );
final MockMacOSApp mockMacOSApp = MockMacOSApp(); final FakeMacOSApp package = FakeMacOSApp();
expect(await device.targetPlatform, TargetPlatform.darwin); expect(await device.targetPlatform, TargetPlatform.darwin);
expect(device.name, 'macOS'); expect(device.name, 'macOS');
expect(await device.installApp(mockMacOSApp), true); expect(await device.installApp(package), true);
expect(await device.uninstallApp(mockMacOSApp), true); expect(await device.uninstallApp(package), true);
expect(await device.isLatestBuildInstalled(mockMacOSApp), true); expect(await device.isLatestBuildInstalled(package), true);
expect(await device.isAppInstalled(mockMacOSApp), true); expect(await device.isAppInstalled(package), true);
expect(device.category, Category.desktop); expect(device.category, Category.desktop);
expect(device.supportsRuntimeMode(BuildMode.debug), true); expect(device.supportsRuntimeMode(BuildMode.debug), true);
...@@ -61,7 +61,7 @@ void main() { ...@@ -61,7 +61,7 @@ void main() {
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
processManager: FakeProcessManager.list(<FakeCommand>[ processManager: FakeProcessManager.list(<FakeCommand>[
FakeCommand( FakeCommand(
command: const <String>['Example.app'], command: const <String>['release/executable'],
stdout: 'Hello World', stdout: 'Hello World',
stderr: 'Goodnight, Moon', stderr: 'Goodnight, Moon',
completer: completer, completer: completer,
...@@ -70,18 +70,17 @@ void main() { ...@@ -70,18 +70,17 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
operatingSystemUtils: FakeOperatingSystemUtils(), operatingSystemUtils: FakeOperatingSystemUtils(),
); );
final MockMacOSApp mockMacOSApp = MockMacOSApp(); final FakeMacOSApp package = FakeMacOSApp();
when(mockMacOSApp.executable(BuildMode.release)).thenReturn('Example.app');
final LaunchResult result = await device.startApp( final LaunchResult result = await device.startApp(
mockMacOSApp, package,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
prebuiltApplication: true, prebuiltApplication: true,
); );
expect(result.started, true); expect(result.started, true);
final DeviceLogReader logReader = device.getLogReader(app: mockMacOSApp); final DeviceLogReader logReader = device.getLogReader(app: package);
expect(logReader.logLines, emits('Hello WorldGoodnight, Moon')); expect(logReader.logLines, emits('Hello WorldGoodnight, Moon'));
completer.complete(); completer.complete();
...@@ -213,7 +212,7 @@ void main() { ...@@ -213,7 +212,7 @@ void main() {
}); });
testUsingContext('executablePathForDevice uses the correct package executable', () async { testUsingContext('executablePathForDevice uses the correct package executable', () async {
final MockMacOSApp mockApp = MockMacOSApp(); final FakeMacOSApp package = FakeMacOSApp();
final MacOSDevice device = MacOSDevice( final MacOSDevice device = MacOSDevice(
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(), logger: BufferLogger.test(),
...@@ -223,13 +222,10 @@ void main() { ...@@ -223,13 +222,10 @@ void main() {
const String debugPath = 'debug/executable'; const String debugPath = 'debug/executable';
const String profilePath = 'profile/executable'; const String profilePath = 'profile/executable';
const String releasePath = 'release/executable'; const String releasePath = 'release/executable';
when(mockApp.executable(BuildMode.debug)).thenReturn(debugPath);
when(mockApp.executable(BuildMode.profile)).thenReturn(profilePath);
when(mockApp.executable(BuildMode.release)).thenReturn(releasePath);
expect(device.executablePathForDevice(mockApp, BuildMode.debug), debugPath); expect(device.executablePathForDevice(package, BuildMode.debug), debugPath);
expect(device.executablePathForDevice(mockApp, BuildMode.profile), profilePath); expect(device.executablePathForDevice(package, BuildMode.profile), profilePath);
expect(device.executablePathForDevice(mockApp, BuildMode.release), releasePath); expect(device.executablePathForDevice(package, BuildMode.release), releasePath);
}); });
} }
...@@ -241,4 +237,18 @@ FlutterProject setUpFlutterProject(Directory directory) { ...@@ -241,4 +237,18 @@ FlutterProject setUpFlutterProject(Directory directory) {
return flutterProjectFactory.fromDirectory(directory); return flutterProjectFactory.fromDirectory(directory);
} }
class MockMacOSApp extends Mock implements MacOSApp {} class FakeMacOSApp extends Fake implements MacOSApp {
@override
String executable(BuildMode buildMode) {
switch (buildMode) {
case BuildMode.debug:
return 'debug/executable';
case BuildMode.profile:
return 'profile/executable';
case BuildMode.release:
return 'release/executable';
default:
throw StateError('');
}
}
}
...@@ -7,14 +7,12 @@ ...@@ -7,14 +7,12 @@
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/project_migrator.dart'; import 'package:flutter_tools/src/base/project_migrator.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/macos/migrations/remove_macos_framework_link_and_embedding_migration.dart'; import 'package:flutter_tools/src/macos/migrations/remove_macos_framework_link_and_embedding_migration.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
...@@ -22,31 +20,22 @@ void main() { ...@@ -22,31 +20,22 @@ void main() {
TestUsage testUsage; TestUsage testUsage;
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
BufferLogger testLogger; BufferLogger testLogger;
MockMacOSProject mockMacOSProject; FakeMacOSProject macOSProject;
File xcodeProjectInfoFile; File xcodeProjectInfoFile;
setUp(() { setUp(() {
testUsage = TestUsage(); testUsage = TestUsage();
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj'); xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
testLogger = BufferLogger.test();
testLogger = BufferLogger( macOSProject = FakeMacOSProject();
terminal: AnsiTerminal( macOSProject.xcodeProjectInfoFile = xcodeProjectInfoFile;
stdio: null,
platform: const LocalPlatform(),
),
outputPreferences: OutputPreferences.test(),
);
mockMacOSProject = MockMacOSProject();
when(mockMacOSProject.xcodeProjectInfoFile)
.thenReturn(xcodeProjectInfoFile);
}); });
testWithoutContext('skipped if files are missing', () { testWithoutContext('skipped if files are missing', () {
final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration = final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration =
RemoveMacOSFrameworkLinkAndEmbeddingMigration( RemoveMacOSFrameworkLinkAndEmbeddingMigration(
mockMacOSProject, macOSProject,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -70,7 +59,7 @@ void main() { ...@@ -70,7 +59,7 @@ void main() {
final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration = final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration =
RemoveMacOSFrameworkLinkAndEmbeddingMigration( RemoveMacOSFrameworkLinkAndEmbeddingMigration(
mockMacOSProject, macOSProject,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -91,7 +80,7 @@ shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/. ...@@ -91,7 +80,7 @@ shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.
final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration = final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration =
RemoveMacOSFrameworkLinkAndEmbeddingMigration( RemoveMacOSFrameworkLinkAndEmbeddingMigration(
mockMacOSProject, macOSProject,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -114,7 +103,7 @@ keep this 2 ...@@ -114,7 +103,7 @@ keep this 2
final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration = final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration =
RemoveMacOSFrameworkLinkAndEmbeddingMigration( RemoveMacOSFrameworkLinkAndEmbeddingMigration(
mockMacOSProject, macOSProject,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -137,7 +126,7 @@ keep this 2 ...@@ -137,7 +126,7 @@ keep this 2
final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration = final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration =
RemoveMacOSFrameworkLinkAndEmbeddingMigration( RemoveMacOSFrameworkLinkAndEmbeddingMigration(
mockMacOSProject, macOSProject,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -157,7 +146,7 @@ keep this 2 ...@@ -157,7 +146,7 @@ keep this 2
final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration = final RemoveMacOSFrameworkLinkAndEmbeddingMigration macosProjectMigration =
RemoveMacOSFrameworkLinkAndEmbeddingMigration( RemoveMacOSFrameworkLinkAndEmbeddingMigration(
mockMacOSProject, macOSProject,
testLogger, testLogger,
testUsage, testUsage,
); );
...@@ -169,7 +158,10 @@ keep this 2 ...@@ -169,7 +158,10 @@ keep this 2
}); });
} }
class MockMacOSProject extends Mock implements MacOSProject {} class FakeMacOSProject extends Fake implements MacOSProject {
@override
File xcodeProjectInfoFile;
}
class FakeMacOSMigrator extends ProjectMigrator { class FakeMacOSMigrator extends ProjectMigrator {
FakeMacOSMigrator({@required this.succeeds}) : super(null); FakeMacOSMigrator({@required this.succeeds}) : super(null);
......
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