-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle incorrect Scalac options and prevent printing ScalacWorker sta…
…cktraces (#1606) * Improve handling of invalid settings passed to Scala compiler. Throw known exception instead of allowing to None.get (Scala3) or NullPointerException (Scala2) * Prevent printing stack trace of ScalacInvoker on known compilation errors * Run reporter.flush in Scala3 * Restore previous error messages * Addi tests to ensure corect error message and no stack traces are shown * Remove unused code from test_invalid_scalacopts.sh * Print exception message only once. Previously printed in both e.getMessage and e.printStackTrace * Ident with spaces instead of tabs
- Loading branch information
1 parent
ac4181c
commit 5a2453e
Showing
8 changed files
with
91 additions
and
9 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
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
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,36 @@ | ||
# 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}") | ||
|
||
test_logs_contains() { | ||
scalaVersion=$1 | ||
expected=$2 | ||
|
||
bazel build \ | ||
--repo_env=SCALA_VERSION=${scalaVersion} \ | ||
//test_expect_failure/scalacopts_invalid:empty \ | ||
2>&1 | grep "$expected" | ||
} | ||
|
||
test_logs_not_contains() { | ||
scalaVersion=$1 | ||
expected=$2 | ||
|
||
bazel build \ | ||
--repo_env=SCALA_VERSION=${scalaVersion} \ | ||
//test_expect_failure/scalacopts_invalid:empty \ | ||
2>&1 | grep -v "$expected" | ||
} | ||
|
||
for scalaVersion in 2.12.19 2.13.14 3.3.3; do | ||
if [[ "$scalaVersion" == 3.* ]]; then | ||
$runner test_logs_contains $scalaVersion "not-existing is not a valid choice for -source" | ||
else | ||
$runner test_logs_contains $scalaVersion "bad option: '-source:not-existing'" | ||
fi | ||
$runner test_logs_contains $scalaVersion 'Failed to invoke Scala compiler, ensure passed options are valid' | ||
$runner test_logs_not_contains $scalaVersion 'at io.bazel.rulesscala.scalac.ScalacWorker.main' | ||
done |
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,7 @@ | ||
load("//scala:scala.bzl", "scala_library") | ||
|
||
scala_library( | ||
name = "empty", | ||
srcs = ["Empty.scala"], | ||
scalacopts = ["-source:not-existing"], | ||
) |
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 @@ | ||
package test_expect_failure.scalacopts_invalid | ||
|
||
class Empty |
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