aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/test/shell/bazel/BUILD6
-rwxr-xr-xsrc/test/shell/bazel/help_test.sh26
-rwxr-xr-xsrc/test/shell/integration_test_setup.sh31
-rwxr-xr-xsrc/test/shell/testenv.sh8
4 files changed, 56 insertions, 15 deletions
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index 72abc3de2a..450b3c6902 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -537,7 +537,10 @@ sh_test(
name = "help_test",
size = "small",
srcs = ["help_test.sh"],
- data = [":test-deps"],
+ data = [
+ ":test-deps",
+ "@bazel_tools//tools/bash/runfiles",
+ ],
)
sh_test(
@@ -584,6 +587,7 @@ test_suite(
tests = [
":bazel_bootstrap_distfile_test",
":bazel_windows_example_test",
+ ":help_test",
],
visibility = ["//src/test/shell:__pkg__"],
)
diff --git a/src/test/shell/bazel/help_test.sh b/src/test/shell/bazel/help_test.sh
index 3e2570337f..3f81132253 100755
--- a/src/test/shell/bazel/help_test.sh
+++ b/src/test/shell/bazel/help_test.sh
@@ -16,9 +16,29 @@
#
# Test the help command.
-# Load the test setup defined in the parent directory
-CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-source "${CURRENT_DIR}/../integration_test_setup.sh" \
+set -euo pipefail
+# --- begin runfiles.bash initialization ---
+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; }
function test_info_keys() {
diff --git a/src/test/shell/integration_test_setup.sh b/src/test/shell/integration_test_setup.sh
index ba051d4b62..1b68adce21 100755
--- a/src/test/shell/integration_test_setup.sh
+++ b/src/test/shell/integration_test_setup.sh
@@ -19,13 +19,26 @@ function print_message_and_exit() {
echo $1 >&2; exit 1;
}
-CURRENT_SCRIPT=${BASH_SOURCE[0]}
-# Go to the directory where the script is running
-cd "$(dirname ${CURRENT_SCRIPT})" \
- || print_message_and_exit "Unable to access $(dirname ${CURRENT_SCRIPT})"
+if type rlocation >&/dev/null; then
+ # If rlocation is defined, use it to look up data-dependencies.
+ # Load the unit test framework
+ source "$(rlocation io_bazel/src/test/shell/unittest.bash)" \
+ || print_message_and_exit "unittest.bash not found!"
+ # Load the test environment
+ source "$(rlocation io_bazel/src/test/shell/testenv.sh)" \
+ || print_message_and_exit "testenv.sh not found!"
+else
+ # If rlocation is undefined, we are probably running under Blaze.
+ # Assume the existence of a runfiles tree.
-DIR=$(pwd)
-# Load the unit test framework
-source "$DIR/unittest.bash" || print_message_and_exit "unittest.bash not found!"
-# Load the test environment
-source "$DIR/testenv.sh" || print_message_and_exit "testenv.sh not found!"
+ CURRENT_SCRIPT=${BASH_SOURCE[0]}
+ # Go to the directory where the script is running
+ cd "$(dirname ${CURRENT_SCRIPT})" \
+ || print_message_and_exit "Unable to access $(dirname ${CURRENT_SCRIPT})"
+
+ DIR=$(pwd)
+ # Load the unit test framework
+ source "$DIR/unittest.bash" || print_message_and_exit "unittest.bash not found!"
+ # Load the test environment
+ source "$DIR/testenv.sh" || print_message_and_exit "testenv.sh not found!"
+fi
diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh
index 805304a333..cbafb2b33c 100755
--- a/src/test/shell/testenv.sh
+++ b/src/test/shell/testenv.sh
@@ -83,7 +83,6 @@ workspace_file="${BAZEL_RUNFILES}/WORKSPACE"
distdir_bzl_file="${BAZEL_RUNFILES}/distdir.bzl"
# Bazel
-bazel_tree="$(rlocation io_bazel/src/test/shell/bazel/doc-srcs.zip)"
bazel_data="${BAZEL_RUNFILES}"
# Java
@@ -400,6 +399,10 @@ function setup_clean_workspace() {
bazel info bazel-bin >"$bazel_stdout" 2>"$bazel_stderr" \
&& export BAZEL_BIN_DIR=$(cat "$bazel_stdout") \
|| log_fatal "'bazel info bazel-bin' failed, stderr: $(cat "$bazel_stderr")"
+ # Shut down this server in case the tests will run Bazel in a different output
+ # root, otherwise we could not clean up $WORKSPACE_DIR (under $TEST_TMPDIR)
+ # once the test is finished.
+ bazel shutdown
rm -f "$bazel_stdout" "$bazel_stderr"
if is_windows; then
@@ -414,6 +417,8 @@ function cleanup_workspace() {
log_info "Cleaning up workspace" >> $TEST_log
cd ${WORKSPACE_DIR}
bazel clean >> $TEST_log 2>&1 # Clean up the output base
+ # Shut down this server to allow any cleanup code to delete its output_root.
+ bazel shutdown
for i in *; do
if ! is_tools_directory "$i"; then
@@ -501,7 +506,6 @@ function assert_bazel_run() {
}
setup_bazelrc
-setup_clean_workspace
################### shell/integration/testenv ############################
# Setting up the environment for our legacy integration tests.