Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Fix test failures when running directly instead of via script (#106)
Browse files Browse the repository at this point in the history
Fixes #105 by 1) enabling toolchains in the workspace .bazelrc, and 2) making the test harness filter out runfiles added by the autodetecting toolchain.

Previously, the tests worked when run from run_tests.sh but failed in `bazel test //...`. This caused travis to pass but buildkite to fail.

Also fixed a typo that caused run_test.sh to fail on some versions of bash.
  • Loading branch information
brandjon committed May 13, 2019
1 parent 9c7b3e7 commit 5b0f501
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# //tests:version_test asserts on the Python interpreter version, so enable
# toolchains to ensure we get the right one (avoid bazelbuild/bazel#4815).
build --incompatible_use_python_toolchains
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function die {
# that we are compiling uses PY3.
function set_toolchain_hook {
pyver=$1
if [ $pyver == "PY3"]; then
if [ $pyver == "PY3" ]; then
py2_path="$PYTHON2"
py3_path="$2"
else
Expand Down
6 changes: 5 additions & 1 deletion tests/test_harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ TMP_EXECUTABLE="$TEST_TMPDIR"/$(basename "$EXECUTABLE")

# Compare list of files in zipfile with expected list
if [ "$PAR" -eq 1 ]; then
# Exclude runfiles of the autodetecting toolchain. The test is still brittle
# with respect to runfiles introduced by any other toolchain. When tests are
# invoked by run_tests.sh, a custom toolchain with no runfiles is used.
diff \
<(unzip -l -q -q "$EXECUTABLE" | awk '{print $NF}') \
<(unzip -l -q -q "$EXECUTABLE" | awk '{print $NF}' \
| grep -v 'bazel_tools/tools/python/py.wrapper\.sh') \
"$FILELIST" \
|| die 'FATAL: zipfile contents do not match expected'
fi
Expand Down

0 comments on commit 5b0f501

Please sign in to comment.