diff options
-rwxr-xr-x | scripts/ci/windows/compile_windows.sh | 2 | ||||
-rw-r--r-- | src/test/shell/bazel/BUILD | 4 | ||||
-rwxr-xr-x | src/test/shell/bazel/bazel_windows_cpp_test.sh | 70 | ||||
-rwxr-xr-x | src/test/shell/bazel/bazel_windows_example_test.sh | 88 | ||||
-rwxr-xr-x | src/test/shell/bazel/testenv.sh | 13 |
5 files changed, 101 insertions, 76 deletions
diff --git a/scripts/ci/windows/compile_windows.sh b/scripts/ci/windows/compile_windows.sh index 787789212c..30f3ae624c 100755 --- a/scripts/ci/windows/compile_windows.sh +++ b/scripts/ci/windows/compile_windows.sh @@ -56,7 +56,7 @@ cp output/bazel.exe output/ci/ # todo(bazel-team): add more tests here. echo "Running tests" retCode=0 -./output/bazel test --test_output=all //src/test/shell/bazel:bazel_windows_cpp_test || retCode=$? +./output/bazel test --test_output=all //src/test/shell/bazel:bazel_windows_example_test || retCode=$? # Exit for failure except for test failures (exit code 3). if (( $retCode != 0 )); then echo "$retCode" > .unstable diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 7e1f4e68cd..95151b40e2 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -90,9 +90,9 @@ sh_test( ) sh_test( - name = "bazel_windows_cpp_test", + name = "bazel_windows_example_test", size = "large", - srcs = ["bazel_windows_cpp_test.sh"], + srcs = ["bazel_windows_example_test.sh"], data = [ ":test-deps", ], diff --git a/src/test/shell/bazel/bazel_windows_cpp_test.sh b/src/test/shell/bazel/bazel_windows_cpp_test.sh deleted file mode 100755 index e51f411433..0000000000 --- a/src/test/shell/bazel/bazel_windows_cpp_test.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -x -# -# 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. -# -# Tests the examples provided in Bazel with MSVC toolchain -# - -if ! type rlocation &> /dev/null; then - # We do not care about this test on old Bazel releases. - 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; } - -if ! is_windows; then - echo "This test suite requires running on Windows. But now is ${PLATFORM}" >&2 - exit 0 -fi - -function set_up() { - copy_examples - export PATH=$PATH:/c/python_27_amd64/files -} - -common_args="-s --verbose_failures --cpu=x64_windows_msvc" - -function assert_build_windows() { - bazel build ${common_args} $* || fail "Failed to build $*" -} - -function assert_test_ok_windows() { - bazel test ${common_args} --test_output=errors $* \ - || fail "Test $1 failed while expecting success" -} - -function assert_test_fails_windows() { - bazel test ${common_args} --test_output=errors $* >& $TEST_log \ - && fail "Test $* succeed while expecting failure" \ - || true - expect_log "$1.*FAILED" -} - -# -# Native rules -# -function test_cpp() { - local cpp_pkg=examples/cpp - assert_build_windows "//examples/cpp:hello-world" - test -f "./bazel-bin/${cpp_pkg}/libhello-lib.a" || fail "libhello-lib.a should be generated" - assert_binary_run "./bazel-bin/${cpp_pkg}/hello-world foo" "Hello foo" - assert_test_ok_windows "//examples/cpp:hello-success_test" - assert_test_fails_windows "//examples/cpp:hello-fail_test" -} - -run_suite "cpp examples on Windows" - diff --git a/src/test/shell/bazel/bazel_windows_example_test.sh b/src/test/shell/bazel/bazel_windows_example_test.sh new file mode 100755 index 0000000000..c0bd25b54e --- /dev/null +++ b/src/test/shell/bazel/bazel_windows_example_test.sh @@ -0,0 +1,88 @@ +#!/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. +# +# Tests the examples provided in Bazel with MSVC toolchain +# + +if ! type rlocation &> /dev/null; then + # We do not care about this test on old Bazel releases. + 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; } + +if ! is_windows; then + echo "This test suite requires running on Windows. But now is ${PLATFORM}" >&2 + exit 0 +fi + +function set_up() { + copy_examples + export PATH=$PATH:/c/python_27_amd64/files + EXTRA_BAZELRC="build --cpu=x64_windows_msvc" + setup_bazelrc +} + +# An assertion that execute a binary from a sub directory (to test runfiles) +function assert_binary_run_from_subdir() { + ( # Needed to make execution from a different path work. + export PATH=${bazel_javabase}/bin:"$PATH" && + mkdir -p x && + cd x && + unset JAVA_RUNFILES && + unset TEST_SRCDIR && + assert_binary_run "../$1" "$2" ) +} + +# +# Native rules +# +function test_cpp() { + local cpp_pkg=examples/cpp + assert_build_output ./bazel-bin/${cpp_pkg}/libhello-lib.a ${cpp_pkg}:hello-world + assert_bazel_run "//examples/cpp:hello-world foo" "Hello foo" + assert_test_ok "//examples/cpp:hello-success_test" + assert_test_fails "//examples/cpp:hello-fail_test" +} + +function test_java() { + local java_pkg=examples/java-native/src/main/java/com/example/myproject + + assert_build_output ./bazel-bin/${java_pkg}/libhello-lib.jar ${java_pkg}:hello-lib + assert_build_output ./bazel-bin/${java_pkg}/libcustom-greeting.jar ${java_pkg}:custom-greeting + assert_build_output ./bazel-bin/${java_pkg}/hello-world ${java_pkg}:hello-world + assert_build_output ./bazel-bin/${java_pkg}/hello-resources ${java_pkg}:hello-resources + assert_binary_run_from_subdir "bazel-bin/${java_pkg}/hello-world foo" "Hello foo" +} + +function test_java_test() { + setup_javatest_support + local java_native_tests=//examples/java-native/src/test/java/com/example/myproject + local java_native_main=//examples/java-native/src/main/java/com/example/myproject + + assert_build "-- //examples/java-native/... -${java_native_main}:hello-error-prone" + assert_build_fails "${java_native_main}:hello-error-prone" \ + "Did you mean 'result = b == -1;'?" + assert_test_ok "${java_native_tests}:hello" + assert_test_ok "${java_native_tests}:custom" + assert_test_fails "${java_native_tests}:fail" + assert_test_fails "${java_native_tests}:resource-fail" +} + +run_suite "examples on Windows" + diff --git a/src/test/shell/bazel/testenv.sh b/src/test/shell/bazel/testenv.sh index b38251f366..e66e5fca4b 100755 --- a/src/test/shell/bazel/testenv.sh +++ b/src/test/shell/bazel/testenv.sh @@ -118,9 +118,16 @@ case "${PLATFORM}" in fi ;; esac -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" + +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() { |