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