aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell/testenv.sh
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 /src/test/shell/testenv.sh
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
Diffstat (limited to 'src/test/shell/testenv.sh')
-rwxr-xr-xsrc/test/shell/testenv.sh573
1 files changed, 467 insertions, 106 deletions
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