diff options
-rw-r--r-- | src/test/shell/integration/BUILD | 6 | ||||
-rwxr-xr-x | src/test/shell/integration/output_filter_test.sh | 246 | ||||
-rw-r--r-- | tools/bash/runfiles/runfiles.bash | 1 |
3 files changed, 151 insertions, 102 deletions
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD index 8b4c23f519..b6657b8b89 100644 --- a/src/test/shell/integration/BUILD +++ b/src/test/shell/integration/BUILD @@ -147,8 +147,10 @@ sh_test( name = "output_filter_test", size = "large", srcs = ["output_filter_test.sh"], - data = [":test-deps"], - tags = ["no_windows"], + data = [ + ":test-deps", + "@bazel_tools//tools/bash/runfiles", + ], ) sh_test( diff --git a/src/test/shell/integration/output_filter_test.sh b/src/test/shell/integration/output_filter_test.sh index 3d15b7f654..7d814a2eba 100755 --- a/src/test/shell/integration/output_filter_test.sh +++ b/src/test/shell/integration/output_filter_test.sh @@ -17,60 +17,105 @@ # output_filter_test.sh: a couple of end to end tests for the warning # filter functionality. -# Load the test setup defined in the parent directory -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "${CURRENT_DIR}/../integration_test_setup.sh" \ +# --- begin runfiles.bash initialization --- +# Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). +set -euo pipefail +if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ -f "$0.runfiles_manifest" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" + elif [[ -f "$0.runfiles/MANIFEST" ]]; then + export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" + elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + export RUNFILES_DIR="$0.runfiles" + fi +fi +if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then + source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" +elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ + "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" +else + echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" + exit 1 +fi +# --- end runfiles.bash initialization --- + +source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } +case "$(uname -s | tr [:upper:] [:lower:])" in +msys*|mingw*|cygwin*) + declare -r is_windows=true + ;; +*) + declare -r is_windows=false + ;; +esac + +if "$is_windows"; then + export MSYS_NO_PATHCONV=1 + export MSYS2_ARG_CONV_EXCL="*" +fi + function test_output_filter_cc() { # "test warning filter for C compilation" - - mkdir -p cc/main - cat > cc/main/BUILD <<EOF -cc_library(name='cc', - srcs=['main.c'], - nocopts='-Werror') + local -r pkg=$FUNCNAME + + if is_windows; then + local -r copts=\"/W3\" + else + local -r copts="" + fi + + mkdir -p $pkg/cc/main + cat > $pkg/cc/main/BUILD <<EOF +cc_library( + name = "cc", + srcs = ["main.c"], + copts = [$copts], + nocopts = "-Werror", +) EOF - cat >cc/main/main.c <<EOF + cat >$pkg/cc/main/main.c <<EOF #include <stdio.h> int main(void) { -#warning("Through me you pass into the city of woe:") -#warning("Through me you pass into eternal pain:") -#warning("Through me among the people lost for aye.") +#ifdef COMPILER_MSVC + // MSVC does not support the #warning directive. + int unused_variable__triggers_a_warning; // triggers C4101 +#else // not COMPILER_MSVC + // GCC/Clang support #warning. +#warning("triggers_a_warning") +#endif // COMPILER_MSVC printf("%s", "Hello, World!\n"); + return 0; } EOF - bazel clean - bazel build cc/main:cc 2> stderr.txt - cat stderr.txt - grep "into eternal pain" stderr.txt || \ - fail "No warning from C compilation" - - bazel clean - bazel build --output_filter="dummy" cc/main:cc &> stderr.txt - grep "into eternal pain" stderr.txt && \ - fail "Warning given by C compilation although they are disabled" + bazel build --output_filter="dummy" $pkg/cc/main:cc >&"$TEST_log" || fail "build failed" + expect_not_log "triggers_a_warning" - true + echo "/* adding a comment forces recompilation */" >> $pkg/cc/main/main.c + bazel build $pkg/cc/main:cc >&"$TEST_log" || fail "build failed" + expect_log "triggers_a_warning" } function test_output_filter_java() { # "test warning filter for Java compilation" + local -r pkg=$FUNCNAME - mkdir -p java/main - cat >java/main/BUILD <<EOF + mkdir -p $pkg/java/main + cat >$pkg/java/main/BUILD <<EOF java_binary(name = 'main', - deps = ['//java/hello_library'], + deps = ['//$pkg/java/hello_library'], srcs = ['Main.java'], javacopts = ['-Xlint:deprecation'], main_class = 'main.Main') EOF - cat >java/main/Main.java <<EOF + cat >$pkg/java/main/Main.java <<EOF package main; import hello_library.HelloLibrary; public class Main { @@ -81,15 +126,15 @@ public class Main { } EOF - mkdir -p java/hello_library - cat >java/hello_library/BUILD <<EOF + mkdir -p $pkg/java/hello_library + cat >$pkg/java/hello_library/BUILD <<EOF package(default_visibility=['//visibility:public']) java_library(name = 'hello_library', srcs = ['HelloLibrary.java'], javacopts = ['-Xlint:deprecation']); EOF - cat >java/hello_library/HelloLibrary.java <<EOF + cat >$pkg/java/hello_library/HelloLibrary.java <<EOF package hello_library; public class HelloLibrary { /** @deprecated */ @@ -100,49 +145,53 @@ public class HelloLibrary { } EOF - bazel clean # check that we do get a deprecation warning - bazel build //java/main:main 2>stderr.txt || fail "build failed" - grep -q "has been deprecated" stderr.txt || fail "no deprecation warning" + bazel build //$pkg/java/main:main >&"$TEST_log" || fail "build failed" + expect_log "has been deprecated" # check that we do get a deprecation warning if we select the target - bazel clean - bazel build --output_filter=java/main //java/main:main 2>stderr.txt || fail "build failed" - grep -q "has been deprecated" stderr.txt || fail "no deprecation warning" - # check that we do not get a deprecation warning if we select another target - bazel clean - bazel build --output_filter=java/hello_library //java/main:main 2>stderr.txt || fail "build failed" - grep -q "has been deprecated" stderr.txt && fail "deprecation warning" + echo "// add comment to trigger recompilation" >> $pkg/java/hello_library/HelloLibrary.java + echo "// add comment to trigger recompilation" >> $pkg/java/main/Main.java + bazel build --output_filter=$pkg/java/main //$pkg/java/main:main >&"$TEST_log" \ + || fail "build failed" + expect_log "has been deprecated" - true + # check that we do not get a deprecation warning if we select another target + echo "// add another comment" >> $pkg/java/hello_library/HelloLibrary.java + echo "// add another comment" >> $pkg/java/main/Main.java + bazel build --output_filter=$pkg/java/hello_library //$pkg/java/main:main >&"$TEST_log" \ + || fail "build failed" + expect_not_log "has been deprecated" } function test_test_output_printed() { # "test that test output is printed if warnings are disabled" + local -r pkg=$FUNCNAME - mkdir -p foo/bar - cat >foo/bar/BUILD <<EOF + mkdir -p $pkg/foo/bar + cat >$pkg/foo/bar/BUILD <<EOF sh_test(name='test', srcs=['test.sh']) EOF - cat >foo/bar/test.sh <<EOF + cat >$pkg/foo/bar/test.sh <<EOF #!/bin/sh exit 0 EOF - chmod +x foo/bar/test.sh + chmod +x $pkg/foo/bar/test.sh # TODO(b/37617303): make tests UI-independent - bazel test --noexperimental_ui --output_filter="dummy" foo/bar:test 2> stderr.txt - grep "PASS: //foo/bar:test" stderr.txt || fail "no PASSED message" + bazel test --noexperimental_ui --output_filter="dummy" $pkg/foo/bar:test >&"$TEST_log" || fail + expect_log "PASS: //$pkg/foo/bar:test" } function test_output_filter_build() { # "test output filter for BUILD files" + local -r pkg=$FUNCNAME - mkdir -p foo/bar - cat >foo/bar/BUILD <<EOF + mkdir -p $pkg/foo/bar + cat >$pkg/foo/bar/BUILD <<EOF # Trigger sh_binary in deps of sh_binary warning. sh_binary(name='red', srcs=['tomato.skin']) @@ -151,38 +200,37 @@ sh_binary(name='tomato', deps=[':red']) EOF - touch foo/bar/tomato.{skin,pulp} - chmod +x foo/bar/tomato.{skin,pulp} + touch $pkg/foo/bar/tomato.{skin,pulp} + chmod +x $pkg/foo/bar/tomato.{skin,pulp} - bazel clean # check that we do get a deprecation warning - bazel build //foo/bar:tomato 2>stderr.txt || fail "build failed" - grep -q "is unexpected here" stderr.txt \ - || fail "no warning" + bazel build //$pkg/foo/bar:tomato >&"$TEST_log" || fail "build failed" + expect_log "is unexpected here" + # check that we do get a deprecation warning if we select the target - bazel clean - bazel build --output_filter=foo/bar:tomato //foo/bar:tomato 2>stderr.txt \ + + echo "# add comment to trigger rebuild" >> $pkg/foo/bar/tomato.skin + echo "# add comment to trigger rebuild" >> $pkg/foo/bar/tomato.pulp + bazel build --output_filter=$pkg/foo/bar:tomato //$pkg/foo/bar:tomato >&"$TEST_log" \ || fail "build failed" - grep -q "is unexpected here" stderr.txt \ - || fail "no warning" + expect_log "is unexpected here" # check that we do not get a deprecation warning if we select another target - bazel clean - bazel build --output_filter=foo/bar/:red //foo/bar:tomato 2>stderr.txt \ + echo "# add another comment" >> $pkg/foo/bar/tomato.skin + echo "# add another comment" >> $pkg/foo/bar/tomato.pulp + bazel build --output_filter=$pkg/foo/bar/:red //$pkg/foo/bar:tomato >&"$TEST_log" \ || fail "build failed" - grep -q "is unexpected here" stderr.txt \ - && fail "warning" - - true + expect_not_log "is unexpected here" } function test_output_filter_build_hostattribute() { # "test that output filter also applies to host attributes" + local -r pkg=$FUNCNAME # What do you get in bars? - mkdir -p bar + mkdir -p $pkg/bar - cat >bar/BUILD <<EOF + cat >$pkg/bar/BUILD <<EOF # Trigger sh_binary in deps of sh_binary warning. sh_binary(name='red', srcs=['tomato.skin']) @@ -198,49 +246,46 @@ genrule(name='bloody_mary', cmd='cp \$< \$@') EOF - touch bar/tomato.{skin,pulp} - chmod +x bar/tomato.{skin,pulp} - echo Moskowskaya > bar/vodka + touch $pkg/bar/tomato.{skin,pulp} + chmod +x $pkg/bar/tomato.{skin,pulp} + echo Moskowskaya > $pkg/bar/vodka # Check that we do get a deprecation warning - bazel clean - bazel build //bar:bloody_mary 2>stderr1.txt || fail "build failed" - grep -q "is unexpected here" stderr1.txt \ - || fail "no warning" + bazel build //$pkg/bar:bloody_mary >&"$TEST_log" || fail "build failed" + expect_log "is unexpected here" # Check that the warning is disabled if we do not want to see it - bazel clean - bazel build //bar:bloody_mary --output_filter='nothing' 2>stderr2.txt \ - || fail "build failed" - grep -q "is unexpected here" stderr2.txt \ - && fail "warning is not disabled" + echo "# add comment to trigger rebuild" >> $pkg/bar/tomato.skin + echo "# add comment to trigger rebuild" >> $pkg/bar/tomato.pulp - true + bazel build //$pkg/bar:bloody_mary --output_filter='nothing' >&"$TEST_log" \ + || fail "build failed" + expect_not_log "is unexpected here" } function test_output_filter_does_not_apply_to_test_output() { - mkdir -p geflugel - cat >geflugel/BUILD <<EOF + local -r pkg=$FUNCNAME + mkdir -p $pkg/geflugel + cat >$pkg/geflugel/BUILD <<EOF sh_test(name='mockingbird', srcs=['mockingbird.sh']) sh_test(name='hummingbird', srcs=['hummingbird.sh']) EOF - cat >geflugel/mockingbird.sh <<EOF -#!/bin/sh + cat >$pkg/geflugel/mockingbird.sh <<EOF +#!$(which bash) echo "To kill -9 a mockingbird" exit 1 EOF - cat >geflugel/hummingbird.sh <<EOF -#!/bin/sh + cat >$pkg/geflugel/hummingbird.sh <<EOF +#!$(which bash) echo "To kill -9 a hummingbird" exit 1 EOF - chmod +x geflugel/*.sh + chmod +x $pkg/geflugel/*.sh - bazel clean - bazel test //geflugel:all --test_output=errors --output_filter=mocking &> $TEST_log \ + bazel test //$pkg/geflugel:all --test_output=errors --output_filter=mocking &> $TEST_log \ && fail "expected tests to fail" expect_log "To kill -9 a mockingbird" @@ -249,26 +294,27 @@ EOF # TODO(mstaib): enable test after deprecation warnings work in bazel function disabled_test_filters_deprecated_targets() { + local -r pkg=$FUNCNAME init_test "test that deprecated target warnings are filtered" - mkdir -p relativity ether - cat > relativity/BUILD <<EOF -cc_binary(name = 'relativity', srcs = ['relativity.cc'], deps = ['//ether']) + mkdir -p $pkg/{relativity,ether} + cat > $pkg/relativity/BUILD <<EOF +cc_binary(name = 'relativity', srcs = ['relativity.cc'], deps = ['//$pkg/ether']) EOF - cat > ether/BUILD <<EOF + cat > $pkg/ether/BUILD <<EOF cc_library(name = 'ether', srcs = ['ether.cc'], deprecation = 'Disproven', visibility = ['//visibility:public']) EOF - bazel build --nobuild //relativity &> $TEST_log || fail "Expected success" - expect_log_once "WARNING:.*target '//relativity:relativity' depends on \ -deprecated target '//ether:ether': Disproven." + bazel build --nobuild //$pkg/relativity &> $TEST_log || fail "Expected success" + expect_log_once "WARNING:.*target '//$pkg/relativity:relativity' depends on \ +deprecated target '//$pkg/ether:ether': Disproven." bazel build --nobuild --output_filter="^//pizza" \ - //relativity &> $TEST_log || fail "Expected success" - expect_not_log "WARNING:.*target '//relativity:relativity' depends on \ -deprecated target '//ether:ether': Disproven." + //$pkg/relativity &> $TEST_log || fail "Expected success" + expect_not_log "WARNING:.*target '//$pkg/relativity:relativity' depends on \ +deprecated target '//$pkg/ether:ether': Disproven." } run_suite "Warning Filter tests" diff --git a/tools/bash/runfiles/runfiles.bash b/tools/bash/runfiles/runfiles.bash index fe29f4eee6..69bb532029 100644 --- a/tools/bash/runfiles/runfiles.bash +++ b/tools/bash/runfiles/runfiles.bash @@ -36,6 +36,7 @@ # Insert the following code snippet to the top of your main script: # # # --- begin runfiles.bash initialization --- +# # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). # set -euo pipefail # if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then # if [[ -f "$0.runfiles_manifest" ]]; then |