blob: 860f13a21350d8a0d86f5c220882edee6cde23ed [file] [log] [blame]
Dmitry Ivankov11717a12025-05-08 09:11:39 -07001#!/usr/bin/env bash
Laszlo Csomor894aab32018-07-29 23:56:52 -07002#
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 ---
22set -euo pipefail
23if [[ ! -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
31fi
32if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
33 source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
34elif [[ -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-)"
37else
38 echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
39 exit 1
40fi
41# --- end runfiles.bash initialization ---
42
43source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
44 || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
45
46output_base=$TEST_TMPDIR/out
47TEST_stderr=$(dirname $TEST_log)/stderr
48
49#### HELPER FUNCTIONS ##################################################
50
51function set_up() {
52 cd ${WORKSPACE_DIR}
53}
54
55function tear_down() {
56 bazel shutdown
57}
58
59#### TESTS #############################################################
60
Googler22c80012019-04-22 11:34:52 -070061function 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
philwoa9dc7492019-06-24 04:55:18 -070075function test_glob_utf8() {
Googler22c80012019-04-22 11:34:52 -070076 local -r pkg="$FUNCNAME"
77 mkdir $pkg
78 echo "filegroup(name='t', srcs=glob(['*']))" > $pkg/BUILD
79 cd $pkg
philwoa9dc7492019-06-24 04:55:18 -070080 # 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
Googler22c80012019-04-22 11:34:52 -070085 cd ..
86 bazel query "//$pkg:*" >& $TEST_log || fail "Expected success"
87}
88
nharmatace4cf602019-11-13 10:44:24 -080089function run_test_glob_with_io_error() {
90 local option=$1
Laszlo Csomor894aab32018-07-29 23:56:52 -070091 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
nharmatace4cf602019-11-13 10:44:24 -0800100 bazel query "$option" "//$pkg/t:*" >& $TEST_log && fail "Expected failure"
janakrdc9e15d2020-11-30 15:33:44 -0800101 # TODO(katre): when error message from ErrorDeterminingRepositoryException is
102 # improved, add it here too.
103 expect_log 'error globbing'
Laszlo Csomor894aab32018-07-29 23:56:52 -0700104
105 chmod 755 $pkg/t/u
nharmatace4cf602019-11-13 10:44:24 -0800106 bazel query "$option" "//$pkg/t:*" >& $TEST_log || fail "Expected success"
janakrdc9e15d2020-11-30 15:33:44 -0800107 expect_not_log 'error globbing'
Laszlo Csomor894aab32018-07-29 23:56:52 -0700108 expect_log "//$pkg/t:u"
109 expect_log "//$pkg/t:u/v"
110}
111
nharmatace4cf602019-11-13 10:44:24 -0800112function test_glob_with_io_error_nokeep_going() {
113 run_test_glob_with_io_error "--nokeep_going"
114}
115
116function test_glob_with_io_error_keep_going() {
117 run_test_glob_with_io_error "--keep_going"
118}
119
Laszlo Csomor894aab32018-07-29 23:56:52 -0700120function 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"
Googlercea4e302022-09-21 08:34:07 -0700140 ln -s foo $pkg/c/BUILD || fail "couldn't link $pkg/c/BUILD to foo"
Laszlo Csomor894aab32018-07-29 23:56:52 -0700141 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
149run_suite "Integration tests of ${PRODUCT_NAME} using loading/analysis phases."
150