-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catch macro expansion exceptions in ScalacWorker (#1489)
* Catch macro expansion exceptions in ScalacWorker * E2E test for persistent worker * Add new test to test_rules_scala.sh
- Loading branch information
1 parent
068122a
commit 394c0aa
Showing
6 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# shellcheck source=./test_runner.sh | ||
|
||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
. "${dir}"/test_runner.sh | ||
. "${dir}"/test_helper.sh | ||
runner=$(get_test_runner "${1:-local}") | ||
|
||
PERSISTENT_WORKER_FLAGS="--strategy=Scalac=worker --worker_sandboxing" | ||
|
||
test_persistent_worker_success() { | ||
# shellcheck disable=SC2086 | ||
bazel build //test:ScalaBinary $PERSISTENT_WORKER_FLAGS | ||
} | ||
|
||
test_persistent_worker_failure() { | ||
action_should_fail "build //test_expect_failure/diagnostics_reporter:error_file $PERSISTENT_WORKER_FLAGS" | ||
} | ||
|
||
test_persistent_worker_handles_exception_in_macro_invocation() { | ||
command="bazel build //test_expect_failure/scalac_exceptions:bad_macro_invocation $PERSISTENT_WORKER_FLAGS" | ||
output=$(${command} 2>&1) | ||
! (echo "$output" | grep -q -- "---8<---8<---") && (echo "$output" | grep -q "Build failure during macro expansion") | ||
|
||
RESPONSE_CODE=$? | ||
if [ $RESPONSE_CODE -ne 0 ]; then | ||
echo -e "${RED} Scalac persistent worker does not handle uncaught error in macro expansion. $NC" | ||
exit 1 | ||
fi | ||
} | ||
|
||
$runner test_persistent_worker_success | ||
$runner test_persistent_worker_failure | ||
$runner test_persistent_worker_handles_exception_in_macro_invocation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//scala:scala.bzl", "scala_library", "scala_macro_library") | ||
|
||
scala_macro_library( | ||
name = "bad_macro", | ||
srcs = ["BadMacro.scala"], | ||
) | ||
|
||
scala_library( | ||
name = "bad_macro_invocation", | ||
srcs = ["BadMacroInvocation.scala"], | ||
deps = [":bad_macro"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import scala.language.experimental.macros | ||
|
||
object BadMacro { | ||
def badMacro(): Unit = macro badMacroImpl | ||
|
||
def badMacroImpl(c: scala.reflect.macros.blackbox.Context)(): c.Tree = { | ||
throw new NoSuchMethodError() | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test_expect_failure/scalac_exceptions/BadMacroInvocation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object BadMacroInvocation { | ||
BadMacro.badMacro() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters