Dmitry Ivankov | 11717a1 | 2025-05-08 09:11:39 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Laszlo Csomor | 894aab3 | 2018-07-29 23:56:52 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2015 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 | # loading_phase_tests.sh: miscellaneous integration tests of Bazel, |
| 18 | # that use only the loading or analysis phases. |
| 19 | # |
| 20 | |
| 21 | # --- begin runfiles.bash initialization --- |
| 22 | set -euo pipefail |
| 23 | if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 24 | if [[ -f "$0.runfiles_manifest" ]]; then |
| 25 | export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" |
| 26 | elif [[ -f "$0.runfiles/MANIFEST" ]]; then |
| 27 | export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" |
| 28 | elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 29 | export RUNFILES_DIR="$0.runfiles" |
| 30 | fi |
| 31 | fi |
| 32 | if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 33 | source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" |
| 34 | elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 35 | source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ |
| 36 | "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" |
| 37 | else |
| 38 | echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" |
| 39 | exit 1 |
| 40 | fi |
| 41 | # --- end runfiles.bash initialization --- |
| 42 | |
| 43 | source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \ |
| 44 | || { echo "integration_test_setup.sh not found!" >&2; exit 1; } |
| 45 | |
| 46 | output_base=$TEST_TMPDIR/out |
| 47 | TEST_stderr=$(dirname $TEST_log)/stderr |
| 48 | |
| 49 | #### HELPER FUNCTIONS ################################################## |
| 50 | |
| 51 | function set_up() { |
| 52 | cd ${WORKSPACE_DIR} |
| 53 | } |
| 54 | |
| 55 | function tear_down() { |
| 56 | bazel shutdown |
| 57 | } |
| 58 | |
| 59 | #### TESTS ############################################################# |
| 60 | |
Googler | 22c8001 | 2019-04-22 11:34:52 -0700 | [diff] [blame] | 61 | function test_glob_control_chars() { |
| 62 | local char escape raw |
| 63 | for char in {1..31} 127; do |
| 64 | local pkg="$FUNCNAME/char$char" |
| 65 | mkdir -p $pkg |
| 66 | echo "filegroup(name='t', srcs=glob(['*']))" > $pkg/BUILD |
| 67 | printf -v escape \\%03o $char |
| 68 | printf -v raw %b "$escape" |
| 69 | touch "$pkg/$raw" |
| 70 | bazel query "//$pkg:*" >& $TEST_log && fail "Expected failure" |
| 71 | expect_log 'invalid label' |
| 72 | done |
| 73 | } |
| 74 | |
philwo | a9dc749 | 2019-06-24 04:55:18 -0700 | [diff] [blame] | 75 | function test_glob_utf8() { |
Googler | 22c8001 | 2019-04-22 11:34:52 -0700 | [diff] [blame] | 76 | local -r pkg="$FUNCNAME" |
| 77 | mkdir $pkg |
| 78 | echo "filegroup(name='t', srcs=glob(['*']))" > $pkg/BUILD |
| 79 | cd $pkg |
philwo | a9dc749 | 2019-06-24 04:55:18 -0700 | [diff] [blame] | 80 | # This might print error messages for individual file names on systems like |
| 81 | # macOS that use a file system that only permits correct UTF-8 strings as file |
| 82 | # names. The errors can be ignored - we just test with whatever files the OS |
| 83 | # allowed us to create. |
| 84 | perl -CS -e 'for $i (160..0xd7ff) {print chr $i, $i%20?"":"\n"}' | xargs touch || true |
Googler | 22c8001 | 2019-04-22 11:34:52 -0700 | [diff] [blame] | 85 | cd .. |
| 86 | bazel query "//$pkg:*" >& $TEST_log || fail "Expected success" |
| 87 | } |
| 88 | |
nharmata | ce4cf60 | 2019-11-13 10:44:24 -0800 | [diff] [blame] | 89 | function run_test_glob_with_io_error() { |
| 90 | local option=$1 |
Laszlo Csomor | 894aab3 | 2018-07-29 23:56:52 -0700 | [diff] [blame] | 91 | local -r pkg="${FUNCNAME}" |
| 92 | mkdir -p "$pkg" || fail "could not create \"$pkg\"" |
| 93 | |
| 94 | mkdir -p $pkg/t/u |
| 95 | touch $pkg/t/u/v |
| 96 | |
| 97 | echo "filegroup(name='t', srcs=glob(['u/*']))" > $pkg/t/BUILD |
| 98 | chmod 000 $pkg/t/u |
| 99 | |
nharmata | ce4cf60 | 2019-11-13 10:44:24 -0800 | [diff] [blame] | 100 | bazel query "$option" "//$pkg/t:*" >& $TEST_log && fail "Expected failure" |
janakr | dc9e15d | 2020-11-30 15:33:44 -0800 | [diff] [blame] | 101 | # TODO(katre): when error message from ErrorDeterminingRepositoryException is |
| 102 | # improved, add it here too. |
| 103 | expect_log 'error globbing' |
Laszlo Csomor | 894aab3 | 2018-07-29 23:56:52 -0700 | [diff] [blame] | 104 | |
| 105 | chmod 755 $pkg/t/u |
nharmata | ce4cf60 | 2019-11-13 10:44:24 -0800 | [diff] [blame] | 106 | bazel query "$option" "//$pkg/t:*" >& $TEST_log || fail "Expected success" |
janakr | dc9e15d | 2020-11-30 15:33:44 -0800 | [diff] [blame] | 107 | expect_not_log 'error globbing' |
Laszlo Csomor | 894aab3 | 2018-07-29 23:56:52 -0700 | [diff] [blame] | 108 | expect_log "//$pkg/t:u" |
| 109 | expect_log "//$pkg/t:u/v" |
| 110 | } |
| 111 | |
nharmata | ce4cf60 | 2019-11-13 10:44:24 -0800 | [diff] [blame] | 112 | function test_glob_with_io_error_nokeep_going() { |
| 113 | run_test_glob_with_io_error "--nokeep_going" |
| 114 | } |
| 115 | |
| 116 | function test_glob_with_io_error_keep_going() { |
| 117 | run_test_glob_with_io_error "--keep_going" |
| 118 | } |
| 119 | |
Laszlo Csomor | 894aab3 | 2018-07-29 23:56:52 -0700 | [diff] [blame] | 120 | function test_build_file_symlinks() { |
| 121 | local -r pkg="${FUNCNAME}" |
| 122 | mkdir -p "$pkg" || fail "could not create \"$pkg\"" |
| 123 | |
| 124 | mkdir $pkg/b || fail "couldn't make $pkg/b" |
| 125 | ln -s b $pkg/a || fail "couldn't link $pkg/a to b" |
| 126 | |
| 127 | bazel query $pkg/a:all >& $TEST_log && fail "Expected failure" |
| 128 | expect_log "no such package '$pkg/a'" |
| 129 | |
| 130 | touch $pkg/b/BUILD |
| 131 | bazel query $pkg/a:all >& $TEST_log || fail "Expected success" |
| 132 | expect_log "Empty results" |
| 133 | |
| 134 | unlink $pkg/a || fail "couldn't unlink a" |
| 135 | ln -s c $pkg/a |
| 136 | bazel query $pkg/a:all >& $TEST_log && fail "Expected failure" |
| 137 | expect_log "no such package '$pkg/a'" |
| 138 | |
| 139 | mkdir $pkg/c || fail "couldn't make c" |
Googler | cea4e30 | 2022-09-21 08:34:07 -0700 | [diff] [blame] | 140 | ln -s foo $pkg/c/BUILD || fail "couldn't link $pkg/c/BUILD to foo" |
Laszlo Csomor | 894aab3 | 2018-07-29 23:56:52 -0700 | [diff] [blame] | 141 | bazel query $pkg/a:all >& $TEST_log && fail "Expected failure" |
| 142 | expect_log "no such package '$pkg/a'" |
| 143 | |
| 144 | touch $pkg/c/foo |
| 145 | bazel query $pkg/a:all >& $TEST_log || fail "Expected success" |
| 146 | expect_log "Empty results" |
| 147 | } |
| 148 | |
| 149 | run_suite "Integration tests of ${PRODUCT_NAME} using loading/analysis phases." |
| 150 | |