-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Automatically add -release option when needed
Previously, if we compiled with a Bloop running an newer JDK we would not see any errors even when using methods belonging to a newer JDK. Now, we automatically add -release flag, which makes sure that we will fail any compilation that should not pass with an older JDK (if specified in configuration)
- Loading branch information
Showing
4 changed files
with
143 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package bloop | ||
|
||
import bloop.cli.ExitStatus | ||
import bloop.config.Config | ||
import bloop.logging.RecordingLogger | ||
import bloop.util.TestProject | ||
import bloop.util.TestUtil | ||
|
||
object JavaVersionSpec extends bloop.testing.BaseSuite { | ||
|
||
private val jvmManager = coursierapi.JvmManager.create() | ||
|
||
def checkFlag(scalacOpts: List[String], jdkVersion: String = "8") = { | ||
val javaHome = jvmManager.get(jdkVersion).toPath() | ||
val jvmConfig = Some(Config.JvmConfig(Some(javaHome), Nil)) | ||
TestUtil.withinWorkspace { workspace => | ||
val sources = List( | ||
"""/main/scala/Foo.scala | ||
|class Foo{ | ||
| val output = "La ".repeat(2) + "Land"; | ||
|} | ||
""".stripMargin | ||
) | ||
|
||
val logger = new RecordingLogger(ansiCodesSupported = false) | ||
val `A` = | ||
TestProject(workspace, "a", sources, jvmConfig = jvmConfig, scalacOptions = scalacOpts) | ||
val projects = List(`A`) | ||
val state = loadState(workspace, projects, logger) | ||
val compiledState = state.compile(`A`) | ||
if (jdkVersion == "8") { | ||
assertExitStatus(compiledState, ExitStatus.CompilationError) | ||
val targetFoo = TestUtil.universalPath("a/src/main/scala/Foo.scala") | ||
assertNoDiff( | ||
logger.renderErrors(), | ||
s"""|[E1] $targetFoo:2:22 | ||
| value repeat is not a member of String | ||
| L2: val output = "La ".repeat(2) + "Land"; | ||
| ^ | ||
|a/src/main/scala/Foo.scala: L2 [E1] | ||
|Failed to compile 'a' | ||
|""".stripMargin | ||
) | ||
} else { | ||
assertExitStatus(compiledState, ExitStatus.Ok) | ||
} | ||
} | ||
} | ||
|
||
test("flag-is-added-correctly") { | ||
checkFlag(Nil) | ||
} | ||
|
||
test("flag-is-not-added-correctly") { | ||
checkFlag(List("-release", "8")) | ||
checkFlag(List("-release:8")) | ||
} | ||
|
||
test("compiles-with-11") { | ||
checkFlag(Nil, jdkVersion = "11") | ||
} | ||
|
||
test("compiles-with-17") { | ||
checkFlag(Nil, jdkVersion = "17") | ||
} | ||
} |