Skip to content

Commit

Permalink
Create a proper wrapper script for executing "bazel" in the integrati…
Browse files Browse the repository at this point in the history
…on 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
  • Loading branch information
lfpino authored and philwo committed Oct 19, 2016
1 parent aecf826 commit fa38906
Show file tree
Hide file tree
Showing 67 changed files with 1,139 additions and 1,045 deletions.
6 changes: 6 additions & 0 deletions src/test/shell/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package(default_visibility = ["//visibility:private"])

exports_files([
"bin/bazel",
"testenv.sh",
"integration_test_setup.sh",
])

filegroup(
name = "srcs",
srcs = glob(["**"]) + [
Expand Down
12 changes: 4 additions & 8 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/apple/bazel_apple_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/apple/bazel_objc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_execute_testlog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_localtest_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/test/shell/bazel/bazel_rules_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/test/shell/bazel/bazel_sandboxing_cpp_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions src/test/shell/bazel/bazel_sandboxing_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_toolchain_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_tools_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_windows_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_worker_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bazel_workspace_status_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/bound_targets_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/cc_inc_library_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/client_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/empty_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/execroot_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/test/shell/bazel/external_correctness_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/external_skylark_load_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit fa38906

Please sign in to comment.