1# Copyright 2021 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15""" Bazel rules that test the Android Local Test rule. 16 17launcher_test: Asserts that the executable is populated correctly in the target script. 18""" 19 20def _android_local_test_launcher_integration(ctx): 21 substitutions = { 22 "%executable%": ctx.attr.target[DefaultInfo].files_to_run.executable.short_path, 23 "%expected_executable%": ctx.attr.expected_executable, 24 } 25 runner = ctx.actions.declare_file(ctx.label.name + "_runner.sh") 26 ctx.actions.expand_template( 27 template = ctx.file._test_stub_script, 28 substitutions = substitutions, 29 output = runner, 30 ) 31 return [ 32 DefaultInfo( 33 executable = runner, 34 runfiles = ctx.runfiles( 35 files = [ctx.attr.target[DefaultInfo].files_to_run.executable], 36 ), 37 ), 38 ] 39 40integration_test = rule( 41 attrs = dict( 42 target = attr.label(), 43 _test_stub_script = attr.label( 44 cfg = "exec", 45 default = ":integration_test_stub_script.sh", 46 allow_single_file = True, 47 ), 48 expected_executable = attr.string(), 49 ), 50 test = True, 51 implementation = _android_local_test_launcher_integration, 52) 53 54def android_local_test_launcher_integration_test_suite(name, expected_executable): 55 integration_test( 56 name = "android_local_test_default_launcher_integration", 57 target = ":sample_test_default_launcher_integration", 58 expected_executable = expected_executable, 59 ) 60 61 native.test_suite( 62 name = name, 63 tests = [":android_local_test_default_launcher_integration"], 64 ) 65