Skip to content

Commit 11d3b32

Browse files
authored
Fix silently broken test_version.sh tests (#1716)
Fixes silently broken tests depending on `test_version/test_reporter` and adds an assertion to avoid future silent breakages. Part of #1482 and #1652. - Moves `test_version/version_specific_tests_dir/scala_repositories.bzl` to `test_version`. - Updates `test_version.sh` to copy this file into test repos generated from both `version_specific_tests_dir` and `test_reporter`. - Updates `compilation_should_fail` to break if the `bazel build` output doesn't contain the expected `ErrorFile.scala` error. The affected test cases expect their underlying builds to fail because of errors in `test_version/test_reporter/ErrorFile.scala`. Failing Scala 2.x build output should contain: ```txt ErrorFile.scala:6: ')' expected but '}' found ``` Failing Scala 3.x build output should contain: ```txt -- [E040] Syntax Error: ErrorFile.scala:6:2 ------------------------------------ 6 | } | ^ | ')' expected, but '}' found ``` Using `RULES_SCALA_TEST_ONLY` to select an affected test case revealed that the underlying build actually failed because Bazel couldn't find `//:scrooge_repositories.bzl`: ```txt $ RULES_SCALA_TEST_ONLY="test_reporter 2.12.20 //:diagnostics_reporter_toolchain" \ ./test_version.sh running test test_reporter 2.12.20 //:diagnostics_reporter_toolchain Starting local Bazel server and connecting to it... Computing main repo mapping: ERROR: Error computing the main repository mapping: cannot load '//:scrooge_repositories.bzl': no such file $ echo $? 0 ```
1 parent bfc9495 commit 11d3b32

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

test_version.sh

+19-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,26 @@ compilation_should_fail() {
1616
# runs the tests locally
1717
set +e
1818
TEST_ARG=$@
19-
DUMMY=$(bazel $TEST_ARG)
19+
OUTPUT="$(bazel $TEST_ARG 2>&1)"
2020
RESPONSE_CODE=$?
21+
set -e
22+
2123
if [ $RESPONSE_CODE -eq 0 ]; then
2224
echo -e "${RED} \"bazel $TEST_ARG\" should have failed but passed. $NC"
25+
echo "$OUTPUT"
2326
return -1
27+
fi
28+
29+
local expected_error_pattern=(
30+
"ErrorFile\.scala:6:[[:print:][:space:]]*'[)]' expected,? but '[}]' found"
31+
)
32+
33+
if [[ ! "$OUTPUT" =~ $expected_error_pattern ]]; then
34+
echo -e "${RED} \"bazel $*\" failure should have matched:"
35+
echo -e " ${expected_error_pattern}"
36+
echo -e " got:${NC}"
37+
echo "$OUTPUT"
38+
return 1
2439
else
2540
return 0
2641
fi
@@ -45,12 +60,12 @@ run_in_test_repo() {
4560

4661
if [[ -n "$TWITTER_SCROOGE_VERSION" ]]; then
4762
local version_param="version = \"$TWITTER_SCROOGE_VERSION\""
48-
scrooge_ws="$version_param"
63+
scrooge_ws="$version_param\\n"
4964
fi
5065

51-
sed -e "s%\${twitter_scrooge_repositories}%${scrooge_ws}\n%" \
66+
sed -e "s%\${twitter_scrooge_repositories}%${scrooge_ws}%" \
5267
WORKSPACE.template >> $NEW_TEST_DIR/WORKSPACE
53-
cp ../.bazel{rc,version} $NEW_TEST_DIR/
68+
cp ../.bazel{rc,version} scrooge_repositories.bzl $NEW_TEST_DIR/
5469

5570
cd $NEW_TEST_DIR
5671

0 commit comments

Comments
 (0)