diff --git a/README.md b/README.md index 41161d3..6756747 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Bazel implementations to test a build error. There's a situation where a developer wants to test if particular code doesn't compile. However, when using ordinary testing rules, such as `cc_test`, `bazel test` results in an error if the test code doesn't compile. -`rules_build_error` is the repository to address such a problem. It provides some implementations to test the compilation error for each programming language. When the code written in a particular **does** compile, `bazel build` should fail for the associated target. +`rules_build_error` is the repository to address such a problem. It provides some implementations to test the compilation error for each programming language. When the code written in a particular programming language **does** compile, `bazel build` should fail for the associated target. ## Usage diff --git a/execute_tests.sh b/execute_tests.sh index a6d5d7a..2960e01 100755 --- a/execute_tests.sh +++ b/execute_tests.sh @@ -4,6 +4,16 @@ set -euo pipefail +# Bazel executable with some arguments +BAZEL_EXECUTABLE=( + "env" + "-i" + BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 + "HOME=${HOME}" + "PATH=${PATH}" + bazelisk +) + check_bazel_build_error() { # Check bazel build error for a particular target # @@ -12,11 +22,11 @@ check_bazel_build_error() { local label label=$1 - # Before executing `bazelisk build`, check if the target exists with `bazelisk query` - bazelisk query "${label}" + # Before executing `bazel build`, check if the target exists with `bazel query` + "${BAZEL_EXECUTABLE[@]}" query "${label}" # Check build error - if bazelisk build "${label}"; then + if "${BAZEL_EXECUTABLE[@]}" build "${label}"; then echo "Target '${label}' must fail to build, but succeeded" >&2 exit 1 else @@ -24,10 +34,10 @@ check_bazel_build_error() { fi } -echo "Executing the test cases which should pass straightforward 'bazelisk test'" -bazelisk test //... +echo "Executing the test cases which should succeed in straightforward 'bazel test'" +"${BAZEL_EXECUTABLE[@]}" test //... -echo "Executing the test cases which should fail at 'bazelisk build'" +echo "Executing the test cases which should fail at 'bazel build'" check_bazel_build_error //tests/cc/cpp_successful_build:plain check_bazel_build_error //tests/cc/cpp_successful_build:with_basic_regex_matcher check_bazel_build_error //tests/cc/cpp_successful_build:with_extended_regex_matcher