|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2022 The Bazel Authors. All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -eu |
| 18 | + |
| 19 | +# Load the test setup defined in the parent directory |
| 20 | +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 21 | +source "${CURRENT_DIR}/../integration_test_setup.sh" \ |
| 22 | + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } |
| 23 | + |
| 24 | +function set_up_sh_test_coverage() { |
| 25 | + cat <<EOF > BUILD |
| 26 | +constraint_setting(name = "incompatible_setting") |
| 27 | +
|
| 28 | +constraint_value( |
| 29 | + name = "incompatible", |
| 30 | + constraint_setting = ":incompatible_setting", |
| 31 | +) |
| 32 | +
|
| 33 | +sh_test( |
| 34 | + name = "compatible_test", |
| 35 | + srcs = ["compatible_test.sh"], |
| 36 | +) |
| 37 | +
|
| 38 | +sh_test( |
| 39 | + name = "incompatible_test", |
| 40 | + srcs = ["incompatible_test.sh"], |
| 41 | + target_compatible_with = [":incompatible"], |
| 42 | +) |
| 43 | +EOF |
| 44 | + cat <<EOF > compatible_test.sh |
| 45 | +#!/bin/bash |
| 46 | +exit 0 |
| 47 | +EOF |
| 48 | + cat <<EOF > incompatible_test.sh |
| 49 | +#!/bin/bash |
| 50 | +exit 1 |
| 51 | +EOF |
| 52 | + chmod +x compatible_test.sh |
| 53 | + chmod +x incompatible_test.sh |
| 54 | +} |
| 55 | + |
| 56 | +# Validates that coverage skips incompatible tests. This is a regression test for |
| 57 | +# https://github.com/bazelbuild/bazel/issues/15385. |
| 58 | +function test_sh_test_coverage() { |
| 59 | + set_up_sh_test_coverage |
| 60 | + bazel coverage --test_output=all --combined_report=lcov //:all &>$TEST_log \ |
| 61 | + || fail "Coverage for //:all failed" |
| 62 | + expect_log "INFO: Build completed successfully" |
| 63 | + expect_log "//:compatible_test .* PASSED" |
| 64 | + expect_log "//:incompatible_test .* SKIPPED" |
| 65 | +} |
| 66 | + |
| 67 | +run_suite "test tests" |
0 commit comments