aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar ajmichael <ajmichael@google.com>2017-05-19 17:21:05 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-05-22 14:36:00 +0200
commita79015e696f163436244887085d3b8a05ec1b0b1 (patch)
treea2391026165d5359feddf76d8beec2ad5d552d46 /src/test/java/com/google
parent42ca7907bf9293087ff6b7e7701e8874a4627712 (diff)
Create new android_host_service_fixture rule.
This rule specifies a host binary that is run as part of an android_instrumentation_test. It merely collects options, support APKs and the runfiles for the host binary and passes them along to the upcoming android_instrumentation_test rule. Note that this CL does _not_ install the rule, so this CL does not make it usable by anyone. Once the other android testing rules are ready, we will install them all. One small step towards https://github.com/bazelbuild/bazel/issues/903. RELNOTES: None PiperOrigin-RevId: 156553198
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java1
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java168
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/BUILD16
3 files changed, 185 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
index 8c3d325bd4..185f52892c 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
@@ -55,6 +55,7 @@ public abstract class AndroidBuildViewTestCase extends BuildViewTestCase {
return builder
// TODO(b/35097211): Remove this once the new testing rules are released.
.addRuleDefinition(new AndroidDeviceScriptFixtureRule())
+ .addRuleDefinition(new AndroidHostServiceFixtureRule())
.addRuleDefinition(new AndroidInstrumentationRule())
.build();
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java
new file mode 100644
index 0000000000..1d77e5db4f
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidHostServiceFixtureTest.java
@@ -0,0 +1,168 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.rules.android;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
+import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.RunfilesProvider;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link AndroidHostServiceFixture}. */
+@RunWith(JUnit4.class)
+public class AndroidHostServiceFixtureTest extends AndroidBuildViewTestCase {
+
+ @Before
+ public void setup() throws Exception {
+ scratch.file(
+ "java/com/server/BUILD",
+ "java_binary(",
+ " name = 'server',",
+ " main_class = 'does.not.exist',",
+ " srcs = [],",
+ ")");
+ scratch.file(
+ "java/com/app/BUILD",
+ "android_binary(",
+ " name = 'support',",
+ " manifest = 'AndroidManifest.xml',",
+ ")",
+ "genrule(",
+ " name = 'genrule',",
+ " outs = ['generated.apk'],",
+ " cmd = 'touch $(OUTS)',",
+ ")");
+ }
+
+ @Test
+ public void testPropagatesExecutableRunfiles() throws Exception {
+ ConfiguredTarget hostServiceFixture =
+ scratchConfiguredTarget(
+ "javatests/com/app/BUILD",
+ "fixture",
+ "android_host_service_fixture(",
+ " name = 'fixture',",
+ " executable = '//java/com/server',",
+ ")");
+ assertThat(hostServiceFixture).isNotNull();
+ assertThat(
+ ActionsTestUtil.prettyArtifactNames(
+ hostServiceFixture
+ .getProvider(RunfilesProvider.class)
+ .getDefaultRunfiles()
+ .getArtifactsWithoutMiddlemen()))
+ .containsExactlyElementsIn(
+ ActionsTestUtil.prettyArtifactNames(
+ getConfiguredTarget("//java/com/server")
+ .getProvider(RunfilesProvider.class)
+ .getDefaultRunfiles()
+ .getArtifacts()));
+ }
+
+ @Test
+ public void testProvidesServiceNames() throws Exception {
+ ConfiguredTarget hostServiceFixture =
+ scratchConfiguredTarget(
+ "javatests/com/app/BUILD",
+ "fixture",
+ "android_host_service_fixture(",
+ " name = 'fixture',",
+ " executable = '//java/com/server',",
+ " service_names = ['proxy', 'echo'],",
+ ")");
+ assertThat(getHostServiceFixtureInfoProvider(hostServiceFixture).getServiceNames())
+ .containsExactly("proxy", "echo")
+ .inOrder();
+ }
+
+ @Test
+ public void testProvidesSupportApks() throws Exception {
+ ConfiguredTarget hostServiceFixture =
+ scratchConfiguredTarget(
+ "javatests/com/app/BUILD",
+ "fixture",
+ "android_host_service_fixture(",
+ " name = 'fixture',",
+ " executable = '//java/com/server',",
+ " service_names = ['proxy', 'echo'],",
+ " support_apks = [",
+ " '//java/com/app:support',",
+ " '//java/com/app:generated.apk',",
+ " ],",
+ ")");
+ assertThat(
+ ActionsTestUtil.prettyArtifactNames(
+ getHostServiceFixtureInfoProvider(hostServiceFixture).getSupportApks()))
+ .containsExactly("java/com/app/support.apk", "java/com/app/generated.apk")
+ .inOrder();
+ }
+
+ @Test
+ public void testProvidesProvidesTestArgs() throws Exception {
+ scratch.file(
+ "javatests/com/app/BUILD",
+ "android_host_service_fixture(",
+ " name = 'fixture_with_no_test_args',",
+ " executable = '//java/com/server',",
+ ")",
+ "android_host_service_fixture(",
+ " name = 'fixture_with_test_args',",
+ " executable = '//java/com/server',",
+ " provides_test_args = 1,",
+ ")");
+ assertThat(
+ getHostServiceFixtureInfoProvider(
+ getConfiguredTarget("//javatests/com/app:fixture_with_no_test_args"))
+ .getProvidesTestArgs())
+ .isFalse();
+ assertThat(
+ getHostServiceFixtureInfoProvider(
+ getConfiguredTarget("//javatests/com/app:fixture_with_test_args"))
+ .getProvidesTestArgs())
+ .isTrue();
+ }
+
+ @Test
+ public void testProvidesDaemon() throws Exception {
+ scratch.file(
+ "javatests/com/app/BUILD",
+ "android_host_service_fixture(",
+ " name = 'no_daemon',",
+ " executable = '//java/com/server',",
+ ")",
+ "android_host_service_fixture(",
+ " name = 'daemon',",
+ " executable = '//java/com/server',",
+ " daemon = 1,",
+ ")");
+ assertThat(
+ getHostServiceFixtureInfoProvider(getConfiguredTarget("//javatests/com/app:no_daemon"))
+ .getIsDaemon())
+ .isFalse();
+ assertThat(
+ getHostServiceFixtureInfoProvider(getConfiguredTarget("//javatests/com/app:daemon"))
+ .getIsDaemon())
+ .isTrue();
+ }
+
+ private AndroidHostServiceFixtureInfoProvider getHostServiceFixtureInfoProvider(
+ ConfiguredTarget ct) throws Exception {
+ return (AndroidHostServiceFixtureInfoProvider)
+ ct.get(AndroidHostServiceFixtureInfoProvider.ANDROID_HOST_SERVICE_FIXTURE_INFO.getKey());
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
index db8e70ecda..8e732e018e 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
@@ -95,6 +95,22 @@ java_test(
)
java_test(
+ name = "AndroidHostServiceFixtureTest",
+ srcs = ["AndroidHostServiceFixtureTest.java"],
+ deps = [
+ ":AndroidBuildViewTestCase",
+ "//src/main/java/com/google/devtools/build/lib:android-rules",
+ "//src/main/java/com/google/devtools/build/lib:build-base",
+ "//src/main/java/com/google/devtools/build/lib/actions",
+ "//src/test/java/com/google/devtools/build/lib:actions_testutil",
+ "//src/test/java/com/google/devtools/build/lib:analysis_testutil",
+ "//src/test/java/com/google/devtools/build/lib:testutil",
+ "//third_party:junit4",
+ "//third_party:truth",
+ ],
+)
+
+java_test(
name = "AndroidInstrumentationRuleImplTest",
srcs = ["AndroidInstrumentationRuleImplTest.java"],
deps = [