Unverified Commit 62d89692 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Adopt Artifacts.test(localEngine:) in a few tests (#76354)

parent 6fec8b36
...@@ -135,7 +135,6 @@ void main() { ...@@ -135,7 +135,6 @@ void main() {
testbed.test('flutter assemble does not inject engine revision with local-engine', () async { testbed.test('flutter assemble does not inject engine revision with local-engine', () async {
Environment environment; Environment environment;
when(globals.artifacts.isLocalEngine).thenReturn(true);
when(globals.buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) when(globals.buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig')))
.thenAnswer((Invocation invocation) async { .thenAnswer((Invocation invocation) async {
environment = invocation.positionalArguments[1] as Environment; environment = invocation.positionalArguments[1] as Environment;
...@@ -146,7 +145,7 @@ void main() { ...@@ -146,7 +145,7 @@ void main() {
expect(environment.engineVersion, isNull); expect(environment.engineVersion, isNull);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => MockLocalEngineArtifacts() Artifacts: () => Artifacts.test(localEngine: 'out/host_release'),
}); });
testbed.test('flutter assemble only writes input and output files when the values change', () async { testbed.test('flutter assemble only writes input and output files when the values change', () async {
...@@ -239,4 +238,3 @@ void main() { ...@@ -239,4 +238,3 @@ void main() {
} }
class MockBuildSystem extends Mock implements BuildSystem {} class MockBuildSystem extends Mock implements BuildSystem {}
class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
...@@ -315,24 +315,22 @@ include ':app' ...@@ -315,24 +315,22 @@ include ':app'
}); });
group('Gradle local.properties', () { group('Gradle local.properties', () {
MockLocalEngineArtifacts mockArtifacts; Artifacts localEngineArtifacts;
MockProcessManager mockProcessManager;
FakePlatform android; FakePlatform android;
FileSystem fs; FileSystem fs;
setUp(() { setUp(() {
fs = MemoryFileSystem.test(); fs = MemoryFileSystem.test();
mockArtifacts = MockLocalEngineArtifacts(); localEngineArtifacts = Artifacts.test(localEngine: 'out/android_arm');
mockProcessManager = MockProcessManager();
android = fakePlatform('android'); android = fakePlatform('android');
}); });
void testUsingAndroidContext(String description, dynamic testMethod()) { void testUsingAndroidContext(String description, dynamic testMethod()) {
testUsingContext(description, testMethod, overrides: <Type, Generator>{ testUsingContext(description, testMethod, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts, Artifacts: () => localEngineArtifacts,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fs,
ProcessManager: () => mockProcessManager, ProcessManager: () => FakeProcessManager.any(),
}); });
} }
...@@ -349,14 +347,6 @@ include ':app' ...@@ -349,14 +347,6 @@ include ':app'
String expectedBuildName, String expectedBuildName,
String expectedBuildNumber, String expectedBuildNumber,
}) async { }) async {
when(mockArtifacts.getArtifactPath(
Artifact.flutterFramework,
platform: TargetPlatform.android_arm,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType'),
)).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(globals.fs.path.join('out', 'android_arm'));
final File manifestFile = globals.fs.file('path/to/project/pubspec.yaml'); final File manifestFile = globals.fs.file('path/to/project/pubspec.yaml');
manifestFile.createSync(recursive: true); manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync(manifest); manifestFile.writeAsStringSync(manifest);
...@@ -1042,5 +1032,3 @@ class FakeGradleUtils extends GradleUtils { ...@@ -1042,5 +1032,3 @@ class FakeGradleUtils extends GradleUtils {
class MockAndroidSdk extends Mock implements AndroidSdk {} class MockAndroidSdk extends Mock implements AndroidSdk {}
class MockAndroidProject extends Mock implements AndroidProject {} class MockAndroidProject extends Mock implements AndroidProject {}
class MockFlutterProject extends Mock implements FlutterProject {} class MockFlutterProject extends Mock implements FlutterProject {}
class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
class MockProcessManager extends Mock implements ProcessManager {}
...@@ -638,20 +638,20 @@ Information about project "Runner": ...@@ -638,20 +638,20 @@ Information about project "Runner":
}); });
group('updateGeneratedXcodeProperties', () { group('updateGeneratedXcodeProperties', () {
MockLocalEngineArtifacts mockArtifacts; Artifacts localArtifacts;
FakePlatform macOS; FakePlatform macOS;
FileSystem fs; FileSystem fs;
setUp(() { setUp(() {
fs = MemoryFileSystem.test(); fs = MemoryFileSystem.test();
mockArtifacts = MockLocalEngineArtifacts(); localArtifacts = Artifacts.test(localEngine: 'out/ios_profile_arm');
macOS = FakePlatform(operatingSystem: 'macos'); macOS = FakePlatform(operatingSystem: 'macos');
fs.file(xcodebuild).createSync(recursive: true); fs.file(xcodebuild).createSync(recursive: true);
}); });
void testUsingOsxContext(String description, dynamic testMethod()) { void testUsingOsxContext(String description, dynamic testMethod()) {
testUsingContext(description, testMethod, overrides: <Type, Generator>{ testUsingContext(description, testMethod, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts, Artifacts: () => localArtifacts,
Platform: () => macOS, Platform: () => macOS,
FileSystem: () => fs, FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
...@@ -659,13 +659,6 @@ Information about project "Runner": ...@@ -659,13 +659,6 @@ Information about project "Runner":
} }
testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () async { testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType')))
.thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm'));
const BuildInfo buildInfo = BuildInfo.debug; const BuildInfo buildInfo = BuildInfo.debug;
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
await updateGeneratedXcodeProperties( await updateGeneratedXcodeProperties(
...@@ -686,41 +679,7 @@ Information about project "Runner": ...@@ -686,41 +679,7 @@ Information about project "Runner":
expect(buildPhaseScriptContents.contains('ARCHS=armv7'), isTrue); expect(buildPhaseScriptContents.contains('ARCHS=armv7'), isTrue);
}); });
testUsingOsxContext('sets ARCHS=x86_64 when sim local engine is set', () async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType')))
.thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_debug_sim_unopt'));
const BuildInfo buildInfo = BuildInfo.debug;
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
await updateGeneratedXcodeProperties(
project: project,
buildInfo: buildInfo,
);
final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
expect(config.existsSync(), isTrue);
final String contents = config.readAsStringSync();
expect(contents.contains('ARCHS=x86_64'), isTrue);
final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
expect(buildPhaseScript.existsSync(), isTrue);
final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
expect(buildPhaseScriptContents.contains('ARCHS=x86_64'), isTrue);
});
testUsingOsxContext('sets TRACK_WIDGET_CREATION=true when trackWidgetCreation is true', () async { testUsingOsxContext('sets TRACK_WIDGET_CREATION=true when trackWidgetCreation is true', () async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType')))
.thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm'));
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null, trackWidgetCreation: true, treeShakeIcons: false); const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null, trackWidgetCreation: true, treeShakeIcons: false);
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
await updateGeneratedXcodeProperties( await updateGeneratedXcodeProperties(
...@@ -742,12 +701,6 @@ Information about project "Runner": ...@@ -742,12 +701,6 @@ Information about project "Runner":
}); });
testUsingOsxContext('does not set TRACK_WIDGET_CREATION when trackWidgetCreation is false', () async { testUsingOsxContext('does not set TRACK_WIDGET_CREATION when trackWidgetCreation is false', () async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType')))
.thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm'));
const BuildInfo buildInfo = BuildInfo.debug; const BuildInfo buildInfo = BuildInfo.debug;
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
await updateGeneratedXcodeProperties( await updateGeneratedXcodeProperties(
...@@ -768,26 +721,67 @@ Information about project "Runner": ...@@ -768,26 +721,67 @@ Information about project "Runner":
expect(buildPhaseScriptContents.contains('TRACK_WIDGET_CREATION=true'), isFalse); expect(buildPhaseScriptContents.contains('TRACK_WIDGET_CREATION=true'), isFalse);
}); });
testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () async { group('sim local engine', () {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, Artifacts localArtifacts;
platform: TargetPlatform.ios,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType')))
.thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile'));
const BuildInfo buildInfo = BuildInfo.debug;
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); setUp(() {
await updateGeneratedXcodeProperties( localArtifacts = Artifacts.test(localEngine: 'out/ios_debug_sim_unopt');
project: project, });
buildInfo: buildInfo,
);
final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig'); testUsingContext('sets ARCHS=x86_64 when sim local engine is set', () async {
expect(config.existsSync(), isTrue); const BuildInfo buildInfo = BuildInfo.debug;
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
await updateGeneratedXcodeProperties(
project: project,
buildInfo: buildInfo,
);
final String contents = config.readAsStringSync(); final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
expect(contents.contains('ARCHS=arm64'), isTrue); expect(config.existsSync(), isTrue);
final String contents = config.readAsStringSync();
expect(contents.contains('ARCHS=x86_64'), isTrue);
final File buildPhaseScript = fs.file('path/to/project/ios/Flutter/flutter_export_environment.sh');
expect(buildPhaseScript.existsSync(), isTrue);
final String buildPhaseScriptContents = buildPhaseScript.readAsStringSync();
expect(buildPhaseScriptContents.contains('ARCHS=x86_64'), isTrue);
}, overrides: <Type, Generator>{
Artifacts: () => localArtifacts,
Platform: () => macOS,
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
});
});
group('armv7 local engine', () {
Artifacts localArtifacts;
setUp(() {
localArtifacts = Artifacts.test(localEngine: 'out/ios_profile');
});
testUsingContext('sets ARCHS=armv7 when armv7 local engine is set', () async {
const BuildInfo buildInfo = BuildInfo.debug;
final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project'));
await updateGeneratedXcodeProperties(
project: project,
buildInfo: buildInfo,
);
final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig');
expect(config.existsSync(), isTrue);
final String contents = config.readAsStringSync();
expect(contents.contains('ARCHS=arm64'), isTrue);
}, overrides: <Type, Generator>{
Artifacts: () => localArtifacts,
Platform: () => macOS,
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
});
}); });
String propertyFor(String key, File file) { String propertyFor(String key, File file) {
...@@ -805,13 +799,6 @@ Information about project "Runner": ...@@ -805,13 +799,6 @@ Information about project "Runner":
String expectedBuildName, String expectedBuildName,
String expectedBuildNumber, String expectedBuildNumber,
}) async { }) async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: anyNamed('mode'),
environmentType: anyNamed('environmentType')))
.thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios'));
final File manifestFile = fs.file('path/to/project/pubspec.yaml'); final File manifestFile = fs.file('path/to/project/pubspec.yaml');
manifestFile.createSync(recursive: true); manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync(manifestString); manifestFile.writeAsStringSync(manifestString);
...@@ -989,5 +976,3 @@ flutter: ...@@ -989,5 +976,3 @@ flutter:
}); });
}); });
} }
class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
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