aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2018-07-29 23:56:52 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-29 23:58:24 -0700
commit894aab3f87a6176c5490b90a31bc58d50f3cb221 (patch)
tree6c3cccef6e0e37a3fac65c96b87e12f5b64004d9 /src/test/shell
parent696442c2cf3ab935b328000b78cac210300a7004 (diff)
Windows,tests: port loading_phase_tests
//src/test/shell/integration:loading_phase_tests now runs on Windows. The inherently incompatible parts of the test are now in //src/test/shell/integration:loading_phase_posix_tests See https://github.com/bazelbuild/bazel/issues/4292 Change-Id: I90db31449e72aed2138916eed6289bcc20af5cae Closes #5685. Change-Id: I38727aed1b548ec8b566f99551e63cceac78180b PiperOrigin-RevId: 206533515
Diffstat (limited to 'src/test/shell')
-rw-r--r--src/test/shell/integration/BUILD21
-rwxr-xr-xsrc/test/shell/integration/loading_phase_posix_test.sh111
-rwxr-xr-xsrc/test/shell/integration/loading_phase_test.sh351
-rwxr-xr-xsrc/test/shell/integration/loading_phase_tests.sh328
4 files changed, 480 insertions, 331 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index 69aa68f75c..9dc0aae2c4 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -50,10 +50,25 @@ sh_test(
sh_test(
name = "loading_phase_tests",
size = "large",
- srcs = ["loading_phase_tests.sh"],
- data = [":test-deps"],
+ srcs = ["loading_phase_test.sh"],
+ data = [
+ ":test-deps",
+ "@bazel_tools//tools/bash/runfiles",
+ ],
shard_count = 4,
- tags = ["no_windows"],
+)
+
+sh_test(
+ name = "loading_phase_posix_tests",
+ size = "large",
+ srcs = ["loading_phase_posix_test.sh"],
+ data = [
+ ":test-deps",
+ "@bazel_tools//tools/bash/runfiles",
+ ],
+ tags = [
+ "no_windows", # test uses symlinks and chmod
+ ],
)
sh_test(
diff --git a/src/test/shell/integration/loading_phase_posix_test.sh b/src/test/shell/integration/loading_phase_posix_test.sh
new file mode 100755
index 0000000000..21abb59fff
--- /dev/null
+++ b/src/test/shell/integration/loading_phase_posix_test.sh
@@ -0,0 +1,111 @@
+#!/bin/bash
+#
+# Copyright 2015 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.
+#
+# loading_phase_tests.sh: miscellaneous integration tests of Bazel,
+# that use only the loading or analysis phases.
+#
+
+# --- begin runfiles.bash initialization ---
+set -euo pipefail
+if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ if [[ -f "$0.runfiles_manifest" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
+ elif [[ -f "$0.runfiles/MANIFEST" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
+ elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ export RUNFILES_DIR="$0.runfiles"
+ fi
+fi
+if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
+elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
+ "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
+else
+ echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
+ exit 1
+fi
+# --- end runfiles.bash initialization ---
+
+source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
+ || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
+
+output_base=$TEST_TMPDIR/out
+TEST_stderr=$(dirname $TEST_log)/stderr
+
+#### HELPER FUNCTIONS ##################################################
+
+function set_up() {
+ cd ${WORKSPACE_DIR}
+}
+
+function tear_down() {
+ bazel shutdown
+}
+
+#### TESTS #############################################################
+
+function test_glob_with_io_error() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir -p $pkg/t/u
+ touch $pkg/t/u/v
+
+ echo "filegroup(name='t', srcs=glob(['u/*']))" > $pkg/t/BUILD
+ chmod 000 $pkg/t/u
+
+ bazel query "//$pkg/t:*" >& $TEST_log && fail "Expected failure"
+ expect_log 'error globbing.*Permission denied'
+
+ chmod 755 $pkg/t/u
+ bazel query "//$pkg/t:*" >& $TEST_log || fail "Expected success"
+ expect_not_log 'error globbing.*Permission denied'
+ expect_log "//$pkg/t:u"
+ expect_log "//$pkg/t:u/v"
+}
+
+function test_build_file_symlinks() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir $pkg/b || fail "couldn't make $pkg/b"
+ ln -s b $pkg/a || fail "couldn't link $pkg/a to b"
+
+ bazel query $pkg/a:all >& $TEST_log && fail "Expected failure"
+ expect_log "no such package '$pkg/a'"
+
+ touch $pkg/b/BUILD
+ bazel query $pkg/a:all >& $TEST_log || fail "Expected success"
+ expect_log "Empty results"
+
+ unlink $pkg/a || fail "couldn't unlink a"
+ ln -s c $pkg/a
+ bazel query $pkg/a:all >& $TEST_log && fail "Expected failure"
+ expect_log "no such package '$pkg/a'"
+
+ mkdir $pkg/c || fail "couldn't make c"
+ ln -s foo $pkg/c/BUILD || "couldn't link $pkg/c/BUILD to foo"
+ bazel query $pkg/a:all >& $TEST_log && fail "Expected failure"
+ expect_log "no such package '$pkg/a'"
+
+ touch $pkg/c/foo
+ bazel query $pkg/a:all >& $TEST_log || fail "Expected success"
+ expect_log "Empty results"
+}
+
+run_suite "Integration tests of ${PRODUCT_NAME} using loading/analysis phases."
+
diff --git a/src/test/shell/integration/loading_phase_test.sh b/src/test/shell/integration/loading_phase_test.sh
new file mode 100755
index 0000000000..5e1d76642c
--- /dev/null
+++ b/src/test/shell/integration/loading_phase_test.sh
@@ -0,0 +1,351 @@
+#!/bin/bash
+#
+# Copyright 2015 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.
+#
+# loading_phase_tests.sh: miscellaneous integration tests of Bazel,
+# that use only the loading or analysis phases.
+#
+
+# --- begin runfiles.bash initialization ---
+set -euo pipefail
+if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ if [[ -f "$0.runfiles_manifest" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
+ elif [[ -f "$0.runfiles/MANIFEST" ]]; then
+ export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
+ elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ export RUNFILES_DIR="$0.runfiles"
+ fi
+fi
+if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+ source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
+elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+ source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
+ "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
+else
+ echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
+ exit 1
+fi
+# --- end runfiles.bash initialization ---
+
+source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
+ || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
+
+case "$(uname -s | tr [:upper:] [:lower:])" in
+msys*|mingw*|cygwin*)
+ declare -r is_windows=true
+ ;;
+*)
+ declare -r is_windows=false
+ ;;
+esac
+
+if "$is_windows"; then
+ export MSYS_NO_PATHCONV=1
+ export MSYS2_ARG_CONV_EXCL="*"
+fi
+
+# Our tests use the static crosstool, so make it the default.
+# add_to_bazelrc "build --crosstool_top=@bazel_tools//tools/cpp:default-toolchain"
+
+output_base=$TEST_TMPDIR/out
+TEST_stderr=$(dirname $TEST_log)/stderr
+
+#### HELPER FUNCTIONS ##################################################
+
+function set_up() {
+ cd ${WORKSPACE_DIR}
+}
+
+function tear_down() {
+ bazel shutdown
+}
+
+#### TESTS #############################################################
+
+function test_query_buildfiles_with_load() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir -p $pkg/x || fail "mkdir $pkg/x failed"
+ echo "load('//$pkg/y:rules.bzl', 'a')" >$pkg/x/BUILD
+ echo "cc_library(name='x')" >>$pkg/x/BUILD
+ mkdir -p $pkg/y || fail "mkdir $pkg/y failed"
+ touch $pkg/y/BUILD
+ echo "a=1" >$pkg/y/rules.bzl
+
+ bazel query --noshow_progress "buildfiles(//$pkg/x)" >$TEST_log ||
+ fail "Expected success"
+ expect_log //$pkg/x:BUILD
+ expect_log //$pkg/y:BUILD
+ expect_log //$pkg/y:rules.bzl
+
+ # null terminated:
+ bazel query --noshow_progress --null "buildfiles(//$pkg/x)" >$pkg/null.log ||
+ fail "Expected null success"
+ printf "//$pkg/y:rules.bzl\0//$pkg/y:BUILD\0//$pkg/x:BUILD\0" >$pkg/null.ref.log
+ cmp $pkg/null.ref.log $pkg/null.log || fail "Expected match"
+
+ # Missing skylark file:
+ rm -f $pkg/y/rules.bzl
+ bazel query --noshow_progress "buildfiles(//$pkg/x)" 2>$TEST_log &&
+ fail "Expected error"
+ expect_log "Extension file not found. Unable to load file '//$pkg/y:rules.bzl'"
+}
+
+# Regression test for:
+# "Skyframe does not build targets that transitively depend on non-rule targets
+# that live in packages with errors".
+function test_non_error_target_in_bad_pkg() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir -p $pkg/a || fail "mkdir $pkg/a failed"
+ mkdir -p $pkg/b || fail "mkdir $pkg/b failed"
+
+ echo "sh_library(name = 'a', data = ['//$pkg/b'])" > $pkg/a/BUILD
+ echo "exports_files(['b'])" > $pkg/b/BUILD
+ echo "genrule(name='r1', cmd = '', outs = ['conflict'])" >> $pkg/b/BUILD
+ echo "genrule(name='r2', cmd = '', outs = ['conflict'])" >> $pkg/b/BUILD
+
+ bazel build --nobuild -k //$pkg/a >& $TEST_log && fail "Expected failure"
+ expect_log "'conflict' in rule"
+ expect_not_log "Loading failed"
+ expect_log "but there were loading phase errors"
+ expect_not_log "Loading succeeded for only"
+}
+
+# This is a regression test to make sure that none of the bazel
+# commands has an incompatible set of @Options annotations. In the
+# past, options have been declared multiple times, making a command
+# unusable.
+function test_options_errors() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ # Enumerate bazel commands...
+ bazel help 2>/dev/null |
+ grep '^ [a-z]' |
+ grep -v '^ '${PRODUCT_NAME}' ' |
+ awk '{print $1}' |
+ while read command; do
+ bazel $command >$TEST_log 2>&1 || true
+ # Mustn't crash in the options package:
+ expect_not_log "Duplicate option name"
+ expect_not_log "at com.google.devtools.build.lib"
+ expect_not_log "lib.util.options.*Exception"
+ done
+}
+
+function test_bazelrc_option() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ if [[ "$(realpath "${bazelrc}")" != "$(realpath ".${PRODUCT_NAME}rc")" ]]; then
+ cp "${bazelrc}" ".${PRODUCT_NAME}rc"
+ fi
+
+ echo "build --subcommands" >>".${PRODUCT_NAME}rc" # default bazelrc
+ $PATH_TO_BAZEL_BIN info --announce_rc >/dev/null 2>$TEST_log
+ expect_log "Reading.*$pkg[/\\\\].${PRODUCT_NAME}rc:
+.*--subcommands"
+
+ cp .${PRODUCT_NAME}rc $pkg/foo
+ echo "build --nosubcommands" >>$pkg/foo # non-default bazelrc
+ $PATH_TO_BAZEL_BIN --${PRODUCT_NAME}rc=$pkg/foo info --announce_rc >/dev/null \
+ 2>$TEST_log
+ expect_log "Reading.*$pkg[/\\\\]foo:
+.*--nosubcommands"
+}
+
+# This exercises the production-code assertion in AbstractCommand.java
+# that all help texts mention their %{options}.
+function test_all_help_topics_succeed() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ topics=($(bazel help 2>/dev/null |
+ grep '^ [a-z]' |
+ grep -v '^ '${PRODUCT_NAME}' ' |
+ awk '{print $1}') \
+ startup_options \
+ target-syntax)
+ for topic in "${topics[@]}"; do
+ bazel help $topic >$TEST_log 2>&1 || {
+ fail "help $topic failed"
+ expect_not_log . # print the log
+ }
+ done
+ [ ${#topics[@]} -gt 15 ] || fail "Hmmm: not many topics: ${topics[*]}."
+}
+
+# Regression for "Sticky error during analysis phase when input is cyclic".
+function test_regress_cycle_during_analysis_phase() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir -p $pkg/cycle $pkg/main
+ cat >$pkg/main/BUILD <<EOF
+genrule(name='mygenrule', outs=['baz.h'], srcs=['//$pkg/cycle:foo.h'], cmd=':')
+EOF
+ cat >$pkg/cycle/BUILD <<EOF
+genrule(name='foo.h', outs=['bar.h'], srcs=['foo.h'], cmd=':')
+EOF
+ bazel build --nobuild //$pkg/cycle:foo.h >$TEST_log 2>&1 || true
+ expect_log "in genrule rule //$pkg/cycle:foo.h: .*dependency graph"
+ expect_log "//$pkg/cycle:foo.h.*self-edge"
+
+ bazel build --nobuild //$pkg/main:mygenrule >$TEST_log 2>&1 || true
+ expect_log "in genrule rule //$pkg/cycle:foo.h: .*dependency graph"
+ expect_log "//$pkg/cycle:foo.h.*self-edge"
+
+ bazel build --nobuild //$pkg/cycle:foo.h >$TEST_log 2>&1 || true
+ expect_log "in genrule rule //$pkg/cycle:foo.h: .*dependency graph"
+ expect_log "//$pkg/cycle:foo.h.*self-edge"
+}
+
+# glob function should not return values that are outside the package
+function test_glob_with_subpackage() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir -p $pkg/p/subpkg || fail "mkdir $pkg/p/subpkg failed"
+ mkdir -p $pkg/p/dir || fail "mkdir $pkg/p/dir failed"
+
+ echo "exports_files(glob(['**/*.txt']))" >$pkg/p/BUILD
+ echo "# Empty" >$pkg/p/subpkg/BUILD
+
+ echo "$pkg/p/t1.txt" > $pkg/p/t1.txt
+ echo "$pkg/p/dir/t2.txt" > $pkg/p/dir/t2.txt
+ echo "$pkg/p/subpkg/t3.txt" > $pkg/p/subpkg/t3.txt
+
+ bazel query "$pkg/p:*" >$TEST_log || fail "Expected success"
+ expect_log "//$pkg/p:t1\.txt"
+ expect_log "//$pkg/p:dir/t2\.txt"
+ expect_log "//$pkg/p:BUILD"
+ expect_not_log 't3\.txt'
+ assert_equals "3" $(wc -l "$TEST_log")
+
+ # glob returns an empty list, because t3.txt is outside the package
+ echo "exports_files(glob(['subpkg/t3.txt']))" >$pkg/p/BUILD
+ bazel query "$pkg/p:*" -k >$TEST_log || fail "Expected success"
+ expect_log "//$pkg/p:BUILD"
+ assert_equals "1" $(wc -l "$TEST_log")
+
+ # same test, with a nonexisting file
+ echo "exports_files(glob(['subpkg/no_glob.txt']))" >$pkg/p/BUILD
+ bazel query "$pkg/p:*" -k >$TEST_log || fail "Expected success"
+ expect_log "//$pkg/p:BUILD"
+ assert_equals "1" $(wc -l "$TEST_log")
+
+ # Non-recursive wildcard gives the same result as the recursive wildcard
+ echo "exports_files(glob(['*.txt', '*/*.txt']))" >$pkg/p/BUILD
+ bazel query "$pkg/p:*" >$TEST_log || fail "Expected success"
+ expect_log "//$pkg/p:t1\.txt"
+ expect_log "//$pkg/p:dir/t2\.txt"
+ expect_log "//$pkg/p:BUILD"
+ expect_not_log 't3\.txt'
+ assert_equals "3" $(wc -l "$TEST_log")
+}
+
+function test_glob_with_subpackage2() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir -p $pkg/p/q/subpkg || fail "mkdir $pkg/p/q/subpkg failed"
+ mkdir -p $pkg/p/q/dir || fail "mkdir $pkg/p/q/dir failed"
+
+ echo "exports_files(glob(['**/*.txt']))" >$pkg/p/q/BUILD
+ echo "# Empty" >$pkg/p/q/subpkg/BUILD
+
+ echo "$pkg/p/q/t1.txt" > $pkg/p/q/t1.txt
+ echo "$pkg/p/q/dir/t2.txt" > $pkg/p/q/dir/t2.txt
+ echo "$pkg/p/q/subpkg/t3.txt" > $pkg/p/q/subpkg/t3.txt
+
+ bazel query "$pkg/p/q:*" >$TEST_log || fail "Expected success"
+ expect_log "//$pkg/p/q:t1\.txt"
+ expect_log "//$pkg/p/q:dir/t2\.txt"
+ expect_log "//$pkg/p/q:BUILD"
+ expect_not_log 't3\.txt'
+ assert_equals "3" $(wc -l "$TEST_log")
+}
+
+# Regression test for bug "ASTFileLookupFunction has an unnoted
+# dependency on the PathPackageLocator".
+function test_incremental_deleting_package_roots() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ local other_root=$TEST_TMPDIR/other_root/${WORKSPACE_NAME}
+ mkdir -p $other_root/$pkg/a
+ touch $other_root/WORKSPACE
+ echo 'sh_library(name="external")' > $other_root/$pkg/a/BUILD
+ mkdir -p $pkg/a
+ echo 'sh_library(name="internal")' > $pkg/a/BUILD
+
+ bazel query --package_path=$other_root:. $pkg/a:all >& $TEST_log \
+ || fail "Expected success"
+ expect_log "//$pkg/a:external"
+ expect_not_log "//$pkg/a:internal"
+ rm -r $other_root
+ bazel query --package_path=$other_root:. $pkg/a:all >& $TEST_log \
+ || fail "Expected success"
+ expect_log "//$pkg/a:internal"
+ expect_not_log "//$pkg/a:external"
+ mkdir -p $other_root
+ bazel query --package_path=$other_root:. $pkg/a:all >& $TEST_log \
+ || fail "Expected success"
+ expect_log "//$pkg/a:internal"
+ expect_not_log "//$pkg/a:external"
+}
+
+function test_no_package_loading_on_benign_workspace_file_changes() {
+ local -r pkg="${FUNCNAME}"
+ mkdir -p "$pkg" || fail "could not create \"$pkg\""
+
+ mkdir $pkg/foo
+
+ echo 'workspace(name="wsname1")' > WORKSPACE
+ echo 'sh_library(name="shname1")' > $pkg/foo/BUILD
+ # TODO(b/37617303): make tests UI-independent
+ bazel query --noexperimental_ui //$pkg/foo:all >& "$TEST_log" \
+ || fail "Expected success"
+ expect_log "Loading package: $pkg/foo"
+ expect_log "//$pkg/foo:shname1"
+
+ echo 'sh_library(name="shname2")' > $pkg/foo/BUILD
+ # TODO(b/37617303): make tests UI-independent
+ bazel query --noexperimental_ui //$pkg/foo:all >& "$TEST_log" \
+ || fail "Expected success"
+ expect_log "Loading package: $pkg/foo"
+ expect_log "//$pkg/foo:shname2"
+
+ # Test that comment changes do not cause package reloading
+ echo '#benign comment' >> WORKSPACE
+ # TODO(b/37617303): make tests UI-independent
+ bazel query --noexperimental_ui //$pkg/foo:all >& "$TEST_log" \
+ || fail "Expected success"
+ expect_not_log "Loading package: $pkg/foo"
+ expect_log "//$pkg/foo:shname2"
+
+ echo 'workspace(name="wsname2")' > WORKSPACE
+ # TODO(b/37617303): make tests UI-independent
+ bazel query --noexperimental_ui //$pkg/foo:all >& "$TEST_log" \
+ || fail "Expected success"
+ expect_log "Loading package: $pkg/foo"
+ expect_log "//$pkg/foo:shname2"
+}
+
+run_suite "Integration tests of ${PRODUCT_NAME} using loading/analysis phases."
diff --git a/src/test/shell/integration/loading_phase_tests.sh b/src/test/shell/integration/loading_phase_tests.sh
deleted file mode 100755
index 02573b1d59..0000000000
--- a/src/test/shell/integration/loading_phase_tests.sh
+++ /dev/null
@@ -1,328 +0,0 @@
-#!/bin/bash
-#
-# Copyright 2015 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.
-#
-# loading_phase_tests.sh: miscellaneous integration tests of Bazel,
-# that use only the loading or analysis phases.
-#
-
-# Our tests use the static crosstool, so make it the default.
-add_to_bazelrc "build --crosstool_top=@bazel_tools//tools/cpp:default-toolchain"
-
-# Load the test setup defined in the parent directory
-CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-source "${CURRENT_DIR}/../integration_test_setup.sh" \
- || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
-
-output_base=$TEST_TMPDIR/out
-TEST_stderr=$(dirname $TEST_log)/stderr
-
-#### HELPER FUNCTIONS ##################################################
-
-function set_up() {
- cd ${WORKSPACE_DIR}
-}
-
-function tear_down() {
- bazel shutdown
-}
-
-#### TESTS #############################################################
-
-function test_query_buildfiles_with_load() {
- mkdir -p x || fail "mkdir x failed"
- echo "load('//y:rules.bzl', 'a')" >x/BUILD
- echo "cc_library(name='x')" >>x/BUILD
- mkdir -p y || fail "mkdir y failed"
- touch y/BUILD
- echo "a=1" >y/rules.bzl
-
- bazel query --noshow_progress 'buildfiles(//x)' >$TEST_log ||
- fail "Expected success"
- expect_log //x:BUILD
- expect_log //y:BUILD
- expect_log //y:rules.bzl
-
- # null terminated:
- bazel query --noshow_progress --null 'buildfiles(//x)' >null.log ||
- fail "Expected null success"
- printf '//y:rules.bzl\0//y:BUILD\0//x:BUILD\0' >null.ref.log
- cmp null.ref.log null.log || fail "Expected match"
-
- # Missing skylark file:
- rm -f y/rules.bzl
- bazel query --noshow_progress 'buildfiles(//x)' 2>$TEST_log &&
- fail "Expected error"
- expect_log "Extension file not found. Unable to load file '//y:rules.bzl'"
-}
-
-# Regression test for:
-# "Skyframe does not build targets that transitively depend on non-rule targets
-# that live in packages with errors".
-function test_non_error_target_in_bad_pkg() {
- mkdir -p a || fail "mkdir a failed"
- mkdir -p b || fail "mkdir b failed"
-
- echo "sh_library(name = 'a', data = ['//b'])" > a/BUILD
- echo "exports_files(['b'])" > b/BUILD
- echo "genrule(name='r1', cmd = '', outs = ['conflict'])" >> b/BUILD
- echo "genrule(name='r2', cmd = '', outs = ['conflict'])" >> b/BUILD
-
- bazel build --nobuild -k //a >& $TEST_log && fail "Expected failure"
- expect_log "'conflict' in rule"
- expect_not_log "Loading failed"
- expect_log "but there were loading phase errors"
- expect_not_log "Loading succeeded for only"
-}
-
-# This is a regression test to make sure that none of the bazel
-# commands has an incompatible set of @Options annotations. In the
-# past, options have been declared multiple times, making a command
-# unusable.
-function test_options_errors() {
- # Enumerate bazel commands...
- bazel help 2>/dev/null |
- grep '^ [a-z]' |
- grep -v '^ '${PRODUCT_NAME}' ' |
- awk '{print $1}' |
- while read command; do
- bazel $command >$TEST_log 2>&1 || true
- # Mustn't crash in the options package:
- expect_not_log "Duplicate option name"
- expect_not_log "at com.google.devtools.build.lib"
- expect_not_log "lib.util.options.*Exception"
- done
-}
-
-function test_bazelrc_option() {
- cp ${bazelrc} ${new_workspace_dir}/.${PRODUCT_NAME}rc
-
- echo "build --cpu=armeabi-v7a" >>.${PRODUCT_NAME}rc # default bazelrc
- $PATH_TO_BAZEL_BIN info --announce_rc >/dev/null 2>$TEST_log
- expect_log "Reading.*$(pwd)/.${PRODUCT_NAME}rc:
-.*--cpu=armeabi-v7a"
-
- cp .${PRODUCT_NAME}rc foo
- echo "build --cpu=armeabi-v7a" >>foo # non-default bazelrc
- $PATH_TO_BAZEL_BIN --${PRODUCT_NAME}rc=foo info --announce_rc >/dev/null \
- 2>$TEST_log
- expect_log "Reading.*$(pwd)/foo:
-.*--cpu=armeabi-v7a"
-}
-
-# This exercises the production-code assertion in AbstractCommand.java
-# that all help texts mention their %{options}.
-function test_all_help_topics_succeed() {
- topics=($(bazel help 2>/dev/null |
- grep '^ [a-z]' |
- grep -v '^ '${PRODUCT_NAME}' ' |
- awk '{print $1}') \
- startup_options \
- target-syntax)
- for topic in "${topics[@]}"; do
- bazel help $topic >$TEST_log 2>&1 || {
- fail "help $topic failed"
- expect_not_log . # print the log
- }
- done
- [ ${#topics[@]} -gt 15 ] || fail "Hmmm: not many topics: ${topics[*]}."
-}
-
-# Regression for "Sticky error during analysis phase when input is cyclic".
-function test_regress_cycle_during_analysis_phase() {
- mkdir -p cycle main
- cat >main/BUILD <<EOF
-genrule(name='mygenrule', outs=['baz.h'], srcs=['//cycle:foo.h'], cmd=':')
-EOF
- cat >cycle/BUILD <<EOF
-genrule(name='foo.h', outs=['bar.h'], srcs=['foo.h'], cmd=':')
-EOF
- bazel build --nobuild //cycle:foo.h >$TEST_log 2>&1 || true
- expect_log "in genrule rule //cycle:foo.h: .*dependency graph"
- expect_log "//cycle:foo.h.*self-edge"
-
- bazel build --nobuild //main:mygenrule >$TEST_log 2>&1 || true
- expect_log "in genrule rule //cycle:foo.h: .*dependency graph"
- expect_log "//cycle:foo.h.*self-edge"
-
- bazel build --nobuild //cycle:foo.h >$TEST_log 2>&1 || true
- expect_log "in genrule rule //cycle:foo.h: .*dependency graph"
- expect_log "//cycle:foo.h.*self-edge"
-}
-
-# glob function should not return values that are outside the package
-function test_glob_with_subpackage() {
- mkdir -p p/subpkg || fail "mkdir p/subpkg failed"
- mkdir -p p/dir || fail "mkdir p/dir failed"
-
- echo "exports_files(glob(['**/*.txt']))" >p/BUILD
- echo "# Empty" >p/subpkg/BUILD
-
- echo "p/t1.txt" > p/t1.txt
- echo "p/dir/t2.txt" > p/dir/t2.txt
- echo "p/subpkg/t3.txt" > p/subpkg/t3.txt
-
- bazel query 'p:*' >$TEST_log || fail "Expected success"
- expect_log '//p:t1\.txt'
- expect_log '//p:dir/t2\.txt'
- expect_log '//p:BUILD'
- expect_not_log 't3\.txt'
- assert_equals "3" $(wc -l "$TEST_log")
-
- # glob returns an empty list, because t3.txt is outside the package
- echo "exports_files(glob(['subpkg/t3.txt']))" >p/BUILD
- bazel query 'p:*' -k >$TEST_log || fail "Expected success"
- expect_log '//p:BUILD'
- assert_equals "1" $(wc -l "$TEST_log")
-
- # same test, with a nonexisting file
- echo "exports_files(glob(['subpkg/no_glob.txt']))" >p/BUILD
- bazel query 'p:*' -k >$TEST_log || fail "Expected success"
- expect_log '//p:BUILD'
- assert_equals "1" $(wc -l "$TEST_log")
-
- # Non-recursive wildcard gives the same result as the recursive wildcard
- echo "exports_files(glob(['*.txt', '*/*.txt']))" >p/BUILD
- bazel query 'p:*' >$TEST_log || fail "Expected success"
- expect_log '//p:t1\.txt'
- expect_log '//p:dir/t2\.txt'
- expect_log '//p:BUILD'
- expect_not_log 't3\.txt'
- assert_equals "3" $(wc -l "$TEST_log")
-}
-
-function test_glob_with_subpackage2() {
- mkdir -p p/q/subpkg || fail "mkdir p/q/subpkg failed"
- mkdir -p p/q/dir || fail "mkdir p/q/dir failed"
-
- echo "exports_files(glob(['**/*.txt']))" >p/q/BUILD
- echo "# Empty" >p/q/subpkg/BUILD
-
- echo "p/q/t1.txt" > p/q/t1.txt
- echo "p/q/dir/t2.txt" > p/q/dir/t2.txt
- echo "p/q/subpkg/t3.txt" > p/q/subpkg/t3.txt
-
- bazel query 'p/q:*' >$TEST_log || fail "Expected success"
- expect_log '//p/q:t1\.txt'
- expect_log '//p/q:dir/t2\.txt'
- expect_log '//p/q:BUILD'
- expect_not_log 't3\.txt'
- assert_equals "3" $(wc -l "$TEST_log")
-}
-
-function test_glob_with_io_error() {
- mkdir -p t/u
- touch t/u/v
-
- echo "filegroup(name='t', srcs=glob(['u/*']))" > t/BUILD
- chmod 000 t/u
-
- bazel query '//t:*' >& $TEST_log && fail "Expected failure"
- expect_log 'error globbing.*Permission denied'
-
- chmod 755 t/u
- bazel query '//t:*' >& $TEST_log || fail "Expected success"
- expect_not_log 'error globbing.*Permission denied'
- expect_log '//t:u'
- expect_log '//t:u/v'
-}
-
-function test_build_file_symlinks() {
- mkdir b || fail "couldn't make b"
- ln -s b a || fail "couldn't link a to b"
-
- bazel query a:all >& $TEST_log && fail "Expected failure"
- expect_log "no such package 'a'"
-
- touch b/BUILD
- bazel query a:all >& $TEST_log || fail "Expected success"
- expect_log "Empty results"
-
- unlink a || fail "couldn't unlink a"
- ln -s c a
- bazel query a:all >& $TEST_log && fail "Expected failure"
- expect_log "no such package 'a'"
-
- mkdir c || fail "couldn't make c"
- ln -s foo c/BUILD || "couldn't link c/BUILD to c/foo"
- bazel query a:all >& $TEST_log && fail "Expected failure"
- expect_log "no such package 'a'"
-
- touch c/foo
- bazel query a:all >& $TEST_log || fail "Expected success"
- expect_log "Empty results"
-}
-
-# Regression test for bug "ASTFileLookupFunction has an unnoted
-# dependency on the PathPackageLocator".
-function test_incremental_deleting_package_roots() {
- local other_root=$TEST_TMPDIR/other_root/${WORKSPACE_NAME}
- mkdir -p $other_root/a
- touch $other_root/WORKSPACE
- echo 'sh_library(name="external")' > $other_root/a/BUILD
- mkdir -p a
- echo 'sh_library(name="internal")' > a/BUILD
-
- bazel query --package_path=$other_root:. a:all >& $TEST_log \
- || fail "Expected success"
- expect_log "//a:external"
- expect_not_log "//a:internal"
- rm -r $other_root
- bazel query --package_path=$other_root:. a:all >& $TEST_log \
- || fail "Expected success"
- expect_log "//a:internal"
- expect_not_log "//a:external"
- mkdir -p $other_root
- bazel query --package_path=$other_root:. a:all >& $TEST_log \
- || fail "Expected success"
- expect_log "//a:internal"
- expect_not_log "//a:external"
-}
-
-function test_no_package_loading_on_benign_workspace_file_changes() {
- mkdir foo
-
- echo 'workspace(name="wsname1")' > WORKSPACE
- echo 'sh_library(name="shname1")' > foo/BUILD
- # TODO(b/37617303): make tests UI-independent
- bazel query --noexperimental_ui //foo:all >& "$TEST_log" \
- || fail "Expected success"
- expect_log "Loading package: foo"
- expect_log "//foo:shname1"
-
- echo 'sh_library(name="shname2")' > foo/BUILD
- # TODO(b/37617303): make tests UI-independent
- bazel query --noexperimental_ui //foo:all >& "$TEST_log" \
- || fail "Expected success"
- expect_log "Loading package: foo"
- expect_log "//foo:shname2"
-
- # Test that comment changes do not cause package reloading
- echo '#benign comment' >> WORKSPACE
- # TODO(b/37617303): make tests UI-independent
- bazel query --noexperimental_ui //foo:all >& "$TEST_log" \
- || fail "Expected success"
- expect_not_log "Loading package: foo"
- expect_log "//foo:shname2"
-
- echo 'workspace(name="wsname2")' > WORKSPACE
- # TODO(b/37617303): make tests UI-independent
- bazel query --noexperimental_ui //foo:all >& "$TEST_log" \
- || fail "Expected success"
- expect_log "Loading package: foo"
- expect_log "//foo:shname2"
-}
-
-run_suite "Integration tests of ${PRODUCT_NAME} using loading/analysis phases."