aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Luis Fernando Pino Duque <lpino@google.com>2016-10-18 14:28:42 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-10-19 08:26:02 +0000
commitfa389066641ac7f92b220ef232f23e757704318d (patch)
treecfedd733426e8b7b95b87105bd6344a6c0154983
parentaecf826aa0cd12d25a8f6d69604d721f50d940f0 (diff)
Create a proper wrapper script for executing "bazel" in the integration tests.
Currently a call to "bazel" in an integration test means calling a (quite hidden) function in test-setup.sh which actually calls "$bazel" defined in "shell/bazel/testenv.sh" which is equal to "$(rlocation io_bazel/src/bazel)". This is extremely confusing and error prone. The new mechanism is to add a wrapper script to shell/bin called bazel and export this directory to the PATH. Moreover, not every test loads the same test environment, for instance consider how bazel_query_test loads the test environment: - Load shell/integration/testenv.sh which loads, - shell/bazel/test-setup.sh which loads, - shell/bazel/testenv.sh which loads, - shell/unittest.bash which loads, - shell/testenv.sh Again this is error prone and specially hard to understand, in fact each test writer needs to decide which of these testenv to load. This change fixes all of this by having only one testenv.sh and summarizing the test setup in integration_test_setup.sh. Namely, for any new integration test, the developer needs to load integration_test_setup to get the environment set up including the unittest framework (also it helps to attract contributions). This change also allows to open sourcing client_sigint_test: Since bazel was a function client_sigint_test was using a wrong process id to interrupt the build. The problem is that $! returns bash's id instead of the id of the process running in the background when using a function instead of an executable. A few tests needed to be adapted to the new infrastructure. -- MOS_MIGRATED_REVID=136470360
-rw-r--r--src/test/shell/BUILD6
-rw-r--r--src/test/shell/bazel/BUILD12
-rwxr-xr-xsrc/test/shell/bazel/apple/bazel_apple_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/apple/bazel_objc_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_example_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_execute_testlog.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_java_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_localtest_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_rules_test.sh11
-rwxr-xr-xsrc/test/shell/bazel/bazel_sandboxing_cpp_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/bazel_sandboxing_test.sh11
-rwxr-xr-xsrc/test/shell/bazel/bazel_test_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_toolchain_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_tools_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_windows_example_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_worker_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bazel_workspace_status_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/bound_targets_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/cc_inc_library_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/client_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/empty_package.sh7
-rwxr-xr-xsrc/test/shell/bazel/execroot_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/external_correctness_test.sh6
-rwxr-xr-xsrc/test/shell/bazel/external_integration_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/external_skylark_load_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/generate_workspace_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/git_repository_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/help_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/linux-sandbox_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/local_repository_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/local_repository_test_jdk8.sh7
-rwxr-xr-xsrc/test/shell/bazel/location_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/maven_skylark_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/maven_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/process-wrapper_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/remote_execution_test.sh8
-rwxr-xr-xsrc/test/shell/bazel/runfiles_test.sh7
-rwxr-xr-xsrc/test/shell/bazel/skylark_repository_test.sh10
-rwxr-xr-xsrc/test/shell/bazel/test-setup.sh267
-rwxr-xr-xsrc/test/shell/bazel/testenv.sh234
-rwxr-xr-xsrc/test/shell/bazel/workspace_test.sh7
-rwxr-xr-xsrc/test/shell/bin/bazel20
-rw-r--r--src/test/shell/integration/BUILD11
-rwxr-xr-xsrc/test/shell/integration/action_env_test.sh53
-rwxr-xr-xsrc/test/shell/integration/bazel_command_log_test.sh13
-rwxr-xr-xsrc/test/shell/integration/bazel_javabase_test.sh12
-rwxr-xr-xsrc/test/shell/integration/bazel_query_test.sh13
-rwxr-xr-xsrc/test/shell/integration/bazel_testjobs_test.sh14
-rwxr-xr-xsrc/test/shell/integration/client_sigint_test.sh87
-rwxr-xr-xsrc/test/shell/integration/discard_analysis_cache_test.sh12
-rwxr-xr-xsrc/test/shell/integration/discard_graph_edges_test.sh11
-rwxr-xr-xsrc/test/shell/integration/experimental_ui_test.sh46
-rwxr-xr-xsrc/test/shell/integration/ide_info_generation.sh61
-rwxr-xr-xsrc/test/shell/integration/java_integration_test.sh47
-rwxr-xr-xsrc/test/shell/integration/loading_phase_tests.sh28
-rwxr-xr-xsrc/test/shell/integration/output_filter_test.sh11
-rwxr-xr-xsrc/test/shell/integration/progress_reporting_test.sh19
-rwxr-xr-xsrc/test/shell/integration/rc_options_test.sh11
-rwxr-xr-xsrc/test/shell/integration/run_test.sh43
-rwxr-xr-xsrc/test/shell/integration/runfiles_test.sh11
-rwxr-xr-xsrc/test/shell/integration/startup_options_test.sh15
-rwxr-xr-xsrc/test/shell/integration/stub_finds_runfiles_test.sh31
-rwxr-xr-xsrc/test/shell/integration/testenv.sh47
-rwxr-xr-xsrc/test/shell/integration/ui_test.sh11
-rwxr-xr-xsrc/test/shell/integration_test_setup.sh31
-rwxr-xr-xsrc/test/shell/testenv.sh573
-rw-r--r--src/test/shell/unittest.bash143
67 files changed, 1139 insertions, 1045 deletions
diff --git a/src/test/shell/BUILD b/src/test/shell/BUILD
index 9db5e5bb6e..ed233cb28c 100644
--- a/src/test/shell/BUILD
+++ b/src/test/shell/BUILD
@@ -1,5 +1,11 @@
package(default_visibility = ["//visibility:private"])
+exports_files([
+ "bin/bazel",
+ "testenv.sh",
+ "integration_test_setup.sh",
+])
+
filegroup(
name = "srcs",
srcs = glob(["**"]) + [
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index d815e5e97a..3d70474b93 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -24,8 +24,6 @@ filegroup(
srcs = [
"bazel_sandboxing_test_utils.sh",
"remote_helpers.sh",
- "test-setup.sh",
- "testenv.sh",
"testing_server.py",
":langtools-copy",
"//examples:srcs",
@@ -40,6 +38,9 @@ filegroup(
"//src/main/tools:linux-sandbox",
"//src/main/tools:process-wrapper",
"//src/test/shell:bashunit",
+ "//src/test/shell:bin/bazel",
+ "//src/test/shell:integration_test_setup.sh",
+ "//src/test/shell:testenv.sh",
"//third_party:srcs",
"//third_party/ijar",
"//third_party/java/jdk/langtools:test-srcs",
@@ -271,12 +272,7 @@ sh_test(
name = "process_wrapper_test",
size = "small",
srcs = ["process-wrapper_test.sh"],
- data = [
- "test-setup.sh",
- "testenv.sh",
- "//src/main/tools:process-wrapper",
- "//src/test/shell:bashunit",
- ],
+ data = [":test-deps"],
)
sh_test(
diff --git a/src/test/shell/bazel/apple/bazel_apple_test.sh b/src/test/shell/bazel/apple/bazel_apple_test.sh
index abf199bdcb..a2546b3de7 100755
--- a/src/test/shell/bazel/apple/bazel_apple_test.sh
+++ b/src/test/shell/bazel/apple/bazel_apple_test.sh
@@ -17,9 +17,10 @@
# Tests the examples provided in Bazel
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
if [ "${PLATFORM}" != "darwin" ]; then
echo "This test suite requires running on OS X" >&2
diff --git a/src/test/shell/bazel/apple/bazel_objc_test.sh b/src/test/shell/bazel/apple/bazel_objc_test.sh
index 3b5edb895a..325cb0b0c9 100755
--- a/src/test/shell/bazel/apple/bazel_objc_test.sh
+++ b/src/test/shell/bazel/apple/bazel_objc_test.sh
@@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
if [ "${PLATFORM}" != "darwin" ]; then
echo "This test suite requires running on OS X" >&2
diff --git a/src/test/shell/bazel/bazel_example_test.sh b/src/test/shell/bazel/bazel_example_test.sh
index c440a6eeae..b28c860e60 100755
--- a/src/test/shell/bazel/bazel_example_test.sh
+++ b/src/test/shell/bazel/bazel_example_test.sh
@@ -17,9 +17,10 @@
# Tests the examples provided in Bazel
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function set_up() {
copy_examples
diff --git a/src/test/shell/bazel/bazel_execute_testlog.sh b/src/test/shell/bazel/bazel_execute_testlog.sh
index 9c9c2b4b7e..1c3bb952b3 100755
--- a/src/test/shell/bazel/bazel_execute_testlog.sh
+++ b/src/test/shell/bazel/bazel_execute_testlog.sh
@@ -17,9 +17,10 @@
# Test the execution of test logs
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_execute_testlog() {
mkdir dir
diff --git a/src/test/shell/bazel/bazel_java_test.sh b/src/test/shell/bazel/bazel_java_test.sh
index 8bc7bef8fd..d2d1346a16 100755
--- a/src/test/shell/bazel/bazel_java_test.sh
+++ b/src/test/shell/bazel/bazel_java_test.sh
@@ -17,9 +17,10 @@
# Tests the examples provided in Bazel
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function write_hello_library_files() {
mkdir -p java/main
diff --git a/src/test/shell/bazel/bazel_localtest_test.sh b/src/test/shell/bazel/bazel_localtest_test.sh
index 0034d47eb6..ea592a4ec7 100755
--- a/src/test/shell/bazel/bazel_localtest_test.sh
+++ b/src/test/shell/bazel/bazel_localtest_test.sh
@@ -16,9 +16,10 @@
set -eu
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_run_local() {
mkdir -p dir
diff --git a/src/test/shell/bazel/bazel_rules_test.sh b/src/test/shell/bazel/bazel_rules_test.sh
index b34a26bb77..93bfa4101d 100755
--- a/src/test/shell/bazel/bazel_rules_test.sh
+++ b/src/test/shell/bazel/bazel_rules_test.sh
@@ -17,9 +17,10 @@
# Test rules provided in Bazel not tested by examples
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_sh_test() {
mkdir -p a
@@ -234,11 +235,11 @@ EOF
local new_tmpdir="$(mktemp -d "${TEST_TMPDIR}/newfancytmpdirXXXXXX")"
[ -d "${new_tmpdir}" ] || \
fail "Could not create new temporary directory ${new_tmpdir}"
- export PATH="/bin:/usr/bin:/random/path"
+ export PATH="$PATH_TO_BAZEL_WRAPPER:/bin:/usr/bin:/random/path"
export TMPDIR="${new_tmpdir}"
# batch mode to force reload of the environment
bazel --batch build //pkg:test || fail "Failed to build //pkg:test"
- assert_contains "PATH=/bin:/usr/bin:/random/path" \
+ assert_contains "PATH=$PATH_TO_BAZEL_WRAPPER:/bin:/usr/bin:/random/path" \
bazel-genfiles/pkg/test.out
assert_contains "TMPDIR=.*newfancytmpdir" \
bazel-genfiles/pkg/test.out
diff --git a/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh b/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh
index 2c2710bf13..272351da18 100755
--- a/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh
+++ b/src/test/shell/bazel/bazel_sandboxing_cpp_test.sh
@@ -17,11 +17,11 @@
# Test C++ builds with the sandboxing spawn strategy.
#
-# Load test environment
-src_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
-source ${src_dir}/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source ${src_dir}/bazel_sandboxing_test_utils.sh \
+# 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; }
+source ${CURRENT_DIR}/bazel_sandboxing_test_utils.sh \
|| { echo "bazel_sandboxing_test_utils.sh not found!" >&2; exit 1; }
function set_up {
diff --git a/src/test/shell/bazel/bazel_sandboxing_test.sh b/src/test/shell/bazel/bazel_sandboxing_test.sh
index 0b796683ed..f827420a8f 100755
--- a/src/test/shell/bazel/bazel_sandboxing_test.sh
+++ b/src/test/shell/bazel/bazel_sandboxing_test.sh
@@ -18,12 +18,13 @@
#
# Load test environment
-src_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
-source ${src_dir}/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source ${src_dir}/bazel_sandboxing_test_utils.sh \
+# 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; }
+source ${CURRENT_DIR}/bazel_sandboxing_test_utils.sh \
|| { echo "bazel_sandboxing_test_utils.sh not found!" >&2; exit 1; }
-source ${src_dir}/remote_helpers.sh \
+source ${CURRENT_DIR}/remote_helpers.sh \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
cat >>$TEST_TMPDIR/bazelrc <<'EOF'
diff --git a/src/test/shell/bazel/bazel_test_test.sh b/src/test/shell/bazel/bazel_test_test.sh
index b82562d6e7..d62fa2c084 100755
--- a/src/test/shell/bazel/bazel_test_test.sh
+++ b/src/test/shell/bazel/bazel_test_test.sh
@@ -16,9 +16,10 @@
set -eu
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function set_up_jobcount() {
tmp=$(mktemp -d ${TEST_TMPDIR}/testjobs.XXXXXXXX)
diff --git a/src/test/shell/bazel/bazel_toolchain_test.sh b/src/test/shell/bazel/bazel_toolchain_test.sh
index 1c6ac1e3e1..67a5ac6dcf 100755
--- a/src/test/shell/bazel/bazel_toolchain_test.sh
+++ b/src/test/shell/bazel/bazel_toolchain_test.sh
@@ -17,9 +17,10 @@
# Tests compiling using an external Linaro toolchain on a Linux machine
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
if [ "${PLATFORM-}" = "darwin" ]; then
echo "Skipping test: linaro toolchain is not supported on darwin host."
diff --git a/src/test/shell/bazel/bazel_tools_test.sh b/src/test/shell/bazel/bazel_tools_test.sh
index 30f4c2b0ec..354a6c9e6a 100755
--- a/src/test/shell/bazel/bazel_tools_test.sh
+++ b/src/test/shell/bazel/bazel_tools_test.sh
@@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_build_objc_tools() {
# TODO(cparsons): Test building tools/objc/...
diff --git a/src/test/shell/bazel/bazel_windows_example_test.sh b/src/test/shell/bazel/bazel_windows_example_test.sh
index 2d62c57007..d5d22d010c 100755
--- a/src/test/shell/bazel/bazel_windows_example_test.sh
+++ b/src/test/shell/bazel/bazel_windows_example_test.sh
@@ -22,9 +22,10 @@ if ! type rlocation &> /dev/null; then
exit 0
fi
-# Load test environment
-source $(rlocation io_bazel/src/test/shell/bazel/test-setup.sh) \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
if ! is_windows; then
echo "This test suite requires running on Windows. But now is ${PLATFORM}" >&2
diff --git a/src/test/shell/bazel/bazel_worker_test.sh b/src/test/shell/bazel/bazel_worker_test.sh
index 4256b1bfd9..aeb59eaae5 100755
--- a/src/test/shell/bazel/bazel_worker_test.sh
+++ b/src/test/shell/bazel/bazel_worker_test.sh
@@ -22,9 +22,10 @@ ADDITIONAL_BUILD_FLAGS=$1
WORKER_TYPE_LOG_STRING=$2
shift 2
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
# TODO(philwo): Change this so the path to the custom worker gets passed in as an argument to the
# test, once the bug that makes using the "args" attribute with sh_tests in Bazel impossible is
diff --git a/src/test/shell/bazel/bazel_workspace_status_test.sh b/src/test/shell/bazel/bazel_workspace_status_test.sh
index 23fb5741d5..3823b463c0 100755
--- a/src/test/shell/bazel/bazel_workspace_status_test.sh
+++ b/src/test/shell/bazel/bazel_workspace_status_test.sh
@@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_workspace_status_invalidation() {
create_new_workspace
diff --git a/src/test/shell/bazel/bound_targets_test.sh b/src/test/shell/bazel/bound_targets_test.sh
index a516ede00b..d7da26a029 100755
--- a/src/test/shell/bazel/bound_targets_test.sh
+++ b/src/test/shell/bazel/bound_targets_test.sh
@@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
if [ "${PLATFORM}" != "darwin" ]; then
echo "This test suite requires running on OS X" >&2
diff --git a/src/test/shell/bazel/cc_inc_library_test.sh b/src/test/shell/bazel/cc_inc_library_test.sh
index 379c0c82f1..8ee50fd5a6 100755
--- a/src/test/shell/bazel/cc_inc_library_test.sh
+++ b/src/test/shell/bazel/cc_inc_library_test.sh
@@ -16,9 +16,10 @@
#
# Tests the behavior of cc_inc_library.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function set_up() {
rm -rf package
diff --git a/src/test/shell/bazel/client_test.sh b/src/test/shell/bazel/client_test.sh
index 8e72d39fe1..e3eb6f5265 100755
--- a/src/test/shell/bazel/client_test.sh
+++ b/src/test/shell/bazel/client_test.sh
@@ -16,9 +16,10 @@
# Integration tests for Bazel client.
#
-# Load test environment
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_product_name_with_bazel_info() {
bazel info >& "$TEST_log" || fail "Expected zero exit"
diff --git a/src/test/shell/bazel/empty_package.sh b/src/test/shell/bazel/empty_package.sh
index 4f292afc40..d6476522de 100755
--- a/src/test/shell/bazel/empty_package.sh
+++ b/src/test/shell/bazel/empty_package.sh
@@ -17,9 +17,10 @@
# Test top-level package
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_empty_package() {
cat > BUILD <<EOF
diff --git a/src/test/shell/bazel/execroot_test.sh b/src/test/shell/bazel/execroot_test.sh
index 0a97fa6cb0..4f64e09851 100755
--- a/src/test/shell/bazel/execroot_test.sh
+++ b/src/test/shell/bazel/execroot_test.sh
@@ -16,9 +16,10 @@
set -eu
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_execroot_structure() {
ws_name="dooby_dooby_doo"
diff --git a/src/test/shell/bazel/external_correctness_test.sh b/src/test/shell/bazel/external_correctness_test.sh
index 6d79320fe6..ea8ad05eb2 100755
--- a/src/test/shell/bazel/external_correctness_test.sh
+++ b/src/test/shell/bazel/external_correctness_test.sh
@@ -14,8 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function set_up() {
LOCAL=$(pwd)
diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh
index 477e1653ee..a78871f473 100755
--- a/src/test/shell/bazel/external_integration_test.sh
+++ b/src/test/shell/bazel/external_integration_test.sh
@@ -17,11 +17,11 @@
# Test //external mechanisms
#
-# Load test environment
-src=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
-source $src/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source $src/remote_helpers.sh \
+# 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; }
+source "${CURRENT_DIR}/remote_helpers.sh" \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
function set_up() {
diff --git a/src/test/shell/bazel/external_skylark_load_test.sh b/src/test/shell/bazel/external_skylark_load_test.sh
index a198371595..49c603ebdd 100755
--- a/src/test/shell/bazel/external_skylark_load_test.sh
+++ b/src/test/shell/bazel/external_skylark_load_test.sh
@@ -17,9 +17,10 @@
# Test handling of Skylark loads from and in external repositories.
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
# The following tests build an instance of a Skylark macro loaded from a
# local_repository, which in turns loads another Skylark file either from
diff --git a/src/test/shell/bazel/generate_workspace_test.sh b/src/test/shell/bazel/generate_workspace_test.sh
index 584f3e04d8..f7638fe9b8 100755
--- a/src/test/shell/bazel/generate_workspace_test.sh
+++ b/src/test/shell/bazel/generate_workspace_test.sh
@@ -17,11 +17,11 @@
# Test //external mechanisms
#
-# Load test environment
-src_dir=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)
-source $src_dir/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source $src_dir/remote_helpers.sh \
+# 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; }
+source "${CURRENT_DIR}/remote_helpers.sh" \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
function set_up() {
diff --git a/src/test/shell/bazel/git_repository_test.sh b/src/test/shell/bazel/git_repository_test.sh
index 2c862b7f7e..033a6831a2 100755
--- a/src/test/shell/bazel/git_repository_test.sh
+++ b/src/test/shell/bazel/git_repository_test.sh
@@ -17,9 +17,10 @@
# Test git_repository and new_git_repository workspace rules.
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
# Global test setup.
#
diff --git a/src/test/shell/bazel/help_test.sh b/src/test/shell/bazel/help_test.sh
index c6a4a7b6ac..3e2570337f 100755
--- a/src/test/shell/bazel/help_test.sh
+++ b/src/test/shell/bazel/help_test.sh
@@ -16,9 +16,10 @@
#
# Test the help command.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_info_keys() {
bazel help info-keys >& $TEST_log || fail "help failed"
diff --git a/src/test/shell/bazel/linux-sandbox_test.sh b/src/test/shell/bazel/linux-sandbox_test.sh
index 9009d72bb5..549f84fe88 100755
--- a/src/test/shell/bazel/linux-sandbox_test.sh
+++ b/src/test/shell/bazel/linux-sandbox_test.sh
@@ -17,11 +17,11 @@
# Test sandboxing spawn strategy
#
-# Load test environment
-src_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
-source ${src_dir}/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source ${src_dir}/bazel_sandboxing_test_utils.sh \
+# 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; }
+source "${CURRENT_DIR}/bazel_sandboxing_test_utils.sh" \
|| { echo "bazel_sandboxing_test_utils.sh not found!" >&2; exit 1; }
readonly OUT_DIR="${TEST_TMPDIR}/out"
diff --git a/src/test/shell/bazel/local_repository_test.sh b/src/test/shell/bazel/local_repository_test.sh
index b14ba4fd4d..8a495c76e8 100755
--- a/src/test/shell/bazel/local_repository_test.sh
+++ b/src/test/shell/bazel/local_repository_test.sh
@@ -17,9 +17,10 @@
# Test the local_repository binding
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_glob_local_repository_dangling_symlink() {
create_new_workspace
diff --git a/src/test/shell/bazel/local_repository_test_jdk8.sh b/src/test/shell/bazel/local_repository_test_jdk8.sh
index a8f37176c9..469d402171 100755
--- a/src/test/shell/bazel/local_repository_test_jdk8.sh
+++ b/src/test/shell/bazel/local_repository_test_jdk8.sh
@@ -17,9 +17,10 @@
# Test parts of the local_repository binding which are broken with jdk7
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
# Creates an indirect dependency on X from A and make sure the error message
# refers to the correct label, both in an external repository and not.
diff --git a/src/test/shell/bazel/location_test.sh b/src/test/shell/bazel/location_test.sh
index 495d09185a..2435dcc4a1 100755
--- a/src/test/shell/bazel/location_test.sh
+++ b/src/test/shell/bazel/location_test.sh
@@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function test_external_location() {
cat > WORKSPACE <<EOF
diff --git a/src/test/shell/bazel/maven_skylark_test.sh b/src/test/shell/bazel/maven_skylark_test.sh
index 7970c4afca..c1a56d2ece 100755
--- a/src/test/shell/bazel/maven_skylark_test.sh
+++ b/src/test/shell/bazel/maven_skylark_test.sh
@@ -16,11 +16,11 @@
#
# Test the Skylark implementation of the maven_jar() rule.
-# Load test environment
-src=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)
-source $src/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source $src/remote_helpers.sh \
+# 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; }
+source ${CURRENT_DIR}/remote_helpers.sh \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
function setup_zoo() {
diff --git a/src/test/shell/bazel/maven_test.sh b/src/test/shell/bazel/maven_test.sh
index 9768bdab0e..3e50d6d204 100755
--- a/src/test/shell/bazel/maven_test.sh
+++ b/src/test/shell/bazel/maven_test.sh
@@ -17,11 +17,11 @@
# Test //external mechanisms
#
-# Load test environment
-src=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)
-source $src/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source $src/remote_helpers.sh \
+# 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; }
+source "${CURRENT_DIR}/remote_helpers.sh" \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
function setup_zoo() {
diff --git a/src/test/shell/bazel/process-wrapper_test.sh b/src/test/shell/bazel/process-wrapper_test.sh
index a46b4500aa..b720ab8dbd 100755
--- a/src/test/shell/bazel/process-wrapper_test.sh
+++ b/src/test/shell/bazel/process-wrapper_test.sh
@@ -17,10 +17,10 @@
# Test sandboxing spawn strategy
#
-# Load test environment
-
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
+# 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; }
readonly OUT_DIR="${TEST_TMPDIR}/out"
readonly OUT="${OUT_DIR}/outfile"
@@ -82,7 +82,7 @@ function test_basic_timeout() {
function test_timeout_grace() {
local code=0
$process_wrapper 1 10 $OUT $ERR /bin/bash -c \
- 'trap "echo -n before; sleep 1; echo after; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' \
+ 'trap "echo -n "before"; sleep 1; echo "after"; exit 0" SIGINT SIGTERM SIGALRM; sleep 10' \
&> $TEST_log || code=$?
assert_equals 142 "$code" # SIGNAL_BASE + SIGALRM = 128 + 14
assert_stdout "beforeafter"
diff --git a/src/test/shell/bazel/remote_execution_test.sh b/src/test/shell/bazel/remote_execution_test.sh
index c6ec0844f4..75bef52e9a 100755
--- a/src/test/shell/bazel/remote_execution_test.sh
+++ b/src/test/shell/bazel/remote_execution_test.sh
@@ -17,10 +17,10 @@
# Tests remote execution and caching.
#
-# Load test environment
-src_dir=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)
-source $src_dir/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
function set_up() {
mkdir -p a
diff --git a/src/test/shell/bazel/runfiles_test.sh b/src/test/shell/bazel/runfiles_test.sh
index ded1184fcb..e0ac79b8d9 100755
--- a/src/test/shell/bazel/runfiles_test.sh
+++ b/src/test/shell/bazel/runfiles_test.sh
@@ -17,9 +17,10 @@
# Test runfiles creation
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
# Make sure runfiles are created under a custom-named subdirectory when
# workspace() is specified in the WORKSPACE file.
diff --git a/src/test/shell/bazel/skylark_repository_test.sh b/src/test/shell/bazel/skylark_repository_test.sh
index 0e8ef1652d..5fc420b999 100755
--- a/src/test/shell/bazel/skylark_repository_test.sh
+++ b/src/test/shell/bazel/skylark_repository_test.sh
@@ -17,11 +17,11 @@
# Test the local_repository binding
#
-# Load test environment
-src_dir=$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-source "$src_dir/remote_helpers.sh" \
+# 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; }
+source "${CURRENT_DIR}/remote_helpers.sh" \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
# Basic test.
diff --git a/src/test/shell/bazel/test-setup.sh b/src/test/shell/bazel/test-setup.sh
deleted file mode 100755
index 7577d15585..0000000000
--- a/src/test/shell/bazel/test-setup.sh
+++ /dev/null
@@ -1,267 +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.
-#
-# Setup bazel for integration tests
-#
-
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-# OS X has a limit in the pipe length, so force the root to a shorter one
-bazel_root="${TEST_TMPDIR}/root"
-mkdir -p "${bazel_root}"
-
-bazel_javabase="${jdk_dir}"
-
-echo "bazel binary is at $bazel"
-
-# Here we unset variable that were set by the invoking Blaze instance
-unset JAVA_RUNFILES
-
-function setup_bazelrc() {
- cat >$TEST_TMPDIR/bazelrc <<EOF
-startup --output_user_root=${bazel_root}
-startup --host_javabase=${bazel_javabase}
-build -j 8
-${EXTRA_BAZELRC:-}
-EOF
-}
-
-function bazel() {
- ${bazel} --bazelrc=$TEST_TMPDIR/bazelrc "$@"
-}
-
-function setup_android_support() {
- ANDROID_NDK=$PWD/android_ndk
- ANDROID_SDK=$PWD/android_sdk
-
- # TODO(bazel-team): This hard-codes the name of the Android repository in
- # the WORKSPACE file of Bazel. Change this once external repositories have
- # their own defined names under which they are mounted.
- NDK_SRCDIR=$TEST_SRCDIR/androidndk/ndk
- SDK_SRCDIR=$TEST_SRCDIR/androidsdk
-
- mkdir -p $ANDROID_NDK
- mkdir -p $ANDROID_SDK
-
- for i in $NDK_SRCDIR/*; do
- if [[ "$(basename $i)" != "BUILD" ]]; then
- ln -s "$i" "$ANDROID_NDK/$(basename $i)"
- fi
- done
-
- for i in $SDK_SRCDIR/*; do
- ln -s "$i" "$ANDROID_SDK/$(basename $i)"
- done
-
-
- local ANDROID_SDK_API_LEVEL=$(ls $SDK_SRCDIR/platforms | cut -d '-' -f 2 | sort -n | tail -1)
- local ANDROID_NDK_API_LEVEL=$(ls $NDK_SRCDIR/platforms | cut -d '-' -f 2 | sort -n | tail -1)
- local ANDROID_SDK_TOOLS_VERSION=$(ls $SDK_SRCDIR/build-tools | sort -n | tail -1)
- cat >> WORKSPACE <<EOF
-android_ndk_repository(
- name = "androidndk",
- path = "$ANDROID_NDK",
- api_level = $ANDROID_NDK_API_LEVEL,
-)
-
-android_sdk_repository(
- name = "androidsdk",
- path = "$ANDROID_SDK",
- build_tools_version = "$ANDROID_SDK_TOOLS_VERSION",
- api_level = $ANDROID_SDK_API_LEVEL,
-)
-EOF
-}
-
-function setup_javatest_common() {
- # TODO(bazel-team): we should use remote repositories.
- mkdir -p third_party
- if [ ! -f third_party/BUILD ]; then
- cat <<EOF >third_party/BUILD
-package(default_visibility = ["//visibility:public"])
-EOF
- fi
-
- [ -e third_party/junit.jar ] || ln -s ${junit_jar} third_party/junit.jar
- [ -e third_party/hamcrest.jar ] \
- || ln -s ${hamcrest_jar} third_party/hamcrest.jar
-}
-
-function setup_javatest_support() {
- setup_javatest_common
- grep -q 'name = "junit4"' third_party/BUILD \
- || cat <<EOF >>third_party/BUILD
-java_import(
- name = "junit4",
- jars = [
- "junit.jar",
- "hamcrest.jar",
- ],
-)
-EOF
-}
-
-function setup_skylark_javatest_support() {
- setup_javatest_common
- grep -q "name = \"junit4-jars\"" third_party/BUILD \
- || cat <<EOF >>third_party/BUILD
-filegroup(
- name = "junit4-jars",
- srcs = [
- "junit.jar",
- "hamcrest.jar",
- ],
-)
-EOF
-}
-
-function setup_iossim() {
- mkdir -p third_party/iossim
- ln -sv ${iossim_path} third_party/iossim/iossim
-
- cat <<EOF >>third_party/iossim/BUILD
-licenses(["unencumbered"])
-package(default_visibility = ["//visibility:public"])
-
-exports_files(["iossim"])
-EOF
-}
-
-# Sets up Objective-C tools. Mac only.
-function setup_objc_test_support() {
- IOS_SDK_VERSION=$(xcrun --sdk iphoneos --show-sdk-version)
-}
-
-workspaces=()
-# Set-up a new, clean workspace with only the tools installed.
-function create_new_workspace() {
- new_workspace_dir=${1:-$(mktemp -d ${TEST_TMPDIR}/workspace.XXXXXXXX)}
- rm -fr ${new_workspace_dir}
- mkdir -p ${new_workspace_dir}
- workspaces+=(${new_workspace_dir})
- cd ${new_workspace_dir}
- mkdir tools
- mkdir -p third_party/java/jdk/langtools
-
- copy_tools_directory
-
- [ -e third_party/java/jdk/langtools/javac.jar ] \
- || ln -s "${langtools_path}" third_party/java/jdk/langtools/javac.jar
-
- touch WORKSPACE
-}
-
-# Set-up a clean default workspace.
-function setup_clean_workspace() {
- export WORKSPACE_DIR=${TEST_TMPDIR}/workspace
- echo "setting up client in ${WORKSPACE_DIR}" > $TEST_log
- rm -fr ${WORKSPACE_DIR}
- create_new_workspace ${WORKSPACE_DIR}
- [ "${new_workspace_dir}" = "${WORKSPACE_DIR}" ] || \
- { echo "Failed to create workspace" >&2; exit 1; }
- export BAZEL_INSTALL_BASE=$(bazel info install_base)
- export BAZEL_GENFILES_DIR=$(bazel info bazel-genfiles)
- export BAZEL_BIN_DIR=$(bazel info bazel-bin)
- if is_windows; then
- export BAZEL_SH="$(cygpath --windows /bin/bash)"
- fi
-}
-
-# Clean up all files that are not in tools directories, to restart
-# from a clean workspace
-function cleanup_workspace() {
- if [ -d "${WORKSPACE_DIR:-}" ]; then
- echo "Cleaning up workspace" > $TEST_log
- cd ${WORKSPACE_DIR}
- bazel clean >& $TEST_log # Clean up the output base
-
- for i in $(ls); do
- if ! is_tools_directory "$i"; then
- rm -fr "$i"
- fi
- done
- touch WORKSPACE
- fi
- for i in ${workspaces}; do
- if [ "$i" != "${WORKSPACE_DIR:-}" ]; then
- rm -fr $i
- fi
- done
- workspaces=()
-}
-
-# Clean-up the bazel install base
-function cleanup() {
- if [ -d "${BAZEL_INSTALL_BASE:-__does_not_exists__}" ]; then
- rm -fr "${BAZEL_INSTALL_BASE}"
- fi
-}
-
-function tear_down() {
- cleanup_workspace
-}
-
-#
-# Simples assert to make the tests more readable
-#
-function assert_build() {
- bazel build -s --verbose_failures $* || fail "Failed to build $*"
-}
-
-function assert_build_output() {
- local OUTPUT=$1
- shift
- assert_build "$*"
- test -f "$OUTPUT" || fail "Output $OUTPUT not found for target $*"
-}
-
-function assert_build_fails() {
- bazel build -s $1 >& $TEST_log \
- && fail "Test $1 succeed while expecting failure" \
- || true
- if [ -n "${2:-}" ]; then
- expect_log "$2"
- fi
-}
-
-function assert_test_ok() {
- bazel test --test_output=errors $* >& $TEST_log \
- || fail "Test $1 failed while expecting success"
-}
-
-function assert_test_fails() {
- bazel test --test_output=errors $* >& $TEST_log \
- && fail "Test $* succeed while expecting failure" \
- || true
- expect_log "$1.*FAILED"
-}
-
-function assert_binary_run() {
- $1 >& $TEST_log || fail "Failed to run $1"
- [ -z "${2:-}" ] || expect_log "$2"
-}
-
-function assert_bazel_run() {
- bazel run $1 >& $TEST_log || fail "Failed to run $1"
- [ -z "${2:-}" ] || expect_log "$2"
-
- assert_binary_run "./bazel-bin/$(echo "$1" | sed 's|^//||' | sed 's|:|/|')" "${2:-}"
-}
-
-setup_bazelrc
-setup_clean_workspace
diff --git a/src/test/shell/bazel/testenv.sh b/src/test/shell/bazel/testenv.sh
deleted file mode 100755
index 2f5a247086..0000000000
--- a/src/test/shell/bazel/testenv.sh
+++ /dev/null
@@ -1,234 +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.
-#
-# Setting up the environment for Bazel integration tests.
-#
-[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; }
-BAZEL_RUNFILES="$TEST_SRCDIR/io_bazel"
-
-if ! type rlocation &> /dev/null; then
- function rlocation() {
- if [[ "$1" = /* ]]; then
- echo $1
- else
- echo "$TEST_SRCDIR/$1"
- fi
- }
- export -f rlocation
-fi
-
-# Load the unit-testing framework
-source "$(rlocation io_bazel/src/test/shell/unittest.bash)" || \
- { echo "Failed to source unittest.bash" >&2; exit 1; }
-
-# WORKSPACE file
-workspace_file="${BAZEL_RUNFILES}/WORKSPACE"
-
-# Bazel
-bazel_tree="$(rlocation io_bazel/src/test/shell/bazel/doc-srcs.zip)"
-bazel="$(rlocation io_bazel/src/bazel)"
-bazel_data="${BAZEL_RUNFILES}"
-
-# Windows
-PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
-function is_windows() {
- # On windows, the shell test actually running on msys
- if [[ "${PLATFORM}" =~ msys_nt* ]]; then
- true
- else
- false
- fi
-}
-
-# Java
-if is_windows; then
- jdk_dir="$(cygpath -m $(cd $(rlocation local_jdk/bin/java.exe)/../..; pwd))"
-else
- jdk_dir="${TEST_SRCDIR}/local_jdk"
-fi
-langtools="$(rlocation io_bazel/src/test/shell/bazel/langtools.jar)"
-
-# Tools directory location
-tools_dir="$(dirname $(rlocation io_bazel/tools/BUILD))"
-langtools_dir="$(dirname $(rlocation io_bazel/third_party/java/jdk/langtools/BUILD))"
-EXTRA_BAZELRC="build --ios_sdk_version=8.4"
-
-# Java tooling
-javabuilder_path="$(find ${BAZEL_RUNFILES} -name JavaBuilder_*.jar)"
-langtools_path="${BAZEL_RUNFILES}/third_party/java/jdk/langtools/javac.jar"
-singlejar_path="${BAZEL_RUNFILES}/src/java_tools/singlejar/SingleJar_deploy.jar"
-genclass_path="${BAZEL_RUNFILES}/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass_deploy.jar"
-junitrunner_path="${BAZEL_RUNFILES}/src/java_tools/junitrunner/java/com/google/testing/junit/runner/Runner_deploy.jar"
-ijar_path="${BAZEL_RUNFILES}/third_party/ijar/ijar"
-
-# Sandbox tools
-process_wrapper="${BAZEL_RUNFILES}/src/main/tools/process-wrapper"
-linux_sandbox="${BAZEL_RUNFILES}/src/main/tools/linux-sandbox"
-
-# iOS and Objective-C tooling
-iossim_path="${BAZEL_RUNFILES}/third_party/iossim/iossim"
-actoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/actoolwrapper/actoolwrapper.sh"
-ibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh"
-swiftstdlibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh"
-momcwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/momcwrapper/momcwrapper.sh"
-bundlemerge_path="${BAZEL_RUNFILES}/src/objc_tools/bundlemerge/bundlemerge_deploy.jar"
-plmerge_path="${BAZEL_RUNFILES}/src/objc_tools/plmerge/plmerge_deploy.jar"
-xcodegen_path="${BAZEL_RUNFILES}/src/objc_tools/xcodegen/xcodegen_deploy.jar"
-stdredirect_path="${BAZEL_RUNFILES}/src/tools/xcode/stdredirect/StdRedirect.dylib"
-realpath_path="${BAZEL_RUNFILES}/src/tools/xcode/realpath/realpath"
-environment_plist_path="${BAZEL_RUNFILES}/src/tools/xcode/environment/environment_plist.sh"
-xcrunwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh"
-
-# Test data
-testdata_path=${BAZEL_RUNFILES}/src/test/shell/bazel/testdata
-python_server="${BAZEL_RUNFILES}/src/test/shell/bazel/testing_server.py"
-
-# Third-party
-MACHINE_TYPE="$(uname -m)"
-MACHINE_IS_64BIT='no'
-if [ "${MACHINE_TYPE}" = 'amd64' -o "${MACHINE_TYPE}" = 'x86_64' -o "${MACHINE_TYPE}" = 's390x' ]; then
- MACHINE_IS_64BIT='yes'
-fi
-
-MACHINE_IS_Z='no'
-if [ "${MACHINE_TYPE}" = 's390x' ]; then
- MACHINE_IS_Z='yes'
-fi
-
-case "${PLATFORM}" in
- darwin)
- if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then
- protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_64.exe"
- else
- protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_32.exe"
- fi
- ;;
- *)
- if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then
- if [ "${MACHINE_IS_Z}" = 'yes' ]; then
- protoc_compiler="${BAZEL_RUNFILES}//third_party/protobuf/protoc-linux-s390x_64.exe"
- else
- protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_64.exe"
- fi
- else
- protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_32.exe"
- fi
- ;;
-esac
-
-if [ -z ${RUNFILES_MANIFEST_ONLY+x} ]; then
- protoc_jar="${BAZEL_RUNFILES}/third_party/protobuf/protobuf-*.jar"
- junit_jar="${BAZEL_RUNFILES}/third_party/junit/junit-*.jar"
- hamcrest_jar="${BAZEL_RUNFILES}/third_party/hamcrest/hamcrest-*.jar"
-else
- protoc_jar=$(rlocation io_bazel/third_party/protobuf/protobuf-.*.jar)
- junit_jar=$(rlocation io_bazel/third_party/junit/junit-.*.jar)
- hamcrest_jar=$(rlocation io_bazel/third_party/hamcrest/hamcrest-.*.jar)
-fi
-
-# This function copies the tools directory from Bazel.
-function copy_tools_directory() {
- cp -RL ${tools_dir}/* tools
- # tools/jdk/BUILD file for JDK 7 is generated.
- if [ -f tools/jdk/BUILD.* ]; then
- cp tools/jdk/BUILD.* tools/jdk/BUILD
- chmod +w tools/jdk/BUILD
- fi
- # To support custom langtools
- cp ${langtools} tools/jdk/langtools.jar
- cat >>tools/jdk/BUILD <<'EOF'
-filegroup(name = "test-langtools", srcs = ["langtools.jar"])
-EOF
-
- mkdir -p third_party/java/jdk/langtools
- cp -R ${langtools_dir}/* third_party/java/jdk/langtools
-
- chmod -R +w .
- mkdir -p tools/defaults
- touch tools/defaults/BUILD
-
- mkdir -p third_party/py/gflags
- cat > third_party/py/gflags/BUILD <<EOF
-licenses(["notice"])
-package(default_visibility = ["//visibility:public"])
-
-py_library(
- name = "gflags",
-)
-EOF
-}
-
-# Report whether a given directory name corresponds to a tools directory.
-function is_tools_directory() {
- case "$1" in
- third_party|tools|src)
- true
- ;;
- *)
- false
- ;;
- esac
-}
-
-# Copy the examples of the base workspace
-function copy_examples() {
- EXAMPLE="$(cd $(dirname $(rlocation io_bazel/examples/cpp/BUILD))/..; pwd)"
- cp -RL ${EXAMPLE} .
- chmod -R +w .
-}
-
-#
-# Find a random unused TCP port
-#
-pick_random_unused_tcp_port () {
- perl -MSocket -e '
-sub CheckPort {
- my ($port) = @_;
- socket(TCP_SOCK, PF_INET, SOCK_STREAM, getprotobyname("tcp"))
- || die "socket(TCP): $!";
- setsockopt(TCP_SOCK, SOL_SOCKET, SO_REUSEADDR, 1)
- || die "setsockopt(TCP): $!";
- return 0 unless bind(TCP_SOCK, sockaddr_in($port, INADDR_ANY));
- socket(UDP_SOCK, PF_INET, SOCK_DGRAM, getprotobyname("udp"))
- || die "socket(UDP): $!";
- return 0 unless bind(UDP_SOCK, sockaddr_in($port, INADDR_ANY));
- return 1;
-}
-for (1 .. 128) {
- my ($port) = int(rand() * 27000 + 32760);
- if (CheckPort($port)) {
- print "$port\n";
- exit 0;
- }
-}
-print "NO_FREE_PORT_FOUND\n";
-exit 1;
-'
-}
-
-#
-# A uniform SHA-256 commands that works accross platform
-#
-case "${PLATFORM}" in
- darwin)
- function sha256sum() {
- cat "$1" | shasum -a 256 | cut -f 1 -d " "
- }
- ;;
- *)
- # Under linux sha256sum should exists
- ;;
-esac
diff --git a/src/test/shell/bazel/workspace_test.sh b/src/test/shell/bazel/workspace_test.sh
index f6e3a4c11e..ac127ca558 100755
--- a/src/test/shell/bazel/workspace_test.sh
+++ b/src/test/shell/bazel/workspace_test.sh
@@ -14,9 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
+# 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; }
export JAVA_RUNFILES=$BAZEL_RUNFILES
diff --git a/src/test/shell/bin/bazel b/src/test/shell/bin/bazel
new file mode 100755
index 0000000000..27975618ee
--- /dev/null
+++ b/src/test/shell/bin/bazel
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# Copyright 2016 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.
+#
+# Wrapper script to run bazel in the tests. Any change to this file will
+# affect all our integration tests.
+#
+exec $(rlocation io_bazel/src/bazel) --bazelrc=$TEST_TMPDIR/bazelrc "$@" \ No newline at end of file
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index 8549758013..eb131b11c6 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -10,7 +10,6 @@ filegroup(
name = "test-deps",
testonly = 1,
srcs = [
- "testenv.sh",
"//src/test/shell/bazel:test-deps",
],
)
@@ -126,6 +125,16 @@ sh_test(
)
sh_test(
+ name = "client_sigint_test",
+ size = "medium",
+ srcs = ["client_sigint_test.sh"],
+ data = [":test-deps"],
+ # This test doesn't work with the sandbox on, see the source file
+ # for details.
+ tags = ["local"],
+)
+
+sh_test(
name = "ide_info_generation",
size = "large",
srcs = ["ide_info_generation.sh"],
diff --git a/src/test/shell/integration/action_env_test.sh b/src/test/shell/integration/action_env_test.sh
index 6228247fce..52d0e2b541 100755
--- a/src/test/shell/integration/action_env_test.sh
+++ b/src/test/shell/integration/action_env_test.sh
@@ -17,14 +17,10 @@
# An end-to-end test that Bazel's provides the correct environment variables
# to actions.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
-
+# 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; }
#### SETUP #############################################################
@@ -46,7 +42,8 @@ EOF
function test_simple() {
export FOO=baz
bazel build --action_env=FOO=bar pkg:showenv \
- || fail "bazel build showenv failed"
+ || fail "${PRODUCT_NAME} build showenv failed"
+
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log
expect_log "FOO=bar"
}
@@ -56,7 +53,8 @@ function test_simple_latest_wins() {
export BAR=environmentbar
bazel build --action_env=FOO=foo \
--action_env=BAR=willbeoverridden --action_env=BAR=bar pkg:showenv \
- || fail "bazel build showenv failed"
+ || fail "${PRODUCT_NAME} build showenv failed"
+
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log
expect_log "FOO=foo"
expect_log "BAR=bar"
@@ -65,9 +63,11 @@ function test_simple_latest_wins() {
function test_client_env() {
export FOO=startup_foo
bazel clean --expunge
- bazel help build > /dev/null || fail "bazel help failed"
+ bazel help build > /dev/null || fail "${PRODUCT_NAME} help failed"
export FOO=client_foo
- bazel build --action_env=FOO pkg:showenv || fail "bazel build showenv failed"
+ bazel build --action_env=FOO pkg:showenv || \
+ fail "${PRODUCT_NAME} build showenv failed"
+
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log
expect_log "FOO=client_foo"
}
@@ -75,27 +75,29 @@ function test_client_env() {
function test_redo_action() {
export FOO=initial_foo
export UNRELATED=some_value
- bazel build --action_env=FOO pkg:showenv || fail "bazel build showenv failed"
+ bazel build --action_env=FOO pkg:showenv \
+ || fail "${PRODUCT_NAME} build showenv failed"
+
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log
expect_log "FOO=initial_foo"
# If an unrelated value changes, we expect the action not to be executed again
export UNRELATED=some_other_value
bazel build --action_env=FOO -s --experimental_ui pkg:showenv 2> $TEST_log \
- || fail "bazel build showenv failed"
+ || fail "${PRODUCT_NAME} build showenv failed"
expect_not_log '^SUBCOMMAND.*pkg:showenv'
# However, if a used variable changes, we expect the change to be propagated
export FOO=changed_foo
bazel build --action_env=FOO -s --experimental_ui pkg:showenv 2> $TEST_log \
- || fail "bazel build showenv failed"
+ || fail "${PRODUCT_NAME} build showenv failed"
expect_log '^SUBCOMMAND.*pkg:showenv'
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log
expect_log "FOO=changed_foo"
# But repeating the build with no further changes, no action should happen
bazel build --action_env=FOO -s --experimental_ui pkg:showenv 2> $TEST_log \
- || fail "bazel build showenv failed"
+ || fail "${PRODUCT_NAME} build showenv failed"
expect_not_log '^SUBCOMMAND.*pkg:showenv'
}
@@ -103,7 +105,8 @@ function test_latest_wins_arg() {
export FOO=bar
export BAR=baz
bazel build --action_env=BAR --action_env=FOO --action_env=FOO=foo \
- pkg:showenv || fail "bazel build showenv failed"
+ pkg:showenv || fail "${PRODUCT_NAME} build showenv failed"
+
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log
expect_log "FOO=foo"
expect_log "BAR=baz"
@@ -114,7 +117,8 @@ function test_latest_wins_env() {
export FOO=bar
export BAR=baz
bazel build --action_env=BAR --action_env=FOO=foo --action_env=FOO \
- pkg:showenv || fail "bazel build showenv failed"
+ pkg:showenv || fail "${PRODUCT_NAME} build showenv failed"
+
cat `bazel info ${PRODUCT_NAME}-genfiles`/pkg/env.txt > $TEST_log
expect_log "FOO=bar"
expect_log "BAR=baz"
@@ -122,19 +126,18 @@ function test_latest_wins_env() {
}
function test_env_freezing() {
- cat > .${PRODUCT_NAME}rc <<EOF
-build --action_env=FREEZE_TEST_FOO
-build --action_env=FREEZE_TEST_BAR=is_fixed
-build --action_env=FREEZE_TEST_BAZ=will_be_overridden
-build --action_env=FREEZE_TEST_BUILD
-EOF
+ add_to_bazelrc "build --action_env=FREEZE_TEST_FOO"
+ add_to_bazelrc "build --action_env=FREEZE_TEST_BAR=is_fixed"
+ add_to_bazelrc "build --action_env=FREEZE_TEST_BAZ=will_be_overridden"
+ add_to_bazelrc "build --action_env=FREEZE_TEST_BUILD"
export FREEZE_TEST_FOO=client_foo
export FREEZE_TEST_BAR=client_bar
export FREEZE_TEST_BAZ=client_baz
export FREEZE_TEST_BUILD=client_build
- $bazel info --action_env=FREEZE_TEST_BAZ client-env > $TEST_log
+ bazel info --action_env=FREEZE_TEST_BAZ client-env > $TEST_log
+
expect_log "build --action_env=FREEZE_TEST_FOO=client_foo"
expect_not_log "FREEZE_TEST_BAR"
expect_log "build --action_env=FREEZE_TEST_BAZ=client_baz"
diff --git a/src/test/shell/integration/bazel_command_log_test.sh b/src/test/shell/integration/bazel_command_log_test.sh
index 431c648842..195590857e 100755
--- a/src/test/shell/integration/bazel_command_log_test.sh
+++ b/src/test/shell/integration/bazel_command_log_test.sh
@@ -14,13 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
+# 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; }
log="$(bazel --batch info command_log)"
@@ -102,4 +99,4 @@ function test_client_server_mode_with_logging_flag() {
assert_equals "" "$(diff $TEST_log $log 2>&1)"
}
-run_suite "Integration tests of Blaze command log."
+run_suite "Integration tests of ${PRODUCT_NAME} command log."
diff --git a/src/test/shell/integration/bazel_javabase_test.sh b/src/test/shell/integration/bazel_javabase_test.sh
index bd2804ed11..fecf82c89d 100755
--- a/src/test/shell/integration/bazel_javabase_test.sh
+++ b/src/test/shell/integration/bazel_javabase_test.sh
@@ -15,15 +15,13 @@
# Tests that our --host_javabase startup selection algorithm works.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-put_bazel_on_path
-create_and_cd_client
+# 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; }
function test_use_depot_javabase() {
- bazel --batch version >& $TEST_log || fail "Couldn't run Bazel"
+ bazel --batch version >& $TEST_log || fail "Couldn't run ${PRODUCT_NAME}"
expect_not_log "Couldn't find java at"
expect_not_log "Problem with java installation"
}
diff --git a/src/test/shell/integration/bazel_query_test.sh b/src/test/shell/integration/bazel_query_test.sh
index 9138b683dc..b009adb147 100755
--- a/src/test/shell/integration/bazel_query_test.sh
+++ b/src/test/shell/integration/bazel_query_test.sh
@@ -16,13 +16,10 @@
#
# bazel_query_test.sh: integration tests for bazel query
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-put_bazel_on_path
-create_and_cd_client
-write_default_bazelrc
+# 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; }
add_to_bazelrc "build --package_path=%workspace%"
@@ -260,4 +257,4 @@ EOF
expect_log "//peach:harken"
}
-run_suite "bazel query tests"
+run_suite "${PRODUCT_NAME} query tests"
diff --git a/src/test/shell/integration/bazel_testjobs_test.sh b/src/test/shell/integration/bazel_testjobs_test.sh
index 12aca46878..7a1b2de5a0 100755
--- a/src/test/shell/integration/bazel_testjobs_test.sh
+++ b/src/test/shell/integration/bazel_testjobs_test.sh
@@ -14,14 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-EXTRA_BAZELRC="test --nocache_test_results"
-write_default_bazelrc
+# 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; }
+
+add_to_bazelrc "test --nocache_test_results"
# End of preamble.
diff --git a/src/test/shell/integration/client_sigint_test.sh b/src/test/shell/integration/client_sigint_test.sh
new file mode 100755
index 0000000000..88d9ad9f1b
--- /dev/null
+++ b/src/test/shell/integration/client_sigint_test.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+#
+# Copyright 2016 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.
+#
+# Test of client/server SIGINT handling. This test proves that the server
+# gracefully handles SIGINT.
+
+NO_SIGNAL_OVERRIDE=1
+# 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; }
+
+# This function doesn't work well with the sandbox because testfifo and
+# sleepyfifo are created outside the genrule.
+# TODO(bazel-team): Make this test compliant with the behavior of the sandbox
+function runbazel() {
+ startup_opt=$1; shift
+
+ local sleepyfifo=x/sleepyfifo
+ local testfifo=x/testfifo
+ mkdir -p x || fail "Can't create x"
+ cat > x/BUILD << EOF
+genrule(
+ name = "sleepy",
+ srcs = [],
+ outs = ["sleepy.out"],
+ local = 1,
+ cmd = "echo 'hi test' > $testfifo; cat $sleepyfifo; sleep 9999"
+)
+EOF
+
+ mkfifo $testfifo $sleepyfifo || fail "Couldn't create FIFOs under x"
+
+ set -m
+ bazel $startup_opt build --package_path . //x:sleepy >& $TEST_log &
+ local pid=$!
+
+ echo "${PRODUCT_NAME} running in background with pid $pid"
+ local testfifocontents=$(cat $testfifo)
+ echo "hi sleepy" > $sleepyfifo
+ echo "Interrupting pid $pid"
+ kill -INT $pid; sleep 3
+
+ status=0
+ # We expect the wait instruction to fail given that the build is interrupted.
+ wait $pid || status=$?
+ assert_equals 8 $status # Interruption exit code
+ assert_equals "hi test" "$testfifocontents"
+ set +m
+}
+
+function tear_down() {
+ bazel shutdown
+ rm -rf x
+}
+
+function assert_sigint_stops_build() {
+ runbazel $1
+
+ # Must have loaded package 'x':
+ expect_log 'Loading package: x'
+ expect_log 'Elapsed time'
+ expect_log 'build interrupted'
+}
+
+function test_sigint_server_mode() {
+ assert_sigint_stops_build "--nobatch"
+}
+
+function test_sigint_batch_mode() {
+ assert_sigint_stops_build "--batch"
+}
+
+run_suite "Tests of SIGINT on ${PRODUCT_NAME}"
diff --git a/src/test/shell/integration/discard_analysis_cache_test.sh b/src/test/shell/integration/discard_analysis_cache_test.sh
index 425ffbf2fa..9ba865a7c4 100755
--- a/src/test/shell/integration/discard_analysis_cache_test.sh
+++ b/src/test/shell/integration/discard_analysis_cache_test.sh
@@ -16,14 +16,10 @@
#
# A test for --discard_analysis_cache.
-
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-put_bazel_on_path
-create_and_cd_client
-write_default_bazelrc
+# 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; }
function write_hello_world_files() {
mkdir -p hello || fail "mkdir hello failed"
diff --git a/src/test/shell/integration/discard_graph_edges_test.sh b/src/test/shell/integration/discard_graph_edges_test.sh
index c2212c34a4..472d8daac8 100755
--- a/src/test/shell/integration/discard_graph_edges_test.sh
+++ b/src/test/shell/integration/discard_graph_edges_test.sh
@@ -16,13 +16,10 @@
#
# discard_graph_edges_test.sh: basic tests for the --discard_graph_edges flag.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
+# 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; }
#### SETUP #############################################################
diff --git a/src/test/shell/integration/experimental_ui_test.sh b/src/test/shell/integration/experimental_ui_test.sh
index ad6ff654db..e3265a788d 100755
--- a/src/test/shell/integration/experimental_ui_test.sh
+++ b/src/test/shell/integration/experimental_ui_test.sh
@@ -16,13 +16,10 @@
#
# An end-to-end test that Bazel's experimental UI produces reasonable output.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
+# 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; }
#### SETUP #############################################################
@@ -82,7 +79,8 @@ EOF
#### TESTS #############################################################
function test_basic_progress() {
- bazel test --experimental_ui --curses=yes --color=yes pkg:true 2>$TEST_log || fail "bazel test failed"
+ bazel test --experimental_ui --curses=yes --color=yes pkg:true 2>$TEST_log \
+ || fail "${PRODUCT_NAME} test failed"
# some progress indicator is shown
expect_log '\[[0-9,]* / [0-9,]*\]'
# curses are used to delete at least one line
@@ -94,7 +92,7 @@ function test_basic_progress() {
function test_noshow_progress() {
bazel test --experimental_ui --noshow_progress --curses=yes --color=yes \
- pkg:true 2>$TEST_log || fail "bazel test failed"
+ pkg:true 2>$TEST_log || fail "${PRODUCT_NAME} test failed"
# Info messages should still go through
expect_log 'Elapsed time'
# no progress indicator is shown
@@ -103,7 +101,7 @@ function test_noshow_progress() {
function test_basic_progress_no_curses() {
bazel test --experimental_ui --curses=no --color=yes pkg:true 2>$TEST_log \
- || fail "bazel test failed"
+ || fail "${PRODUCT_NAME} test failed"
# some progress indicator is shown
expect_log '\[[0-9,]* / [0-9,]*\]'
# cursor is not moved up
@@ -116,26 +114,28 @@ function test_basic_progress_no_curses() {
function test_no_curses_no_linebreak() {
bazel test --experimental_ui --curses=no --color=yes --terminal_columns=9 \
- pkg:true 2>$TEST_log || fail "bazel test failed"
+ pkg:true 2>$TEST_log || fail "${PRODUCT_NAME} test failed"
# expect a long-ish status line
expect_log '\[[0-9,]* / [0-9,]*\]......'
}
function test_pass() {
- bazel test --experimental_ui --curses=yes --color=yes pkg:true >$TEST_log || fail "bazel test failed"
+ bazel test --experimental_ui --curses=yes --color=yes pkg:true >$TEST_log \
+ || fail "${PRODUCT_NAME} test failed"
# PASS is written in green on the same line as the test target
expect_log 'pkg:true.*'$'\x1b\[32m''.*PASS'
}
function test_fail() {
- bazel test --experimental_ui --curses=yes --color=yes pkg:false >$TEST_log && fail "expected failure"
+ bazel test --experimental_ui --curses=yes --color=yes pkg:false >$TEST_log \
+ && fail "expected failure"
# FAIL is written in red bold on the same line as the test target
expect_log 'pkg:false.*'$'\x1b\[31m\x1b\[1m''.*FAIL'
}
function test_timestamp() {
bazel test --experimental_ui --show_timestamps pkg:true 2>$TEST_log \
- || fail "bazel test failed"
+ || fail "${PRODUCT_NAME} test failed"
# expect something that looks like HH:mm:ss
expect_log '[0-2][0-9]:[0-5][0-9]:[0-6][0-9]'
}
@@ -145,7 +145,7 @@ function test_info_spacing() {
# in particular free carriage-return characters.
BAZEL_INFO_OUTPUT=XXX`bazel info --experimental_ui workspace`XXX
echo "$BAZEL_INFO_OUTPUT" | grep -q 'XXX[^'$'\r'']*XXX' \
- || fail "bazel info output spaced as $BAZEL_INFO_OUTPUT"
+ || fail "${PRODUCT_NAME} info output spaced as $BAZEL_INFO_OUTPUT"
}
function test_query_spacing() {
@@ -195,30 +195,30 @@ function test_version_nobuild {
}
function test_subcommand {
- bazel clean || fail "bazel clean failed"
+ bazel clean || fail "${PRODUCT_NAME} clean failed"
bazel build --experimental_ui -s pkg:gentext 2>$TEST_log \
|| fail "bazel build failed"
expect_log "here be dragons"
}
function test_subcommand_notdefault {
- bazel clean || fail "bazel clean failed"
+ bazel clean || fail "${PRODUCT_NAME} clean failed"
bazel build --experimental_ui pkg:gentext 2>$TEST_log \
|| fail "bazel build failed"
expect_not_log "dragons"
}
function test_loading_progress {
- bazel clean || fail "bazel clean failed"
+ bazel clean || fail "${PRODUCT_NAME} clean failed"
bazel test --experimental_ui \
--experimental_skyframe_target_pattern_evaluator pkg:true 2>$TEST_log \
- || fail "bazel test failed"
+ || fail "${PRODUCT_NAME} test failed"
# some progress indicator is shown during loading
expect_log 'Loading.*[0-9,]* packages'
}
function test_failure_scrollback_buffer_curses {
- bazel clean || fail "bazel clean failed"
+ bazel clean || fail "${PRODUCT_NAME} clean failed"
bazel test --experimental_ui --curses=yes --color=yes \
--nocache_test_results pkg:false pkg:slow 2>$TEST_log \
&& fail "expected failure"
@@ -228,13 +228,13 @@ function test_failure_scrollback_buffer_curses {
function test_terminal_title {
bazel test --experimental_ui --progress_in_terminal_title pkg:true \
- 2>$TEST_log || fail "bazel test failed"
+ 2>$TEST_log || fail "${PRODUCT_NAME} test failed"
# The terminal title is changed
expect_log $'\x1b\]0;.*\x07'
}
function test_failure_scrollback_buffer {
- bazel clean || fail "bazel clean failed"
+ bazel clean || fail "${PRODUCT_NAME} clean failed"
bazel test --experimental_ui --curses=no --color=yes \
--nocache_test_results pkg:false pkg:slow 2>$TEST_log \
&& fail "expected failure"
@@ -249,4 +249,4 @@ function test_streamed {
expect_log 'foobar'
}
-run_suite "Integration tests for bazel's experimental UI"
+run_suite "Integration tests for ${PRODUCT_NAME}'s experimental UI"
diff --git a/src/test/shell/integration/ide_info_generation.sh b/src/test/shell/integration/ide_info_generation.sh
index 516945aff4..9cd215a8eb 100755
--- a/src/test/shell/integration/ide_info_generation.sh
+++ b/src/test/shell/integration/ide_info_generation.sh
@@ -16,17 +16,12 @@
#
# Integration tests for IDE build info generation.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
+# 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; }
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
-add_to_bazelrc "build --embed_changelist=none --noshow_progress"
-
-
-##### TESTS
+add_to_bazelrc "build --noshow_progress"
function test_ide_build_file_generation() {
mkdir -p com/google/example/simple
@@ -68,10 +63,10 @@ EOF
bazel build //com/google/example:complex \
--aspects AndroidStudioInfoAspect --output_groups "ide-info" \
|| fail "Expected success"
- [ -e bazel-bin/com/google/example/simple.aswb-build ] \
- || fail "bazel-bin/com/google/example/simple.aswb-build not found"
- [ -e bazel-bin/com/google/example/complex.aswb-build ] \
- || fail "bazel-bin/com/google/example/complex.aswb-build not found"
+ SIMPLE_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/simple.aswb-build"
+ [ -e $SIMPLE_ASWB_BUILD ] || fail "$SIMPLE_ASWB_BUILD not found"
+ COMPLEX_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/complex.aswb-build"
+ [ -e $COMPLEX_ASWB_BUILD ] || fail "$COMPLEX_ASWB_BUILD not found"
}
function test_detailed_result() {
@@ -119,10 +114,10 @@ EOF
--aspects AndroidStudioInfoAspect --output_groups "ide-info" \
--experimental_show_artifacts 2> $TEST_log \
|| fail "Expected success"
- [ -e bazel-bin/com/google/example/simple.aswb-build ] \
- || fail "bazel-bin/com/google/example/simple.aswb-build not found"
- [ -e bazel-bin/com/google/example/complex.aswb-build ] \
- || fail "bazel-bin/com/google/example/complex.aswb-build not found"
+ SIMPLE_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/simple.aswb-build"
+ [ -e $SIMPLE_ASWB_BUILD ] || fail "$SIMPLE_ASWB_BUILD not found"
+ COMPLEX_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/complex.aswb-build"
+ [ -e $COMPLEX_ASWB_BUILD ] || fail "$COMPLEX_ASWB_BUILD not found"
expect_log '^Build artifacts:'
expect_log "^>>>.*/com/google/example/complex.aswb-build"
@@ -178,10 +173,10 @@ EOF
bazel build //com/google/example:complex \
--aspects AndroidStudioInfoAspect --output_groups "ide-resolve" \
|| fail "Expected success"
- [ -e bazel-bin/com/google/example/libsimple.jar ] \
- || fail "bazel-bin/com/google/example/libsimple.jar not found"
- [ -e bazel-bin/com/google/example/libcomplex.jar ] \
- || fail "bazel-bin/com/google/example/libcomplex.jar not found"
+ [ -e ${PRODUCT_NAME}-bin/com/google/example/libsimple.jar ] \
+ || fail "${PRODUCT_NAME}-bin/com/google/example/libsimple.jar not found"
+ [ -e ${PRODUCT_NAME}-bin/com/google/example/libcomplex.jar ] \
+ || fail "${PRODUCT_NAME}-bin/com/google/example/libcomplex.jar not found"
}
function test_filtered_gen_jar_generation() {
@@ -204,14 +199,16 @@ java_library(
EOF
bazel build //com/google/example:test \
- --aspects AndroidStudioInfoAspect --output_groups "ide-resolve" --experimental_show_artifacts \
+ --aspects AndroidStudioInfoAspect --output_groups "ide-resolve" \
+ --experimental_show_artifacts \
|| fail "Expected success"
- [ -e bazel-bin/com/google/example/libtest.jar ] \
- || fail "bazel-bin/com/google/example/libtest.jar not found"
- [ -e bazel-bin/com/google/example/test-filtered-gen.jar ] \
- || fail "bazel-bin/com/google/example/test-filtered-gen.jar not found"
+ EXAMPLE_DIR="${PRODUCT_NAME}-bin/com/google/example"
+ [ -e "${EXAMPLE_DIR}/libtest.jar" ] \
+ || fail "${EXAMPLE_DIR}/libtest.jar not found"
+ [ -e "${EXAMPLE_DIR}/test-filtered-gen.jar" ] \
+ || fail "${EXAMPLE_DIR}/test-filtered-gen.jar not found"
- unzip bazel-bin/com/google/example/test-filtered-gen.jar
+ unzip "${EXAMPLE_DIR}/test-filtered-gen.jar"
[ -e gen/Gen.class ] \
|| fail "Filtered gen jar does not contain Gen.class"
[ ! -e com/google/example/Test.class ] \
@@ -258,10 +255,10 @@ EOF
bazel build //com/google/example:complex \
--aspects AndroidStudioInfoAspect --output_groups "ide-info-text" \
|| fail "Expected success"
- [ -e bazel-bin/com/google/example/simple.aswb-build.txt ] \
- || fail "bazel-bin/com/google/example/simple.aswb-build.txt not found"
- [ -e bazel-bin/com/google/example/complex.aswb-build.txt ] \
- || fail "bazel-bin/com/google/example/complex.aswb-build.txt not found"
+ SIMPLE_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/simple.aswb-build.txt"
+ [ -e $SIMPLE_ASWB_BUILD ] || fail "$SIMPLE_ASWB_BUILD not found"
+ COMPLEX_ASWB_BUILD="${PRODUCT_NAME}-bin/com/google/example/complex.aswb-build.txt"
+ [ -e $COMPLEX_ASWB_BUILD ] || fail "$COMPLEX_ASWB_BUILD not found"
}
run_suite "Test IDE info files generation"
diff --git a/src/test/shell/integration/java_integration_test.sh b/src/test/shell/integration/java_integration_test.sh
index 3ed4a18263..a8041ceeac 100755
--- a/src/test/shell/integration/java_integration_test.sh
+++ b/src/test/shell/integration/java_integration_test.sh
@@ -15,23 +15,18 @@
# limitations under the License.
#
# These are end to end tests for building Java.
-
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-source $(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/shell_utils.sh \
+CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+source "${CURRENT_DIR}/../shell_utils.sh" \
|| { echo "shell_utils.sh not found!" >&2; exit 1; }
+# Load the test setup defined in the parent directory
+source "${CURRENT_DIR}/../integration_test_setup.sh" \
+ || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
+
set -eu
declare -r runfiles_relative_javabase="$1"
-
-create_and_cd_client
-put_bazel_on_path
-
-write_default_bazelrc
-add_to_bazelrc "build --package_path=%workspace% --embed_changelist=none"
+add_to_bazelrc "build --package_path=%workspace%"
#### HELPER FUNCTIONS ##################################################
@@ -199,16 +194,24 @@ function test_compiles_hello_world_from_deploy_jar() {
write_hello_world_files "$pkg"
bazel build //$pkg/java/hello:hello_deploy.jar || fail "build failed"
- function check_deploy_jar_works() {
- "$@" | grep -q 'Hello, World!' || fail "comparison failed"
- }
- function check_arglists() {
- check_deploy_jar_works "$@" --singlejar
- check_deploy_jar_works "$@" --wrapper_script_flag=--singlejar
- check_deploy_jar_works "$@" REGULAR_ARG --wrapper_script_flag=--singlejar
- }
- check_arglists bazel run //$pkg/java/hello:hello --
- check_arglists ${PRODUCT_NAME}-bin/$pkg/java/hello/hello
+
+ bazel run //$pkg/java/hello:hello -- --singlejar | grep -q 'Hello, World!' \
+ || fail "comparison failed"
+ ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- --singlejar | \
+ grep -q 'Hello, World!' || fail "comparison failed"
+
+ bazel run //$pkg/java/hello:hello -- --wrapper_script_flag=--singlejar \
+ | grep -q 'Hello, World!' || fail "comparison failed"
+ ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- \
+ --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \
+ || fail "comparison failed"
+
+ bazel run //$pkg/java/hello:hello -- REGULAR_ARG \
+ --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \
+ || fail "comparison failed"
+ ${PRODUCT_NAME}-bin/$pkg/java/hello/hello -- REGULAR_ARG \
+ --wrapper_script_flag=--singlejar | grep -q 'Hello, World!' \
+ || fail "comparison failed"
}
function test_explicit_bogus_wrapper_args_are_rejected() {
diff --git a/src/test/shell/integration/loading_phase_tests.sh b/src/test/shell/integration/loading_phase_tests.sh
index b9d10dd23d..cba257afbd 100755
--- a/src/test/shell/integration/loading_phase_tests.sh
+++ b/src/test/shell/integration/loading_phase_tests.sh
@@ -18,15 +18,13 @@
# that use only the loading or analysis phases.
#
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
# Our tests use the static crosstool, so make it the default.
-EXTRA_BAZELRC="build --crosstool_top=@bazel_tools//tools/cpp:default-toolchain"
-write_default_bazelrc
+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
@@ -111,16 +109,16 @@ function test_options_errors() {
function test_bazelrc_option() {
cp ${bazelrc} ${new_workspace_dir}/.${PRODUCT_NAME}rc
- echo "build --cpu=piii" >>.${PRODUCT_NAME}rc # default bazelrc
- $bazel info >/dev/null 2>$TEST_log
+ echo "build --cpu=armeabi-v7a" >>.${PRODUCT_NAME}rc # default bazelrc
+ $PATH_TO_BAZEL_BIN info >/dev/null 2>$TEST_log
expect_log "Reading.*$(pwd)/.${PRODUCT_NAME}rc:
-.*--cpu=piii"
+.*--cpu=armeabi-v7a"
cp .${PRODUCT_NAME}rc foo
- echo "build --cpu=k8" >>foo # non-default bazelrc
- $bazel --${PRODUCT_NAME}rc=foo info >/dev/null 2>$TEST_log
+ echo "build --cpu=armeabi-v7a" >>foo # non-default bazelrc
+ $PATH_TO_BAZEL_BIN --${PRODUCT_NAME}rc=foo info >/dev/null 2>$TEST_log
expect_log "Reading.*$(pwd)/foo:
-.*--cpu=k8"
+.*--cpu=armeabi-v7a"
}
# This exercises the production-code assertion in AbstractCommand.java
@@ -317,4 +315,4 @@ function test_incremental_deleting_package_roots() {
expect_not_log "//a:external"
}
-run_suite "Miscellaneous integration tests of bazel, using loading/analysis phases."
+run_suite "Integration tests of ${PRODUCT_NAME} using loading/analysis phases."
diff --git a/src/test/shell/integration/output_filter_test.sh b/src/test/shell/integration/output_filter_test.sh
index 2007e367ae..588183e386 100755
--- a/src/test/shell/integration/output_filter_test.sh
+++ b/src/test/shell/integration/output_filter_test.sh
@@ -17,13 +17,10 @@
# output_filter_test.sh: a couple of end to end tests for the warning
# filter functionality.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
+# 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; }
function test_output_filter_cc() {
# "test warning filter for C compilation"
diff --git a/src/test/shell/integration/progress_reporting_test.sh b/src/test/shell/integration/progress_reporting_test.sh
index 7d46b4842e..f84b61aefc 100755
--- a/src/test/shell/integration/progress_reporting_test.sh
+++ b/src/test/shell/integration/progress_reporting_test.sh
@@ -16,21 +16,16 @@
#
# This test exercises action progress reporting.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
+# 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; }
set -eu
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
-
-cat >>"$bazelrc" <<EOF
-build --workspace_status_command="$(which true)" --nostamp
-build --show_progress_rate_limit=-1
-build --genrule_strategy=local
-EOF
+add_to_bazelrc "build --workspace_status_command="$(which true)" --nostamp"
+add_to_bazelrc "build --show_progress_rate_limit=-1"
+add_to_bazelrc "build --genrule_strategy=local"
# Match progress messages like [42 / 1,337]
declare -r PROGRESS_RX="\[[0-9, /]\+\]"
diff --git a/src/test/shell/integration/rc_options_test.sh b/src/test/shell/integration/rc_options_test.sh
index df9cb80f67..c9aeb88a9b 100755
--- a/src/test/shell/integration/rc_options_test.sh
+++ b/src/test/shell/integration/rc_options_test.sh
@@ -16,13 +16,10 @@
#
# An end-to-end test for Bazel's option handling
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
+# 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; }
#### SETUP #############################################################
diff --git a/src/test/shell/integration/run_test.sh b/src/test/shell/integration/run_test.sh
index ad986930c7..a2919db5ac 100755
--- a/src/test/shell/integration/run_test.sh
+++ b/src/test/shell/integration/run_test.sh
@@ -16,15 +16,12 @@
#
# Integration tests for "bazel run"
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
+NO_SIGNAL_OVERRIDE=1
+# 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; }
-create_and_cd_client
-NO_SIGNAL_OVERRIDE=1 put_bazel_on_path
-
-write_default_bazelrc
-add_to_bazelrc "build --embed_changelist=none"
add_to_bazelrc "test --notest_loasd"
#### HELPER FUNCTIONS ##################################################
@@ -97,10 +94,12 @@ function test_runfiles_present_cc_binary() {
Hello, kitty.
EOF
- bazel run --nobuild_runfile_links //cc:kitty > output || fail "Bazel run failed."
+ bazel run --nobuild_runfile_links //cc:kitty > output \
+ || fail "${PRODUCT_NAME} run failed."
assert_contains "Hello, kitty" output || fail "Output is not OK."
- bazel run --nobuild_runfile_links //cc:kitty > output2 || fail "Second Bazel run failed."
+ bazel run --nobuild_runfile_links //cc:kitty > output2 \
+ || fail "Second ${PRODUCT_NAME} run failed."
assert_contains "Hello, kitty" output2 || fail "Output is not OK."
}
@@ -111,7 +110,8 @@ function test_runfiles_updated_correctly_with_nobuild_runfile_links {
Hello, kitty.
EOF
- bazel run --nobuild_runfile_links //cc:kitty > output || fail "Bazel run failed."
+ bazel run --nobuild_runfile_links //cc:kitty > output \
+ || fail "${PRODUCT_NAME} run failed."
assert_contains "Hello, kitty" output || fail "Output is not OK."
rm cc/hello_kitty.txt
@@ -119,7 +119,8 @@ EOF
A pussycat.
EOF
- bazel run --nobuild_runfile_links //cc:kitty > output || fail "Bazel run failed."
+ bazel run --nobuild_runfile_links //cc:kitty > output \
+ || fail "${PRODUCT_NAME} run failed."
assert_contains "pussycat" output || fail "Output is not OK."
}
@@ -130,9 +131,9 @@ function test_script_file_generation {
chmod +x fubar/fubar.sh
bazel run --script_path=$(pwd)/fubar/output.sh //fubar \
- || fail "Bazel run failed (--script_path)."
+ || fail "${PRODUCT_NAME} run failed (--script_path)."
grep "fubar \"\$\@\"" ./fubar/output.sh \
- || fail "Bazel run --script_path output was incorrect."
+ || fail "${PRODUCT_NAME} run --script_path output was incorrect."
$(pwd)/fubar/output.sh a "b c" d > ./fubar/fubar.output \
|| fail "Generated script exited with an error."
@@ -159,15 +160,15 @@ function test_consistent_command_line_encoding {
chmod +x foo/foo.sh
bazel run //foo -- "$arg" > output \
- || fail "Bazel run failed."
+ || fail "${PRODUCT_NAME} run failed."
bazel test //foo:foo_test --test_arg="$arg" \
- || fail "Bazel test failed"
+ || fail "${PRODUCT_NAME} test failed"
bazel --batch run //foo -- "$arg" > output \
- || fail "Bazel run failed (--batch)."
+ || fail "${PRODUCT_NAME} run failed (--batch)."
bazel --batch test //foo:foo_test --test_arg="$arg" \
- || fail "Bazel test failed (--batch)"
+ || fail "${PRODUCT_NAME} test failed (--batch)"
}
function test_interrupt_kills_child() {
@@ -181,13 +182,13 @@ function test_interrupt_kills_child() {
# be run in "monitor mode" (with the command set -m) for bazel or the server to receive SIGINT.
local serverpid=$(bazel info server_pid)
if [ -z $serverpid ]; then
- fail "Couldn't get Bazel server PID"
+ fail "Couldn't get ${PRODUCT_NAME} server PID"
fi
(bazel run //foo:sleep-minute || true) &
local sleeppid
read sleeppid </tmp/sleep-minute-pipe
if [ -z $sleeppid ]; then
- fail "Bazel run did not invoke shell script"
+ fail "${PRODUCT_NAME} run did not invoke shell script"
fi
kill -SIGINT $serverpid
@@ -325,4 +326,4 @@ EOF
expect_log "Dancing with wolves"
}
-run_suite "'bazel run' integration tests"
+run_suite "'${PRODUCT_NAME} run' integration tests"
diff --git a/src/test/shell/integration/runfiles_test.sh b/src/test/shell/integration/runfiles_test.sh
index 8cd6ff5ca4..ef1faf0cf6 100755
--- a/src/test/shell/integration/runfiles_test.sh
+++ b/src/test/shell/integration/runfiles_test.sh
@@ -16,13 +16,10 @@
#
# An end-to-end test that Bazel produces runfiles trees as expected.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
+# 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; }
#### SETUP #############################################################
diff --git a/src/test/shell/integration/startup_options_test.sh b/src/test/shell/integration/startup_options_test.sh
index 1534ef1591..68dca09c10 100755
--- a/src/test/shell/integration/startup_options_test.sh
+++ b/src/test/shell/integration/startup_options_test.sh
@@ -16,17 +16,14 @@
#
# Test of Bazel's startup option handling.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-put_bazel_on_path
-create_and_cd_client
-write_default_bazelrc
+# 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; }
function test_different_startup_options() {
pid=$(bazel info server_pid 2> $TEST_log)
- [[ -n $pid ]] || fail "Couldn't run bazel"
+ [[ -n $pid ]] || fail "Couldn't run ${PRODUCT_NAME}"
newpid=$(bazel --batch info server_pid 2> $TEST_log)
expect_log "WARNING: Running B\\(azel\\|laze\\) server needs to be killed, because the startup options are different."
[[ "$newpid" != "$pid" ]] || fail "pid $pid was the same!"
@@ -35,4 +32,4 @@ function test_different_startup_options() {
true
}
-run_suite "bazel startup options test"
+run_suite "${PRODUCT_NAME} startup options test"
diff --git a/src/test/shell/integration/stub_finds_runfiles_test.sh b/src/test/shell/integration/stub_finds_runfiles_test.sh
index 1806cce21c..a608625fa2 100755
--- a/src/test/shell/integration/stub_finds_runfiles_test.sh
+++ b/src/test/shell/integration/stub_finds_runfiles_test.sh
@@ -19,9 +19,10 @@
set -eu
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
+# 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; }
test_strategy="standalone"
genrule_strategy="local"
@@ -31,10 +32,6 @@ if [ $# -ge 1 ]; then
shift
fi
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
-
#### TESTS #############################################################
mkdir pkg pkg/java
@@ -101,36 +98,36 @@ chmod +x pkg/*.sh
unset TEST_SRCDIR
bazel build //pkg:javabin
-bazel-bin/pkg/javabin
+${PRODUCT_NAME}-bin/pkg/javabin
bazel run //pkg:javabin
-bazel-bin/pkg/javabin.runfiles/*/pkg/javabin
+${PRODUCT_NAME}-bin/pkg/javabin.runfiles/*/pkg/javabin
bazel build //pkg:javatest
-bazel-bin/pkg/javatest
+${PRODUCT_NAME}-bin/pkg/javatest
bazel run //pkg:javatest
-bazel-bin/pkg/javatest.runfiles/*/pkg/javatest
+${PRODUCT_NAME}-bin/pkg/javatest.runfiles/*/pkg/javatest
bazel test --test_strategy="$test_strategy" //pkg:javatest
bazel build //pkg:pybin
-bazel-bin/pkg/pybin
+${PRODUCT_NAME}-bin/pkg/pybin
bazel run //pkg:pybin
-bazel-bin/pkg/pybin.runfiles/*/pkg/pybin
+${PRODUCT_NAME}-bin/pkg/pybin.runfiles/*/pkg/pybin
bazel build //pkg:pytest
-bazel-bin/pkg/pytest
+${PRODUCT_NAME}-bin/pkg/pytest
bazel run //pkg:pytest
-bazel-bin/pkg/pytest.runfiles/*/pkg/pytest
+${PRODUCT_NAME}-bin/pkg/pytest.runfiles/*/pkg/pytest
bazel test --test_strategy="$test_strategy" //pkg:pytest
bazel build //pkg:sh_runs_javabin
-bazel-bin/pkg/sh_runs_javabin
+${PRODUCT_NAME}-bin/pkg/sh_runs_javabin
bazel run //pkg:sh_runs_javabin
bazel build //pkg:sh_runs_javatest
bazel test --test_strategy="$test_strategy" //pkg:sh_runs_javatest
bazel build //pkg:sh_runs_pybin
-bazel-bin/pkg/sh_runs_pybin
+${PRODUCT_NAME}-bin/pkg/sh_runs_pybin
bazel run //pkg:sh_runs_pybin
bazel build //pkg:sh_runs_pytest
diff --git a/src/test/shell/integration/testenv.sh b/src/test/shell/integration/testenv.sh
deleted file mode 100755
index e7b484c3cd..0000000000
--- a/src/test/shell/integration/testenv.sh
+++ /dev/null
@@ -1,47 +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.
-#
-# Setting up the environment for our legacy integration tests.
-#
-source $(cd "$(dirname $(dirname "${BASH_SOURCE[0]}"))" && pwd)/bazel/test-setup.sh \
- || { echo "test-setup.sh not found!" >&2; exit 1; }
-
-PRODUCT_NAME=bazel
-WORKSPACE_NAME=main
-bazelrc=$TEST_TMPDIR/bazelrc
-
-function put_bazel_on_path() {
- put_blaze_on_path "$@"
-}
-
-function put_bazel_on_path() {
- # do nothing as test-setup already does that
- true
-}
-
-function write_default_bazelrc() {
- setup_bazelrc
-}
-
-function add_to_bazelrc() {
- echo "$@" >> .bazelrc
-}
-
-function create_and_cd_client() {
- setup_clean_workspace
- echo "workspace(name = '$WORKSPACE_NAME')" >WORKSPACE
- touch .bazelrc
-}
diff --git a/src/test/shell/integration/ui_test.sh b/src/test/shell/integration/ui_test.sh
index 6ab0d9453a..c3651cd7eb 100755
--- a/src/test/shell/integration/ui_test.sh
+++ b/src/test/shell/integration/ui_test.sh
@@ -16,13 +16,10 @@
#
# An end-to-end test that Bazel's experimental UI produces reasonable output.
-# Load test environment
-source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testenv.sh \
- || { echo "testenv.sh not found!" >&2; exit 1; }
-
-create_and_cd_client
-put_bazel_on_path
-write_default_bazelrc
+# 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; }
#### SETUP #############################################################
diff --git a/src/test/shell/integration_test_setup.sh b/src/test/shell/integration_test_setup.sh
new file mode 100755
index 0000000000..73f7c925e8
--- /dev/null
+++ b/src/test/shell/integration_test_setup.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+#
+# Copyright 2016 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.
+#
+
+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})""
+
+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!"
diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh
index 7843f9a654..0e7d1506a5 100755
--- a/src/test/shell/testenv.sh
+++ b/src/test/shell/testenv.sh
@@ -14,146 +14,507 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# Common utility file for Bazel shell tests
+# Testing environment for the Bazel integration tests
#
+# TODO(bazel-team): This file is currently an append of the old testenv.sh and
+# test-setup.sh files. This must be cleaned up eventually.
-# Enable errexit with pretty stack traces.
-enable_errexit
-
-# Print message in "$1" then exit with status "$2"
-die () {
- # second argument is optional, defaulting to 1
- local status_code=${2:-1}
- # Stop capturing stdout/stderr, and dump captured output
- if [ "$CAPTURED_STD_ERR" -ne 0 -o "$CAPTURED_STD_OUT" -ne 0 ]; then
- restore_outputs
- if [ "$CAPTURED_STD_OUT" -ne 0 ]; then
- cat "${TEST_TMPDIR}/captured.out"
- CAPTURED_STD_OUT=0
- fi
- if [ "$CAPTURED_STD_ERR" -ne 0 ]; then
- cat "${TEST_TMPDIR}/captured.err" 1>&2
- CAPTURED_STD_ERR=0
- fi
- fi
+# Make the command "bazel" available for tests.
+PATH_TO_BAZEL_BIN=$(rlocation io_bazel/src/bazel)
+PATH_TO_BAZEL_WRAPPER="${TEST_SRCDIR}/io_bazel/src/test/shell/bin"
+if [ ! -f "${PATH_TO_BAZEL_WRAPPER}/bazel" ];
+then
+ echo "Unable to find the Bazel binary at $PATH_TO_BAZEL_WRAPPER/bazel" >&2
+ exit 1;
+fi
+export PATH="$PATH_TO_BAZEL_WRAPPER:$PATH"
+
+################### shell/bazel/testenv ##################################
+# Setting up the environment for Bazel integration tests.
+#
+[ -z "$TEST_SRCDIR" ] && { echo "TEST_SRCDIR not set!" >&2; exit 1; }
+BAZEL_RUNFILES="$TEST_SRCDIR/io_bazel"
- if [ -n "${1-}" ] ; then
- echo "$1" 1>&2
+if ! type rlocation &> /dev/null; then
+ function rlocation() {
+ if [[ "$1" = /* ]]; then
+ echo $1
+ else
+ echo "$TEST_SRCDIR/$1"
fi
- if [ -n "${BASH-}" ]; then
- local caller_n=0
- while [ $caller_n -lt 4 ] && caller_out=$(caller $caller_n 2>/dev/null); do
- test $caller_n -eq 0 && echo "CALLER stack (max 4):"
- echo " $caller_out"
- let caller_n=caller_n+1
- done 1>&2
+ }
+ export -f rlocation
+fi
+
+# WORKSPACE file
+workspace_file="${BAZEL_RUNFILES}/WORKSPACE"
+
+# Bazel
+bazel_tree="$(rlocation io_bazel/src/test/shell/bazel/doc-srcs.zip)"
+bazel_data="${BAZEL_RUNFILES}"
+
+# Windows
+PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"
+function is_windows() {
+ # On windows, the shell test actually running on msys
+ if [[ "${PLATFORM}" =~ msys_nt* ]]; then
+ true
+ else
+ false
+ fi
+}
+
+# Java
+if is_windows; then
+ jdk_dir="$(cygpath -m $(cd $(rlocation local_jdk/bin/java.exe)/../..; pwd))"
+else
+ jdk_dir="${TEST_SRCDIR}/local_jdk"
+fi
+langtools="$(rlocation io_bazel/src/test/shell/bazel/langtools.jar)"
+
+# Tools directory location
+tools_dir="$(dirname $(rlocation io_bazel/tools/BUILD))"
+langtools_dir="$(dirname $(rlocation io_bazel/third_party/java/jdk/langtools/BUILD))"
+EXTRA_BAZELRC="build --ios_sdk_version=8.4"
+
+# Java tooling
+javabuilder_path="$(find ${BAZEL_RUNFILES} -name JavaBuilder_*.jar)"
+langtools_path="${BAZEL_RUNFILES}/third_party/java/jdk/langtools/javac.jar"
+singlejar_path="${BAZEL_RUNFILES}/src/java_tools/singlejar/SingleJar_deploy.jar"
+genclass_path="${BAZEL_RUNFILES}/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass_deploy.jar"
+junitrunner_path="${BAZEL_RUNFILES}/src/java_tools/junitrunner/java/com/google/testing/junit/runner/Runner_deploy.jar"
+ijar_path="${BAZEL_RUNFILES}/third_party/ijar/ijar"
+
+# Sandbox tools
+process_wrapper="${BAZEL_RUNFILES}/src/main/tools/process-wrapper"
+linux_sandbox="${BAZEL_RUNFILES}/src/main/tools/linux-sandbox"
+
+# iOS and Objective-C tooling
+iossim_path="${BAZEL_RUNFILES}/third_party/iossim/iossim"
+actoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/actoolwrapper/actoolwrapper.sh"
+ibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh"
+swiftstdlibtoolwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh"
+momcwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/momcwrapper/momcwrapper.sh"
+bundlemerge_path="${BAZEL_RUNFILES}/src/objc_tools/bundlemerge/bundlemerge_deploy.jar"
+plmerge_path="${BAZEL_RUNFILES}/src/objc_tools/plmerge/plmerge_deploy.jar"
+xcodegen_path="${BAZEL_RUNFILES}/src/objc_tools/xcodegen/xcodegen_deploy.jar"
+stdredirect_path="${BAZEL_RUNFILES}/src/tools/xcode/stdredirect/StdRedirect.dylib"
+realpath_path="${BAZEL_RUNFILES}/src/tools/xcode/realpath/realpath"
+environment_plist_path="${BAZEL_RUNFILES}/src/tools/xcode/environment/environment_plist.sh"
+xcrunwrapper_path="${BAZEL_RUNFILES}/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh"
+
+# Test data
+testdata_path=${BAZEL_RUNFILES}/src/test/shell/bazel/testdata
+python_server="${BAZEL_RUNFILES}/src/test/shell/bazel/testing_server.py"
+
+# Third-party
+MACHINE_TYPE="$(uname -m)"
+MACHINE_IS_64BIT='no'
+if [ "${MACHINE_TYPE}" = 'amd64' -o "${MACHINE_TYPE}" = 'x86_64' -o "${MACHINE_TYPE}" = 's390x' ]; then
+ MACHINE_IS_64BIT='yes'
+fi
+
+MACHINE_IS_Z='no'
+if [ "${MACHINE_TYPE}" = 's390x' ]; then
+ MACHINE_IS_Z='yes'
+fi
+
+case "${PLATFORM}" in
+ darwin)
+ if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then
+ protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_64.exe"
+ else
+ protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-osx-x86_32.exe"
fi
- if [ x"$status_code" != x -a x"$status_code" != x"0" ]; then
- exit "$status_code"
+ ;;
+ *)
+ if [ "${MACHINE_IS_64BIT}" = 'yes' ]; then
+ if [ "${MACHINE_IS_Z}" = 'yes' ]; then
+ protoc_compiler="${BAZEL_RUNFILES}//third_party/protobuf/protoc-linux-s390x_64.exe"
+ else
+ protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_64.exe"
+ fi
else
- exit 1
+ protoc_compiler="${BAZEL_RUNFILES}/third_party/protobuf/protoc-linux-x86_32.exe"
fi
+ ;;
+esac
+
+if [ -z ${RUNFILES_MANIFEST_ONLY+x} ]; then
+ protoc_jar="${BAZEL_RUNFILES}/third_party/protobuf/protobuf-*.jar"
+ junit_jar="${BAZEL_RUNFILES}/third_party/junit/junit-*.jar"
+ hamcrest_jar="${BAZEL_RUNFILES}/third_party/hamcrest/hamcrest-*.jar"
+else
+ protoc_jar=$(rlocation io_bazel/third_party/protobuf/protobuf-.*.jar)
+ junit_jar=$(rlocation io_bazel/third_party/junit/junit-.*.jar)
+ hamcrest_jar=$(rlocation io_bazel/third_party/hamcrest/hamcrest-.*.jar)
+fi
+
+# This function copies the tools directory from Bazel.
+function copy_tools_directory() {
+ cp -RL ${tools_dir}/* tools
+ # tools/jdk/BUILD file for JDK 7 is generated.
+ if [ -f tools/jdk/BUILD.* ]; then
+ cp tools/jdk/BUILD.* tools/jdk/BUILD
+ chmod +w tools/jdk/BUILD
+ fi
+ # To support custom langtools
+ cp ${langtools} tools/jdk/langtools.jar
+ cat >>tools/jdk/BUILD <<'EOF'
+filegroup(name = "test-langtools", srcs = ["langtools.jar"])
+EOF
+
+ mkdir -p third_party/java/jdk/langtools
+ cp -R ${langtools_dir}/* third_party/java/jdk/langtools
+
+ chmod -R +w .
+ mkdir -p tools/defaults
+ touch tools/defaults/BUILD
+
+ mkdir -p third_party/py/gflags
+ cat > third_party/py/gflags/BUILD <<EOF
+licenses(["notice"])
+package(default_visibility = ["//visibility:public"])
+
+py_library(
+ name = "gflags",
+)
+EOF
}
-# Print message in "$1" then record that a non-fatal error occurred in ERROR_COUNT
-ERROR_COUNT="${ERROR_COUNT:-0}"
-error () {
- if [ -n "$1" ] ; then
- echo "$1" 1>&2
- fi
- ERROR_COUNT=$(($ERROR_COUNT + 1))
+# Report whether a given directory name corresponds to a tools directory.
+function is_tools_directory() {
+ case "$1" in
+ third_party|tools|src)
+ true
+ ;;
+ *)
+ false
+ ;;
+ esac
+}
+
+# Copy the examples of the base workspace
+function copy_examples() {
+ EXAMPLE="$(cd $(dirname $(rlocation io_bazel/examples/cpp/BUILD))/..; pwd)"
+ cp -RL ${EXAMPLE} .
+ chmod -R +w .
+}
+
+#
+# Find a random unused TCP port
+#
+pick_random_unused_tcp_port () {
+ perl -MSocket -e '
+sub CheckPort {
+ my ($port) = @_;
+ socket(TCP_SOCK, PF_INET, SOCK_STREAM, getprotobyname("tcp"))
+ || die "socket(TCP): $!";
+ setsockopt(TCP_SOCK, SOL_SOCKET, SO_REUSEADDR, 1)
+ || die "setsockopt(TCP): $!";
+ return 0 unless bind(TCP_SOCK, sockaddr_in($port, INADDR_ANY));
+ socket(UDP_SOCK, PF_INET, SOCK_DGRAM, getprotobyname("udp"))
+ || die "socket(UDP): $!";
+ return 0 unless bind(UDP_SOCK, sockaddr_in($port, INADDR_ANY));
+ return 1;
+}
+for (1 .. 128) {
+ my ($port) = int(rand() * 27000 + 32760);
+ if (CheckPort($port)) {
+ print "$port\n";
+ exit 0;
+ }
+}
+print "NO_FREE_PORT_FOUND\n";
+exit 1;
+'
+}
+
+#
+# A uniform SHA-256 commands that works accross platform
+#
+case "${PLATFORM}" in
+ darwin)
+ function sha256sum() {
+ cat "$1" | shasum -a 256 | cut -f 1 -d " "
+ }
+ ;;
+ *)
+ # Under linux sha256sum should exists
+ ;;
+esac
+
+################### shell/bazel/test-setup ###############################
+# Setup bazel for integration tests
+#
+
+# OS X has a limit in the pipe length, so force the root to a shorter one
+bazel_root="${TEST_TMPDIR}/root"
+mkdir -p "${bazel_root}"
+
+bazel_javabase="${jdk_dir}"
+
+echo "bazel binary is at $PATH_TO_BAZEL_WRAPPER"
+
+# Here we unset variable that were set by the invoking Blaze instance
+unset JAVA_RUNFILES
+
+function setup_bazelrc() {
+ cat >$TEST_TMPDIR/bazelrc <<EOF
+startup --output_user_root=${bazel_root}
+startup --host_javabase=${bazel_javabase}
+build -j 8
+${EXTRA_BAZELRC:-}
+EOF
}
-# Die if "$1" != "$2", print $3 as death reason
-check_eq () {
- [ "$1" = "$2" ] || die "Check failed: '$1' == '$2' ${3:+ ($3)}"
+function setup_android_support() {
+ ANDROID_NDK=$PWD/android_ndk
+ ANDROID_SDK=$PWD/android_sdk
+
+ # TODO(bazel-team): This hard-codes the name of the Android repository in
+ # the WORKSPACE file of Bazel. Change this once external repositories have
+ # their own defined names under which they are mounted.
+ NDK_SRCDIR=$TEST_SRCDIR/androidndk/ndk
+ SDK_SRCDIR=$TEST_SRCDIR/androidsdk
+
+ mkdir -p $ANDROID_NDK
+ mkdir -p $ANDROID_SDK
+
+ for i in $NDK_SRCDIR/*; do
+ if [[ "$(basename $i)" != "BUILD" ]]; then
+ ln -s "$i" "$ANDROID_NDK/$(basename $i)"
+ fi
+ done
+
+ for i in $SDK_SRCDIR/*; do
+ ln -s "$i" "$ANDROID_SDK/$(basename $i)"
+ done
+
+
+ local ANDROID_SDK_API_LEVEL=$(ls $SDK_SRCDIR/platforms | cut -d '-' -f 2 | sort -n | tail -1)
+ local ANDROID_NDK_API_LEVEL=$(ls $NDK_SRCDIR/platforms | cut -d '-' -f 2 | sort -n | tail -1)
+ local ANDROID_SDK_TOOLS_VERSION=$(ls $SDK_SRCDIR/build-tools | sort -n | tail -1)
+ cat >> WORKSPACE <<EOF
+android_ndk_repository(
+ name = "androidndk",
+ path = "$ANDROID_NDK",
+ api_level = $ANDROID_NDK_API_LEVEL,
+)
+
+android_sdk_repository(
+ name = "androidsdk",
+ path = "$ANDROID_SDK",
+ build_tools_version = "$ANDROID_SDK_TOOLS_VERSION",
+ api_level = $ANDROID_SDK_API_LEVEL,
+)
+EOF
}
-# Die if "$1" == "$2", print $3 as death reason
-check_ne () {
- [ "$1" != "$2" ] || die "Check failed: '$1' != '$2' ${3:+ ($3)}"
+function setup_javatest_common() {
+ # TODO(bazel-team): we should use remote repositories.
+ mkdir -p third_party
+ if [ ! -f third_party/BUILD ]; then
+ cat <<EOF >third_party/BUILD
+package(default_visibility = ["//visibility:public"])
+EOF
+ fi
+
+ [ -e third_party/junit.jar ] || ln -s ${junit_jar} third_party/junit.jar
+ [ -e third_party/hamcrest.jar ] \
+ || ln -s ${hamcrest_jar} third_party/hamcrest.jar
}
-# The structure of the following if statements is such that if '[' fails
-# (e.g., a non-number was passed in) then the check will fail.
+function setup_javatest_support() {
+ setup_javatest_common
+ grep -q 'name = "junit4"' third_party/BUILD \
+ || cat <<EOF >>third_party/BUILD
+java_import(
+ name = "junit4",
+ jars = [
+ "junit.jar",
+ "hamcrest.jar",
+ ],
+)
+EOF
+}
-# Die if "$1" > "$2", print $3 as death reason
-check_le () {
- [ "$1" -gt "$2" ] || die "Check failed: '$1' <= '$2' ${3:+ ($3)}"
+function setup_skylark_javatest_support() {
+ setup_javatest_common
+ grep -q "name = \"junit4-jars\"" third_party/BUILD \
+ || cat <<EOF >>third_party/BUILD
+filegroup(
+ name = "junit4-jars",
+ srcs = [
+ "junit.jar",
+ "hamcrest.jar",
+ ],
+)
+EOF
}
-# Die if "$1" >= "$2", print $3 as death reason
-check_lt () {
- [ "$1" -lt "$2" ] || die "Check failed: '$1' < '$2' ${3:+ ($3)}"
+function setup_iossim() {
+ mkdir -p third_party/iossim
+ ln -sv ${iossim_path} third_party/iossim/iossim
+
+ cat <<EOF >>third_party/iossim/BUILD
+licenses(["unencumbered"])
+package(default_visibility = ["//visibility:public"])
+
+exports_files(["iossim"])
+EOF
}
-# Die if "$1" < "$2", print $3 as death reason
-check_ge () {
- [ "$1" -ge "$2" ] || die "Check failed: '$1' >= '$2' ${3:+ ($3)}"
+# Sets up Objective-C tools. Mac only.
+function setup_objc_test_support() {
+ IOS_SDK_VERSION=$(xcrun --sdk iphoneos --show-sdk-version)
}
-# Die if "$1" <= "$2", print $3 as death reason
-check_gt () {
- [ "$1" -gt "$2" ] || die "Check failed: '$1' > '$2' ${3:+ ($3)}"
+workspaces=()
+# Set-up a new, clean workspace with only the tools installed.
+function create_new_workspace() {
+ new_workspace_dir=${1:-$(mktemp -d ${TEST_TMPDIR}/workspace.XXXXXXXX)}
+ rm -fr ${new_workspace_dir}
+ mkdir -p ${new_workspace_dir}
+ workspaces+=(${new_workspace_dir})
+ cd ${new_workspace_dir}
+ mkdir tools
+ mkdir -p third_party/java/jdk/langtools
+
+ copy_tools_directory
+
+ [ -e third_party/java/jdk/langtools/javac.jar ] \
+ || ln -s "${langtools_path}" third_party/java/jdk/langtools/javac.jar
+
+ touch WORKSPACE
}
-# Die if $2 !~ $1; print $3 as death reason
-check_match ()
-{
- expr match "$2" "$1" >/dev/null || \
- die "Check failed: '$2' does not match regex '$1' ${3:+ ($3)}"
+# Set-up a clean default workspace.
+function setup_clean_workspace() {
+ export WORKSPACE_DIR=${TEST_TMPDIR}/workspace
+ echo "setting up client in ${WORKSPACE_DIR}" > $TEST_log
+ rm -fr ${WORKSPACE_DIR}
+ create_new_workspace ${WORKSPACE_DIR}
+ [ "${new_workspace_dir}" = "${WORKSPACE_DIR}" ] || \
+ { echo "Failed to create workspace" >&2; exit 1; }
+ export BAZEL_INSTALL_BASE=$(bazel info install_base)
+ export BAZEL_GENFILES_DIR=$(bazel info bazel-genfiles)
+ export BAZEL_BIN_DIR=$(bazel info bazel-bin)
+ if is_windows; then
+ export BAZEL_SH="$(cygpath --windows /bin/bash)"
+ fi
}
-# Run command "$1" at exit. Like "trap" but multiple atexits don't
-# overwrite each other. Will break if someone does call trap
-# directly. So, don't do that.
-ATEXIT="${ATEXIT-}"
-atexit () {
- if [ -z "$ATEXIT" ]; then
- ATEXIT="$1"
- else
- ATEXIT="$1 ; $ATEXIT"
+# Clean up all files that are not in tools directories, to restart
+# from a clean workspace
+function cleanup_workspace() {
+ if [ -d "${WORKSPACE_DIR:-}" ]; then
+ echo "Cleaning up workspace" > $TEST_log
+ cd ${WORKSPACE_DIR}
+ bazel clean >& $TEST_log # Clean up the output base
+
+ for i in $(ls); do
+ if ! is_tools_directory "$i"; then
+ rm -fr "$i"
+ fi
+ done
+ touch WORKSPACE
+ fi
+ for i in ${workspaces}; do
+ if [ "$i" != "${WORKSPACE_DIR:-}" ]; then
+ rm -fr $i
fi
- trap "$ATEXIT" EXIT
+ done
+ workspaces=()
}
-## TEST_TMPDIR
-if [ -z "${TEST_TMPDIR:-}" ]; then
- export TEST_TMPDIR="$(mktemp -d ${TMPDIR:-/tmp}/bazel-test.XXXXXXXX)"
-fi
-if [ ! -e "${TEST_TMPDIR}" ]; then
- mkdir -p -m 0700 "${TEST_TMPDIR}"
- # Clean TEST_TMPDIR on exit
- atexit "rm -fr ${TEST_TMPDIR}"
-fi
+# Clean-up the bazel install base
+function cleanup() {
+ if [ -d "${BAZEL_INSTALL_BASE:-__does_not_exists__}" ]; then
+ rm -fr "${BAZEL_INSTALL_BASE}"
+ fi
+}
-# Functions to compare the actual output of a test to the expected
-# (golden) output.
+function tear_down() {
+ cleanup_workspace
+}
+
+#
+# Simples assert to make the tests more readable
#
-# Usage:
-# capture_test_stdout
-# ... do something ...
-# diff_test_stdout "$TEST_SRCDIR/path/to/golden.out"
+function assert_build() {
+ bazel build -s --verbose_failures $* || fail "Failed to build $*"
+}
-# Redirect a file descriptor to a file.
-CAPTURED_STD_OUT="${CAPTURED_STD_OUT:-0}"
-CAPTURED_STD_ERR="${CAPTURED_STD_ERR:-0}"
+function assert_build_output() {
+ local OUTPUT=$1
+ shift
+ assert_build "$*"
+ test -f "$OUTPUT" || fail "Output $OUTPUT not found for target $*"
+}
-capture_test_stdout () {
- exec 3>&1 # Save stdout as fd 3
- exec 4>"${TEST_TMPDIR}/captured.out"
- exec 1>&4
- CAPTURED_STD_OUT=1
+function assert_build_fails() {
+ bazel build -s $1 >& $TEST_log \
+ && fail "Test $1 succeed while expecting failure" \
+ || true
+ if [ -n "${2:-}" ]; then
+ expect_log "$2"
+ fi
}
-capture_test_stderr () {
- exec 6>&2 # Save stderr as fd 6
- exec 7>"${TEST_TMPDIR}/captured.err"
- exec 2>&7
- CAPTURED_STD_ERR=1
+function assert_test_ok() {
+ bazel test --test_output=errors $* >& $TEST_log \
+ || fail "Test $1 failed while expecting success"
}
-# Force XML_OUTPUT_FILE to an existing path
-if [ -z "${XML_OUTPUT_FILE:-}" ]; then
- XML_OUTPUT_FILE=${TEST_TMPDIR}/ouput.xml
-fi
+function assert_test_fails() {
+ bazel test --test_output=errors $* >& $TEST_log \
+ && fail "Test $* succeed while expecting failure" \
+ || true
+ expect_log "$1.*FAILED"
+}
+
+function assert_binary_run() {
+ $1 >& $TEST_log || fail "Failed to run $1"
+ [ -z "${2:-}" ] || expect_log "$2"
+}
+
+function assert_bazel_run() {
+ bazel run $1 >& $TEST_log || fail "Failed to run $1"
+ [ -z "${2:-}" ] || expect_log "$2"
+
+ assert_binary_run "./bazel-bin/$(echo "$1" | sed 's|^//||' | sed 's|:|/|')" "${2:-}"
+}
+
+setup_bazelrc
+setup_clean_workspace
+
+################### shell/integration/testenv ############################
+# Setting up the environment for our legacy integration tests.
+#
+PRODUCT_NAME=bazel
+WORKSPACE_NAME=main
+bazelrc=$TEST_TMPDIR/bazelrc
+
+function put_bazel_on_path() {
+ # do nothing as test-setup already does that
+ true
+}
+
+function write_default_bazelrc() {
+ setup_bazelrc
+}
+
+function add_to_bazelrc() {
+ echo "$@" >> $bazelrc
+}
+
+function create_and_cd_client() {
+ setup_clean_workspace
+ echo "workspace(name = '$WORKSPACE_NAME')" >WORKSPACE
+ touch .bazelrc
+}
+
+################### Extra ############################
+# Functions that need to be called before each test.
+create_and_cd_client \ No newline at end of file
diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash
index c78f491270..2da9cd3092 100644
--- a/src/test/shell/unittest.bash
+++ b/src/test/shell/unittest.bash
@@ -98,7 +98,148 @@ function disable_errexit() {
trap - ERR
}
-source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }
+#### Set up the test environment, branched from the old shell/testenv.sh
+
+# Enable errexit with pretty stack traces.
+enable_errexit
+
+# Print message in "$1" then exit with status "$2"
+die () {
+ # second argument is optional, defaulting to 1
+ local status_code=${2:-1}
+ # Stop capturing stdout/stderr, and dump captured output
+ if [ "$CAPTURED_STD_ERR" -ne 0 -o "$CAPTURED_STD_OUT" -ne 0 ]; then
+ restore_outputs
+ if [ "$CAPTURED_STD_OUT" -ne 0 ]; then
+ cat "${TEST_TMPDIR}/captured.out"
+ CAPTURED_STD_OUT=0
+ fi
+ if [ "$CAPTURED_STD_ERR" -ne 0 ]; then
+ cat "${TEST_TMPDIR}/captured.err" 1>&2
+ CAPTURED_STD_ERR=0
+ fi
+ fi
+
+ if [ -n "${1-}" ] ; then
+ echo "$1" 1>&2
+ fi
+ if [ -n "${BASH-}" ]; then
+ local caller_n=0
+ while [ $caller_n -lt 4 ] && caller_out=$(caller $caller_n 2>/dev/null); do
+ test $caller_n -eq 0 && echo "CALLER stack (max 4):"
+ echo " $caller_out"
+ let caller_n=caller_n+1
+ done 1>&2
+ fi
+ if [ x"$status_code" != x -a x"$status_code" != x"0" ]; then
+ exit "$status_code"
+ else
+ exit 1
+ fi
+}
+
+# Print message in "$1" then record that a non-fatal error occurred in ERROR_COUNT
+ERROR_COUNT="${ERROR_COUNT:-0}"
+error () {
+ if [ -n "$1" ] ; then
+ echo "$1" 1>&2
+ fi
+ ERROR_COUNT=$(($ERROR_COUNT + 1))
+}
+
+# Die if "$1" != "$2", print $3 as death reason
+check_eq () {
+ [ "$1" = "$2" ] || die "Check failed: '$1' == '$2' ${3:+ ($3)}"
+}
+
+# Die if "$1" == "$2", print $3 as death reason
+check_ne () {
+ [ "$1" != "$2" ] || die "Check failed: '$1' != '$2' ${3:+ ($3)}"
+}
+
+# The structure of the following if statements is such that if '[' fails
+# (e.g., a non-number was passed in) then the check will fail.
+
+# Die if "$1" > "$2", print $3 as death reason
+check_le () {
+ [ "$1" -gt "$2" ] || die "Check failed: '$1' <= '$2' ${3:+ ($3)}"
+}
+
+# Die if "$1" >= "$2", print $3 as death reason
+check_lt () {
+ [ "$1" -lt "$2" ] || die "Check failed: '$1' < '$2' ${3:+ ($3)}"
+}
+
+# Die if "$1" < "$2", print $3 as death reason
+check_ge () {
+ [ "$1" -ge "$2" ] || die "Check failed: '$1' >= '$2' ${3:+ ($3)}"
+}
+
+# Die if "$1" <= "$2", print $3 as death reason
+check_gt () {
+ [ "$1" -gt "$2" ] || die "Check failed: '$1' > '$2' ${3:+ ($3)}"
+}
+
+# Die if $2 !~ $1; print $3 as death reason
+check_match ()
+{
+ expr match "$2" "$1" >/dev/null || \
+ die "Check failed: '$2' does not match regex '$1' ${3:+ ($3)}"
+}
+
+# Run command "$1" at exit. Like "trap" but multiple atexits don't
+# overwrite each other. Will break if someone does call trap
+# directly. So, don't do that.
+ATEXIT="${ATEXIT-}"
+atexit () {
+ if [ -z "$ATEXIT" ]; then
+ ATEXIT="$1"
+ else
+ ATEXIT="$1 ; $ATEXIT"
+ fi
+ trap "$ATEXIT" EXIT
+}
+
+## TEST_TMPDIR
+if [ -z "${TEST_TMPDIR:-}" ]; then
+ export TEST_TMPDIR="$(mktemp -d ${TMPDIR:-/tmp}/bazel-test.XXXXXXXX)"
+fi
+if [ ! -e "${TEST_TMPDIR}" ]; then
+ mkdir -p -m 0700 "${TEST_TMPDIR}"
+ # Clean TEST_TMPDIR on exit
+ atexit "rm -fr ${TEST_TMPDIR}"
+fi
+
+# Functions to compare the actual output of a test to the expected
+# (golden) output.
+#
+# Usage:
+# capture_test_stdout
+# ... do something ...
+# diff_test_stdout "$TEST_SRCDIR/path/to/golden.out"
+
+# Redirect a file descriptor to a file.
+CAPTURED_STD_OUT="${CAPTURED_STD_OUT:-0}"
+CAPTURED_STD_ERR="${CAPTURED_STD_ERR:-0}"
+
+capture_test_stdout () {
+ exec 3>&1 # Save stdout as fd 3
+ exec 4>"${TEST_TMPDIR}/captured.out"
+ exec 1>&4
+ CAPTURED_STD_OUT=1
+}
+
+capture_test_stderr () {
+ exec 6>&2 # Save stderr as fd 6
+ exec 7>"${TEST_TMPDIR}/captured.err"
+ exec 2>&7
+ CAPTURED_STD_ERR=1
+}
+
+# Force XML_OUTPUT_FILE to an existing path
+if [ -z "${XML_OUTPUT_FILE:-}" ]; then
+ XML_OUTPUT_FILE=${TEST_TMPDIR}/ouput.xml
+fi
#### Global variables: