From 62d89692034f8ddbde1f8b4c47f6aed907a8b7be Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Thu, 18 Feb 2021 19:31:03 -0800 Subject: [PATCH] Adopt Artifacts.test(localEngine:) in a few tests (#76354) --- .../hermetic/assemble_test.dart | 4 +- .../general.shard/android/gradle_test.dart | 20 +-- .../general.shard/ios/xcodeproj_test.dart | 137 ++++++++---------- 3 files changed, 66 insertions(+), 95 deletions(-) diff --git a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart index 7e05ed45b9b..93813f10978 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart @@ -135,7 +135,6 @@ void main() { testbed.test('flutter assemble does not inject engine revision with local-engine', () async { Environment environment; - when(globals.artifacts.isLocalEngine).thenReturn(true); when(globals.buildSystem.build(any, any, buildSystemConfig: anyNamed('buildSystemConfig'))) .thenAnswer((Invocation invocation) async { environment = invocation.positionalArguments[1] as Environment; @@ -146,7 +145,7 @@ void main() { expect(environment.engineVersion, isNull); }, overrides: { - Artifacts: () => MockLocalEngineArtifacts() + Artifacts: () => Artifacts.test(localEngine: 'out/host_release'), }); testbed.test('flutter assemble only writes input and output files when the values change', () async { @@ -239,4 +238,3 @@ void main() { } class MockBuildSystem extends Mock implements BuildSystem {} -class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {} diff --git a/packages/flutter_tools/test/general.shard/android/gradle_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_test.dart index 33d3a6e6ec2..5f5a0025e42 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_test.dart @@ -315,24 +315,22 @@ include ':app' }); group('Gradle local.properties', () { - MockLocalEngineArtifacts mockArtifacts; - MockProcessManager mockProcessManager; + Artifacts localEngineArtifacts; FakePlatform android; FileSystem fs; setUp(() { fs = MemoryFileSystem.test(); - mockArtifacts = MockLocalEngineArtifacts(); - mockProcessManager = MockProcessManager(); + localEngineArtifacts = Artifacts.test(localEngine: 'out/android_arm'); android = fakePlatform('android'); }); void testUsingAndroidContext(String description, dynamic testMethod()) { testUsingContext(description, testMethod, overrides: { - Artifacts: () => mockArtifacts, + Artifacts: () => localEngineArtifacts, Platform: () => android, FileSystem: () => fs, - ProcessManager: () => mockProcessManager, + ProcessManager: () => FakeProcessManager.any(), }); } @@ -349,14 +347,6 @@ include ':app' String expectedBuildName, String expectedBuildNumber, }) 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'); manifestFile.createSync(recursive: true); manifestFile.writeAsStringSync(manifest); @@ -1042,5 +1032,3 @@ class FakeGradleUtils extends GradleUtils { class MockAndroidSdk extends Mock implements AndroidSdk {} class MockAndroidProject extends Mock implements AndroidProject {} class MockFlutterProject extends Mock implements FlutterProject {} -class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {} -class MockProcessManager extends Mock implements ProcessManager {} diff --git a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart index 63d457b2e46..1233e5d22db 100644 --- a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart @@ -638,20 +638,20 @@ Information about project "Runner": }); group('updateGeneratedXcodeProperties', () { - MockLocalEngineArtifacts mockArtifacts; + Artifacts localArtifacts; FakePlatform macOS; FileSystem fs; setUp(() { fs = MemoryFileSystem.test(); - mockArtifacts = MockLocalEngineArtifacts(); + localArtifacts = Artifacts.test(localEngine: 'out/ios_profile_arm'); macOS = FakePlatform(operatingSystem: 'macos'); fs.file(xcodebuild).createSync(recursive: true); }); void testUsingOsxContext(String description, dynamic testMethod()) { testUsingContext(description, testMethod, overrides: { - Artifacts: () => mockArtifacts, + Artifacts: () => localArtifacts, Platform: () => macOS, FileSystem: () => fs, ProcessManager: () => FakeProcessManager.any(), @@ -659,13 +659,6 @@ Information about project "Runner": } 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; final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); await updateGeneratedXcodeProperties( @@ -686,41 +679,7 @@ Information about project "Runner": 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 { - 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); final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); await updateGeneratedXcodeProperties( @@ -742,12 +701,6 @@ Information about project "Runner": }); 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; final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); await updateGeneratedXcodeProperties( @@ -768,26 +721,67 @@ Information about project "Runner": expect(buildPhaseScriptContents.contains('TRACK_WIDGET_CREATION=true'), isFalse); }); - 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')); - const BuildInfo buildInfo = BuildInfo.debug; + group('sim local engine', () { + Artifacts localArtifacts; - final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); - await updateGeneratedXcodeProperties( - project: project, - buildInfo: buildInfo, - ); + setUp(() { + localArtifacts = Artifacts.test(localEngine: 'out/ios_debug_sim_unopt'); + }); - final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig'); - expect(config.existsSync(), isTrue); + testUsingContext('sets ARCHS=x86_64 when sim 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 String contents = config.readAsStringSync(); - expect(contents.contains('ARCHS=arm64'), isTrue); + 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); + }, overrides: { + 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: { + Artifacts: () => localArtifacts, + Platform: () => macOS, + FileSystem: () => fs, + ProcessManager: () => FakeProcessManager.any(), + }); }); String propertyFor(String key, File file) { @@ -805,13 +799,6 @@ Information about project "Runner": String expectedBuildName, String expectedBuildNumber, }) 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'); manifestFile.createSync(recursive: true); manifestFile.writeAsStringSync(manifestString); @@ -989,5 +976,3 @@ flutter: }); }); } - -class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}