#!/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 < java/com/bin/AndroidManifest.xml < EOF cat > java/com/bin/Bar.java < java/com/bin/res/values/values.xml < EOF # Targets for instrumentation android_binary cat > javatests/com/bin/BUILD < javatests/com/bin/AndroidManifest.xml < EOF cat > javatests/com/bin/BarTest.java < javatests/com/bin/AndroidManifest.xml < EOF assert_build_fails //javatests/com/bin:instr \ "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 assert_build_fails //javatests/com/bin:instr \ "do not reference the same target package" } function test_android_instrumentation_binary_class_filtering() { create_new_workspace setup_android_sdk_support mkdir -p java/com/bin cat > java/com/bin/BUILD < java/com/bin/AndroidManifest.xml < EOF cat > java/com/bin/TestAndroidManifest.xml < EOF cat > java/com/bin/Foo.java < java/com/bin/Bar.java < java/com/bin/Baz.java < java/com/bin/res/values/values.xml < 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"