diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java | 443 |
1 files changed, 25 insertions, 418 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java index f789de4ef1..05130bd7f6 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/IosTestTest.java @@ -20,7 +20,6 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.CommandAction; import com.google.devtools.build.lib.analysis.ConfiguredTarget; @@ -34,11 +33,8 @@ import com.google.devtools.build.lib.analysis.test.TestProvider; import com.google.devtools.build.lib.analysis.test.TestRunnerAction; import com.google.devtools.build.lib.packages.util.MockObjcSupport; import com.google.devtools.build.lib.packages.util.MockProtoSupport; -import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher; -import com.google.devtools.build.lib.rules.apple.AppleToolchain; import com.google.devtools.build.lib.rules.apple.XcodeVersionProperties; import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode; -import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.xcode.plmerge.proto.PlMergeProtos; import java.util.List; import java.util.Map; @@ -172,7 +168,7 @@ public class IosTestTest extends ObjcRuleTestCase { "lib1/_objs/lib1/lib1/b.gcno", "lib2/_objs/lib2/lib2/a.gcno", "lib2/_objs/lib2/lib2/b.gcno", - "tools/objc/_objs/xctest_appbin/tools/objc/objc_dummy.gcno"); + "tools/objc/_objs/dummy_lib/tools/objc/objc_dummy.gcno"); } @Test @@ -205,26 +201,14 @@ public class IosTestTest extends ObjcRuleTestCase { @Test public void testXcTestAppIpaIsInFilesToBuild() throws Exception { scratch.file("x/BUILD", - "ios_application(", - " name = 'xctest_app',", - " binary = ':xctest_app_bin',", - " infoplist = 'Info.plist',", - ")", - "", - "objc_binary(", - " name = 'xctest_app_bin',", - " srcs = ['a.m'],", - ")", - "", "ios_test(", " name = 'x',", " xctest = 1,", - " xctest_app = ':xctest_app',", " srcs = ['test.m'],", ")"); ConfiguredTarget target = getConfiguredTarget("//x:x"); Iterable<Artifact> filesToBuild = target.getProvider(FileProvider.class).getFilesToBuild(); - assertThat(filesToBuild).contains(getBinArtifact("xctest_app.ipa", target)); + assertThat(Artifact.toRootRelativePaths(filesToBuild)).contains("tools/objc/xctest_app.ipa"); } @Test @@ -241,10 +225,10 @@ public class IosTestTest extends ObjcRuleTestCase { ImmutableList<String> expectedRunfiles = ImmutableList.of( "test/XcTest.ipa", - "test/testApp.ipa", "test/XcTest_test_script", "tools/objc/StdRedirect.dylib", - "tools/objc/testrunner"); + "tools/objc/testrunner", + "tools/objc/xctest_app.ipa"); RunfilesProvider runfiles = target.getProvider(RunfilesProvider.class); assertThat(Artifact.toRootRelativePaths(runfiles.getDefaultRunfiles().getArtifacts())) .containsExactlyElementsIn(expectedRunfiles); @@ -261,12 +245,13 @@ public class IosTestTest extends ObjcRuleTestCase { InstrumentedFilesProvider instrumentedFilesProvider = target.getProvider(InstrumentedFilesProvider.class); assertThat(Artifact.toRootRelativePaths(instrumentedFilesProvider.getInstrumentedFiles())) - .containsExactly("test/src.m", "test/test-src.m"); + .containsExactly("tools/objc/objc_dummy.mm", "test/test-src.m"); assertThat( Artifact.toRootRelativePaths( instrumentedFilesProvider.getInstrumentationMetadataFiles())) .containsExactly( - "test/_objs/XcTest/test/test-src.gcno", "test/_objs/testAppBin/test/src.gcno"); + "test/_objs/XcTest/test/test-src.gcno", + "tools/objc/_objs/dummy_lib/tools/objc/objc_dummy.gcno"); } @Test @@ -281,7 +266,7 @@ public class IosTestTest extends ObjcRuleTestCase { // Missing "test/test-src.m" since the target including it has been excluded. assertThat(Artifact.toRootRelativePaths(instrumentedFilesProvider.getInstrumentedFiles())) - .containsExactly("test/src.m"); + .containsExactly("tools/objc/objc_dummy.mm"); } @Test @@ -325,41 +310,24 @@ public class IosTestTest extends ObjcRuleTestCase { } protected void setUpXCTestClient() throws Exception { - scratch.file("/test/XcTest-Info.plist"); - scratch.file("/test/App-Info.plist"); scratch.file("/test/src.m"); scratch.file("/test/test-src.m"); scratch.file("test/BUILD", - "objc_binary(", - " name = 'testAppBin',", - " srcs = ['src.m'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':testAppBin',", - ")", "ios_test(", " name = 'XcTest',", " srcs = ['test-src.m'],", " xctest = True,", - " xctest_app = ':testApp',", ")"); } @Test public void testCreate_recognizesDylibsAttribute() throws Exception { - createBinaryTargetWriter("//bin:bin").setAndCreateFiles("srcs", "a.m").write(); scratch.file("test/BUILD", - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'test',", " srcs = ['test-src.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " sdk_dylibs = ['libdy'],", ")"); CommandAction action = linkAction("//test:test"); @@ -433,15 +401,10 @@ public class IosTestTest extends ObjcRuleTestCase { public void testHasDefaultInfoplistForXcTest() throws Exception { createBinaryTargetWriter("//bin:bin").setAndCreateFiles("srcs", "a.m").write(); scratch.file("x/BUILD", - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'x',", " srcs = ['x-src.m'],", " xctest = 1,", - " xctest_app = ':testApp',", ")"); PlMergeProtos.Control control = plMergeControl("//x:x"); assertThat(control.getSourceFileList()) @@ -472,14 +435,9 @@ public class IosTestTest extends ObjcRuleTestCase { .write(); checkError("x", "x", IosTest.REQUIRES_SOURCE_ERROR, - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'x',", " xctest = 1,", - " xctest_app = ':testApp',", " deps = ['//lib:lib'],", ")"); } @@ -488,15 +446,10 @@ public class IosTestTest extends ObjcRuleTestCase { throws Exception { createBinaryTargetWriter("//bin:bin").setAndCreateFiles("srcs", "a.m").write(); scratch.file("x/BUILD", - "ios_application(", - " name = 'testApp',", - " binary = '//bin:bin',", - ")", "ios_test(", " name = 'x',", " srcs = ['a.m'],", " xctest = 1,", - " xctest_app = ':testApp',", Joiner.on(",").join(extraAttrs), ")"); TemplateExpansionAction action = @@ -544,105 +497,6 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testGetsDefinesFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " defines = ['LIB_DEFINE=1'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " defines = ['BIN_DEFINE=1'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " defines = ['TEST_DEFINE=1'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - assertContainsSublist(compileAction("//x:test", "test.o").getArguments(), - ImmutableList.of("-DLIB_DEFINE=1", "-DBIN_DEFINE=1", "-DTEST_DEFINE=1")); - } - - @Test - public void testGetsSdkDylibsFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " sdk_dylibs = ['lib_dylib'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " sdk_dylibs = ['bin_dylib'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " sdk_dylibs = ['test_dylib'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - - String linkArgs = Joiner.on(' ').join(linkAction("//x:test").getArguments()); - assertThat(linkArgs).contains("-l_dylib"); - assertThat(linkArgs).contains("-lbin_dylib"); - assertThat(linkArgs).contains("-ltest_dylib"); - } - - @Test - public void testGetsSdkFrameworksFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " sdk_frameworks = ['lib_fx'],", - " weak_sdk_frameworks = ['lib_wfx'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " sdk_frameworks = ['bin_fx'],", - " weak_sdk_frameworks = ['bin_wfx'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " sdk_frameworks = ['test_fx'],", - " weak_sdk_frameworks = ['test_wfx'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - - String linkArgs = Joiner.on(' ').join(linkAction("//x:test").getArguments()); - assertThat(linkArgs).contains("-framework lib_fx"); - assertThat(linkArgs).contains("-weak_framework lib_wfx"); - assertThat(linkArgs).contains("-framework bin_fx"); - assertThat(linkArgs).contains("-weak_framework bin_wfx"); - assertThat(linkArgs).contains("-framework test_fx"); - assertThat(linkArgs).contains("-weak_framework test_wfx"); - } - - @Test public void testLinkIncludeOrder_staticLibsFirst() throws Exception { checkLinkIncludeOrderStaticLibsFirst(RULE_TYPE); } @@ -884,7 +738,6 @@ public class IosTestTest extends ObjcRuleTestCase { " name = 'some_test_with_device',", " srcs = ['SomeOtherTest.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " target_device = ':device',", ")", "ios_device(", @@ -892,13 +745,6 @@ public class IosTestTest extends ObjcRuleTestCase { " ios_version = '1.2',", " type = 'iMarmoset',", " locale = 'en-gb'", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "objc_binary(name = 'bin',", - " srcs = ['app.m'],", ")"); scratch.file("test/SomeOtherTest.m"); @@ -906,26 +752,23 @@ public class IosTestTest extends ObjcRuleTestCase { TemplateExpansionAction action = getTestScriptGenerationAction(getConfiguredTarget("//test:some_test_with_device")); - assertThat(action.getSubstitutions()).containsExactly( - Substitution.of("%(memleaks)s", "false"), - - Substitution.of("%(test_app_ipa)s", "test/some_test_with_device.ipa"), - Substitution.of("%(test_app_name)s", "some_test_with_device"), - Substitution.of("%(test_bundle_path)s", "test/some_test_with_device.ipa"), - - Substitution.of("%(xctest_app_ipa)s", "test/testApp.ipa"), - Substitution.of("%(xctest_app_name)s", "testApp"), - Substitution.of("%(test_host_path)s", "test/testApp.ipa"), - - Substitution.of("%(plugin_jars)s", ""), - Substitution.of("%(device_type)s", "iMarmoset"), - Substitution.of("%(locale)s", "en-gb"), - Substitution.of("%(simulator_sdk)s", "1.2"), - Substitution.of("%(testrunner_binary)s", "tools/objc/testrunner"), - Substitution.of("%(std_redirect_dylib_path)s", "tools/objc/StdRedirect.dylib"), - Substitution.of("%(test_env)s", ""), - Substitution.of("%(test_type)s", "XCTEST") - ); + assertThat(action.getSubstitutions()) + .containsExactly( + Substitution.of("%(memleaks)s", "false"), + Substitution.of("%(test_app_ipa)s", "test/some_test_with_device.ipa"), + Substitution.of("%(test_app_name)s", "some_test_with_device"), + Substitution.of("%(test_bundle_path)s", "test/some_test_with_device.ipa"), + Substitution.of("%(xctest_app_ipa)s", "tools/objc/xctest_app.ipa"), + Substitution.of("%(xctest_app_name)s", "xctest_app"), + Substitution.of("%(test_host_path)s", "tools/objc/xctest_app.ipa"), + Substitution.of("%(plugin_jars)s", ""), + Substitution.of("%(device_type)s", "iMarmoset"), + Substitution.of("%(locale)s", "en-gb"), + Substitution.of("%(simulator_sdk)s", "1.2"), + Substitution.of("%(testrunner_binary)s", "tools/objc/testrunner"), + Substitution.of("%(std_redirect_dylib_path)s", "tools/objc/StdRedirect.dylib"), + Substitution.of("%(test_env)s", ""), + Substitution.of("%(test_type)s", "XCTEST")); } @Test @@ -935,14 +778,12 @@ public class IosTestTest extends ObjcRuleTestCase { " name = 'one_plugin',", " srcs = ['SomeTest.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " plugins = [':a_plugin_deploy.jar'],", ")", "ios_test(", " name = 'two_plugins',", " srcs = ['SomeOtherTest.m'],", " xctest = 1,", - " xctest_app = ':testApp',", " plugins = [':a_plugin_deploy.jar', ':b_plugin_deploy.jar'],", ")", "java_binary(", @@ -954,13 +795,6 @@ public class IosTestTest extends ObjcRuleTestCase { " name = 'b_plugin',", " srcs = ['B.java'],", " main_class = 'B',", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "objc_binary(name = 'bin',", - " srcs = ['app.m'],", ")"); scratch.file("test/SomeTest.m"); @@ -1064,83 +898,11 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testProtobufPropagatedHeaderSearchPaths() throws Exception { - scratch.file( - "test/BUILD", - "ios_test(", - " name = 'protos_test',", - " srcs = ['SomeTest.m'],", - " xctest = 1,", - " xctest_app = ':protos_app',", - ")", - "ios_application(", - " name = 'protos_app',", - " binary = ':protos_bin',", - ")", - "objc_binary(", - " name = 'protos_bin',", - " srcs = ['app.m'],", - " deps = [':protos_objc'],", - ")", - "objc_proto_library(", - " name = 'protos_objc',", - " deps = [':protos_lib'],", - " portable_proto_filters = ['filter.pbascii'],", - ")", - "proto_library(", - " name = 'protos_lib',", - " srcs = ['a.proto'],", - ")"); - - ObjcProvider appProvider = - getConfiguredTarget("//test:protos_app") - .get(XcTestAppProvider.SKYLARK_CONSTRUCTOR) - .getObjcProvider(); - ConfiguredTarget binTarget = getConfiguredTarget("//test:protos_bin"); - Artifact protoHeader = - getBinArtifact("_generated_protos/protos_bin/test/A.pbobjc.h", binTarget); - - assertThat(PathFragment.safePathStrings(appProvider.get(ObjcProvider.INCLUDE))) - .containsAllOf( - "objcproto/include", - protoHeader.getExecPath().getParentDirectory().getParentDirectory().toString()); - } - - @Test public void testCcDependency() throws Exception { checkCcDependency(RULE_TYPE, "xctest", "0"); } @Test - public void testPassesTestRigAppAsBundleLoaderFlagToLinker() throws Exception { - useConfiguration("--cpu=ios_x86_64", - "--crosstool_top=" + MockObjcSupport.DEFAULT_OSX_CROSSTOOL, - "--experimental_disable_go"); - scratch.file("x/BUILD", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - CommandAction testLinkAction = linkAction("//x:test"); - Action appLipoAction = lipoBinAction("//x:testApp"); - Artifact rigBinary = Iterables.getOnlyElement(appLipoAction.getOutputs()); - - String linkArgs = Joiner.on(' ').join(testLinkAction.getArguments()); - assertThat(linkArgs).contains("-bundle_loader " + rigBinary.getExecPath()); - assertThat(testLinkAction.getInputs()).contains(rigBinary); - } - - @Test public void testCompilationActionsForDebugInGcovCoverage() throws Exception { checkClangCoptsForCompilationMode(RULE_TYPE, CompilationMode.DBG, CodeCoverageMode.GCOV); @@ -1165,46 +927,6 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testMultiArchUserHeaderSearchPathsUsed() throws Exception { - // Usually, an ios_test would depend on apple_binary through a skylark_ios_application in its - // 'binary' attribute. Since we don't have skylark_ios_application here, we use the 'deps' - // attribute instead. - scratch.file("x/BUILD", - "genrule(", - " name = 'gen_hdrs',", - " outs = ['generated.h'],", - " cmd = 'echo hello > \\$@',", - ")", - "apple_binary(", - " name = 'apple_bin',", - " srcs = ['apple_bin.m'],", - " platform_type = 'ios',", - " hdrs = ['generated.h'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " xctest = 1,", - " xctest_app = ':testApp',", - " deps = [':apple_bin']", - ")"); - CommandAction compileAction = compileAction("//x:test", "test.o"); - // The genfiles root for child configurations must be present in the compile action so that - // generated headers can be resolved. - assertThat(Joiner.on(" ").join(compileAction.getArguments())).contains("-iquote " - + configurationGenfiles("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS, - defaultMinimumOs(ConfigurationDistinguisher.APPLEBIN_IOS))); - } - - @Test public void testXcTest_linkAction_inCoverageMode() throws Exception { useConfiguration("--collect_code_coverage"); setUpXCTestClient(); @@ -1232,37 +954,6 @@ public class IosTestTest extends ObjcRuleTestCase { } @Test - public void testGetsHeadersFromTestRig() throws Exception { - scratch.file( - "x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " hdrs = ['lib.h'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " hdrs = ['bin.h'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " hdrs = ['test.h'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - Iterable<Artifact> compileInputs = - compileAction("//x:test", "test.o").getPossibleInputsForTesting(); - assertThat(Artifact.toExecPaths(compileInputs)).containsAllOf("x/lib.h", "x/bin.h", "x/test.h"); - } - - @Test public void testReceivesTransitivelyPropagatedDefines() throws Exception { checkReceivesTransitivelyPropagatedDefines(RULE_TYPE); } @@ -1271,88 +962,4 @@ public class IosTestTest extends ObjcRuleTestCase { public void testSdkIncludesUsedInCompileAction() throws Exception { checkSdkIncludesUsedInCompileAction(RULE_TYPE); } - - @Test - public void testGetsIncludesFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " includes = ['libinc'],", - " sdk_includes = ['libinc_sdk'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " includes = ['bininc'],", - " sdk_includes = ['bininc_sdk'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " includes = ['testinc'],", - " sdk_includes = ['testinc_sdk'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - // We remove spaces because the crosstool case does not use spaces for include paths. - String compileArgs = Joiner.on("") - .join(compileAction("//x:test", "test.o").getArguments()) - .replace(" ", ""); - assertThat(compileArgs).contains("-Ix/libinc"); - assertThat(compileArgs).contains("-Ix/bininc"); - assertThat(compileArgs).contains("-Ix/testinc"); - - String sdkIncludeDir = AppleToolchain.sdkDir() + "/usr/include/"; - assertThat(compileArgs).contains("-I" + sdkIncludeDir + "libinc_sdk"); - assertThat(compileArgs).contains("-I" + sdkIncludeDir + "bininc_sdk"); - assertThat(compileArgs).contains("-I" + sdkIncludeDir + "testinc_sdk"); - } - - @Test - public void testGetsFrameworksFromTestRig() throws Exception { - scratch.file("x/BUILD", - "objc_framework(", - " name = 'fx',", - " framework_imports = ['fx.framework/1'],", - ")", - "objc_library(", - " name = 'lib',", - " srcs = ['lib.m'],", - " deps = [':fx'],", - ")", - "objc_binary(", - " name = 'bin',", - " srcs = ['bin.m'],", - " deps = [':lib'],", - ")", - "ios_application(", - " name = 'testApp',", - " binary = ':bin',", - ")", - "ios_test(", - " name = 'test',", - " srcs = ['test.m'],", - " xctest = 1,", - " xctest_app = ':testApp',", - ")"); - CommandAction compileAction = compileAction("//x:test", "test.o"); - - assertThat(Artifact.toExecPaths(compileAction.getInputs())) - .contains("x/fx.framework/1"); - // We remove spaces since the crosstool case does not use spaces for '-F'. - String compileActionArgs = Joiner.on("") - .join(compileAction.getArguments()) - .replace(" ", ""); - - assertThat(compileActionArgs).contains("-Fx"); - - CommandAction linkAction = linkAction("//x:test"); - assertThat(Joiner.on(" ").join(linkAction.getArguments())).doesNotContain("-framework fx"); - } } |