aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java1
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java2
-rw-r--r--src/test/shell/bazel/android/BUILD12
-rwxr-xr-xsrc/test/shell/bazel/android/android_instrumentation_test_integration_test.sh235
-rwxr-xr-xsrc/test/shell/bazel/android/android_integration_test.sh65
5 files changed, 249 insertions, 66 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index 622ae6e98d..bd77f4cba1 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -255,6 +255,7 @@ public final class BazelAnalysisMock extends AnalysisMock {
.add("java_plugin(name = 'databinding_annotation_processor',")
.add(" processor_class = 'android.databinding.annotationprocessor.ProcessDataBinding')")
.add("sh_binary(name = 'jarjar_bin', srcs = ['empty.sh'])")
+ .add("sh_binary(name = 'instrumentation_test_check', srcs = ['empty.sh'])")
.add("package_group(name = 'android_device_whitelist', packages = ['//...'])");
return androidBuildContents.build();
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java
index 6084ee30b5..60931e2d61 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationTestTest.java
@@ -211,7 +211,7 @@ public class AndroidInstrumentationTestTest extends AndroidBuildViewTestCase {
checkError(
"javatests/com/app/instr",
"ait",
- "The android_binary target at //javatests/com/app/instr:app "
+ "The android_binary target //javatests/com/app/instr:app "
+ "is missing an 'instruments' attribute",
"android_binary(",
" name = 'app',",
diff --git a/src/test/shell/bazel/android/BUILD b/src/test/shell/bazel/android/BUILD
index b149b01e41..97db86bacf 100644
--- a/src/test/shell/bazel/android/BUILD
+++ b/src/test/shell/bazel/android/BUILD
@@ -104,3 +104,15 @@ sh_test(
# This test builds an android_binary with Java 8 code.
tags = ["jdk8"],
)
+
+sh_test(
+ name = "android_instrumentation_test_integration_test",
+ size = "medium",
+ srcs = ["android_instrumentation_test_integration_test.sh"],
+ data = [
+ ":android_helper",
+ "//external:android_sdk_for_testing",
+ "//src/test/shell/bazel:test-deps",
+ ],
+ shard_count = 4,
+)
diff --git a/src/test/shell/bazel/android/android_instrumentation_test_integration_test.sh b/src/test/shell/bazel/android/android_instrumentation_test_integration_test.sh
new file mode 100755
index 0000000000..a189f42929
--- /dev/null
+++ b/src/test/shell/bazel/android/android_instrumentation_test_integration_test.sh
@@ -0,0 +1,235 @@
+#!/bin/bash
+#
+# 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.
+
+# For these tests to run do the following:
+#
+# 1. Install an Android SDK from https://developer.android.com
+# 2. Set the $ANDROID_HOME environment variable
+# 3. Uncomment the line in WORKSPACE containing android_sdk_repository
+
+# Load the test setup defined in the parent directory
+CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+source "${CURRENT_DIR}/android_helper.sh" \
+ || { echo "android_helper.sh not found!" >&2; exit 1; }
+fail_if_no_android_sdk
+
+source "${CURRENT_DIR}/../../integration_test_setup.sh" \
+ || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
+
+function setup_android_instrumentation_test_env() {
+ mkdir -p java/com/bin/res/values
+ mkdir -p javatests/com/bin
+
+ # Targets for android_binary application under test
+ cat > java/com/bin/BUILD <<EOF
+android_binary(
+ name = 'target',
+ manifest = 'AndroidManifest.xml',
+ deps = [':lib'],
+ visibility = ["//visibility:public"],
+)
+android_library(
+ name = 'lib',
+ manifest = 'AndroidManifest.xml',
+ exports_manifest = 0,
+ resource_files = ['res/values/values.xml'],
+ srcs = ['Bar.java'],
+ visibility = ["//visibility:public"],
+)
+EOF
+ cat > java/com/bin/AndroidManifest.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package='com.bin' xmlns:android="http://schemas.android.com/apk/res/android" />
+EOF
+ cat > java/com/bin/Bar.java <<EOF
+package com.bin;
+public class Bar { }
+EOF
+ cat > java/com/bin/res/values/values.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+</resources>
+EOF
+
+ # Targets for instrumentation android_binary
+ cat > javatests/com/bin/BUILD <<EOF
+android_binary(
+ name = 'instr',
+ srcs = ['BarTest.java'],
+ manifest = 'AndroidManifest.xml',
+ instruments = '//java/com/bin:target',
+ deps = ['//java/com/bin:lib'],
+)
+EOF
+ cat > javatests/com/bin/AndroidManifest.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package='com.bin' xmlns:android='http://schemas.android.com/apk/res/android'>
+ <instrumentation android:targetPackage='com.bin' android:name='some.test.runner' />
+</manifest>
+EOF
+ cat > javatests/com/bin/BarTest.java <<EOF
+package com.bin;
+public class BarTest {
+ public Bar getBar() {
+ return new Bar();
+ }
+}
+EOF
+}
+
+function test_correct_target_package_build_succeed() {
+ create_new_workspace
+ setup_android_sdk_support
+ setup_android_instrumentation_test_env
+ assert_build //javatests/com/bin:instr
+}
+
+function test_incorrect_target_package_build_failure() {
+ create_new_workspace
+ setup_android_sdk_support
+ setup_android_instrumentation_test_env
+
+ cat > javatests/com/bin/AndroidManifest.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package='com.bin' xmlns:android='http://schemas.android.com/apk/res/android'>
+ <instrumentation android:targetPackage='not.com.bin' android:name='some.test.runner' />
+</manifest>
+EOF
+
+ assert_build_fails //javatests/com/bin:instr
+ expect_log "does not match the package name of"
+}
+
+function test_multiple_instrumentations_with_different_package_names_build_failure() {
+ create_new_workspace
+ setup_android_sdk_support
+ setup_android_instrumentation_test_env
+
+ cat > javatests/com/bin/AndroidManifest.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package='com.bin' xmlns:android='http://schemas.android.com/apk/res/android'>
+ <instrumentation android:targetPackage='com.bin' android:name='some.test.runner' />
+ <instrumentation android:targetPackage='not.com.bin' android:name='some.test.runner' />
+</manifest>
+EOF
+
+ assert_build_fails //javatests/com/bin:instr
+ expect_log "do not reference the same target package"
+}
+
+function test_no_target_package_attribute_build_failure() {
+ create_new_workspace
+ setup_android_sdk_support
+ setup_android_instrumentation_test_env
+
+ cat > javatests/com/bin/AndroidManifest.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package='com.bin' xmlns:android='http://schemas.android.com/apk/res/android'>
+ <instrumentation />
+</manifest>
+EOF
+
+ assert_build_fails //javatests/com/bin:instr
+ expect_log "No <instrumentation> tag containing the targetPackage attribute"
+}
+
+function test_target_package_no_package_specified_build_failure() {
+ create_new_workspace
+ setup_android_sdk_support
+ setup_android_instrumentation_test_env
+
+ cat > java/com/bin/AndroidManifest.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
+EOF
+
+ assert_build_fails //javatests/com/bin:instr
+ expect_log "needs to specify the package name"
+}
+
+function test_android_instrumentation_binary_class_filtering() {
+ create_new_workspace
+ setup_android_sdk_support
+ mkdir -p java/com/bin
+ cat > java/com/bin/BUILD <<EOF
+android_binary(
+ name = 'instr',
+ srcs = ['Foo.java'],
+ manifest = 'TestAndroidManifest.xml',
+ instruments = ':target',
+ deps = [':lib'],
+)
+android_binary(
+ name = 'target',
+ manifest = 'AndroidManifest.xml',
+ deps = [':lib'],
+)
+android_library(
+ name = 'lib',
+ manifest = 'AndroidManifest.xml',
+ resource_files = ['res/values/values.xml'],
+ srcs = ['Bar.java', 'Baz.java'],
+)
+EOF
+ cat > java/com/bin/AndroidManifest.xml <<EOF
+<manifest package='com.bin' />
+EOF
+ cat > java/com/bin/TestAndroidManifest.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package='com.bin' xmlns:android='http://schemas.android.com/apk/res/android'>
+ <instrumentation android:targetPackage='com.bin' android:name='some.test.runner' />
+</manifest>
+EOF
+ cat > java/com/bin/Foo.java <<EOF
+package com.bin;
+public class Foo {
+ public Bar getBar() {
+ return new Bar();
+ }
+ public Baz getBaz() {
+ return new Baz();
+ }
+}
+EOF
+ cat > java/com/bin/Bar.java <<EOF
+package com.bin;
+public class Bar {
+ public Baz getBaz() {
+ return new Baz();
+ }
+}
+EOF
+ cat > java/com/bin/Baz.java <<EOF
+package com.bin;
+public class Baz {}
+EOF
+ mkdir -p java/com/bin/res/values
+ cat > java/com/bin/res/values/values.xml <<EOF
+<?xml version="1.0" encoding="utf-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+</resources>
+EOF
+ assert_build //java/com/bin:instr
+ output_classes=$(zipinfo -1 bazel-bin/java/com/bin/instr_filtered.jar)
+ assert_one_of $output_classes "META-INF/MANIFEST.MF"
+ assert_one_of $output_classes "com/bin/Foo.class"
+ assert_not_one_of $output_classes "com/bin/R.class"
+ assert_not_one_of $output_classes "com/bin/Bar.class"
+ assert_not_one_of $output_classes "com/bin/Baz.class"
+}
+
+run_suite "android_instrumentation_test integration tests"
+
diff --git a/src/test/shell/bazel/android/android_integration_test.sh b/src/test/shell/bazel/android/android_integration_test.sh
index 171f7b83e6..557816083b 100755
--- a/src/test/shell/bazel/android/android_integration_test.sh
+++ b/src/test/shell/bazel/android/android_integration_test.sh
@@ -61,69 +61,4 @@ function test_allow_custom_manifest_name() {
"Failed to build android_binary with custom Android manifest file name"
}
-function test_android_instrumentation_binary_class_filtering() {
- create_new_workspace
- setup_android_sdk_support
- mkdir -p java/com/bin
- cat > java/com/bin/BUILD <<EOF
-android_binary(
- name = 'instr',
- srcs = ['Foo.java'],
- manifest = 'AndroidManifest.xml',
- instruments = ':target',
- deps = [':lib'],
-)
-android_binary(
- name = 'target',
- manifest = 'AndroidManifest.xml',
- deps = [':lib'],
-)
-android_library(
- name = 'lib',
- manifest = 'AndroidManifest.xml',
- resource_files = ['res/values/values.xml'],
- srcs = ['Bar.java', 'Baz.java'],
-)
-EOF
- cat > java/com/bin/AndroidManifest.xml <<EOF
-<manifest package='com.bin' />
-EOF
- cat > java/com/bin/Foo.java <<EOF
-package com.bin;
-public class Foo {
- public Bar getBar() {
- return new Bar();
- }
- public Baz getBaz() {
- return new Baz();
- }
-}
-EOF
- cat > java/com/bin/Bar.java <<EOF
-package com.bin;
-public class Bar {
- public Baz getBaz() {
- return new Baz();
- }
-}
-EOF
- cat > java/com/bin/Baz.java <<EOF
-package com.bin;
-public class Baz {}
-EOF
- mkdir -p java/com/bin/res/values
- cat > java/com/bin/res/values/values.xml <<EOF
-<?xml version="1.0" encoding="utf-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android">
-</resources>
-EOF
- assert_build //java/com/bin:instr
- output_classes=$(zipinfo -1 bazel-bin/java/com/bin/instr_filtered.jar)
- assert_one_of $output_classes "META-INF/MANIFEST.MF"
- assert_one_of $output_classes "com/bin/Foo.class"
- assert_not_one_of $output_classes "com/bin/R.class"
- assert_not_one_of $output_classes "com/bin/Bar.class"
- assert_not_one_of $output_classes "com/bin/Baz.class"
-}
-
run_suite "Android integration tests"