Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testing issues on JDK 11 #1005

Merged
merged 7 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ matrix:
"frontend/it:run" \
"gradleBloop212/test" \
"docs/run"
TEST_BLOOP_JDK11:
- bin/sbt-ci.sh \
"show version" \
"benchmarks/compile" \
"jsonConfig210/test" \
"jsonConfig211/test" \
"jsonConfig212/test" \
"millBloop/compile" \
"mavenBloop/compile" \
"sbtBloop013/publishLocal" \
"sbtBloop10/publishLocal" \
"frontend/testOnly bloop.ScalaVersionsSpec" \
"backend/test" \
"jsBridge06/test" \
"jsBridge10/test" \
"jsBridge06/publishLocal" \
"jsBridge10/publishLocal" \
"frontend/testOnly -bloop.ScalaVersionsSpec"

RUN_COMMUNITY_BUILD_EXTRA:
- bin/sbt-ci.sh \
Expand Down Expand Up @@ -63,6 +81,7 @@ matrix:
OPS:
- basic
- community-build
- jdk11
- extra
clone:
git:
Expand Down Expand Up @@ -128,6 +147,24 @@ pipeline:
- ${TEST_BLOOP}
- . bin/check-good-practices.sh # Check that good practices in the repo hold

build-jdk11:
image: eed3si9n/scala-docs:1.6-M2
group: build
when:
ref: [ refs/heads/master, refs/tags/*, refs/pull/*/head ]
matrix:
OS: linux
OPS: jdk11
commands:
- export JAVA_HOME="/usr/lib/jvm/jdk11/bin"
- java -version
- export DRONE_DIR="/drone"
- git log --oneline --graph | head -n 20
- . bin/set-up-community-build-infra.sh # Source it because it exports variables
- . bin/detect-community-build.sh # Source it because it exports variables
- ${TEST_BLOOP_JDK11}
- . bin/check-good-practices.sh # Check that good practices in the repo hold

run_benchmarks_scripted:
image: scalacenter/scala-docs:1.4
group: build
Expand Down
2 changes: 1 addition & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-XX:ReservedCodeCacheSize=256m
-XX:ReservedCodeCacheSize=512m
12 changes: 10 additions & 2 deletions frontend/src/main/scala/bloop/testing/TestInternals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import scala.util.control.NonFatal
object TestInternals {
private final val sbtOrg = "org.scala-sbt"
private final val testAgentId = "test-agent"
private final val testAgentVersion = "1.0.4"
private final val testAgentVersion = "1.2.8"

private implicit val logContext: DebugFilter = DebugFilter.Test

Expand All @@ -45,7 +45,15 @@ object TestInternals {

lazy val filteredLoader = {
val filter = new IncludePackagesFilter(
Set("java.", "javax.", "sun.", "sbt.testing.", "org.scalatools.testing.", "org.xml.sax.")
Set(
"jdk.",
"java.",
"javax.",
"sun.",
"sbt.testing.",
"org.scalatools.testing.",
"org.xml.sax."
)
)
new FilteredLoader(getClass.getClassLoader, filter)
}
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/test/resources/scala-seed-project/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Dependencies._

bloopExportJarClassifiers in Global := Some(Set("sources"))
bloopConfigDir in Global := baseDirectory.value / "bloop-config"

ThisBuild / scalaVersion := "2.12.9"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.example"
ThisBuild / organizationName := "example"

lazy val root = (project in file("."))
.settings(
name := "Scala Seed Project",
libraryDependencies += scalaTest % Test,
fork in Test := true
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sbt._

object Dependencies {
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.2.8
30 changes: 30 additions & 0 deletions frontend/src/test/resources/scala-seed-project/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
val typesafeConfig = "com.typesafe" % "config" % "1.3.2"
val metaconfigCore = "com.geirsson" %% "metaconfig-core" % "0.6.0"
val metaconfigConfig = "com.geirsson" %% "metaconfig-typesafe-config" % "0.6.0"
val metaconfigDocs = "com.geirsson" %% "metaconfig-docs" % "0.6.0"
val circeDerivation = "io.circe" %% "circe-derivation" % "0.9.0-M3"

// Let's add our sbt plugin to the sbt too ;)
unmanagedSourceDirectories in Compile ++= {
val baseDir =
baseDirectory.value.getParentFile.getParentFile.getParentFile.getParentFile.getParentFile.getParentFile
val integrationsMainDir = baseDir / "integrations"
if (!integrationsMainDir.exists()) Nil
else {
val pluginMainDir = integrationsMainDir / "sbt-bloop" / "src" / "main"
List(
baseDir / "config" / "src" / "main" / "scala",
baseDir / "config" / "src" / "main" / "scala-2.11-12",
pluginMainDir / "scala",
pluginMainDir / s"scala-sbt-${sbt.Keys.sbtBinaryVersion.value}"
)
}
}

libraryDependencies ++= List(
typesafeConfig,
metaconfigCore,
metaconfigDocs,
metaconfigConfig,
circeDerivation
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

object Hello extends Greeting with App {
println(greeting)
}

trait Greeting {
lazy val greeting: String = "hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package example

import org.scalatest._

class HelloSpec extends FlatSpec with Matchers {
"The Hello object" should "say hello" in {
Hello.greeting shouldEqual "hello"
}
}
2 changes: 1 addition & 1 deletion frontend/src/test/scala/bloop/BuildPipeliningSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object BuildPipeliningSpec extends bloop.testing.BaseSuite {
}
}

test("compile simple build using Scala 2.10 (without pipelining)") {
testOnlyOnJava8("compile simple build using Scala 2.10 (without pipelining)") {
TestUtil.withinWorkspace { workspace =>
object Sources {
val `A.scala` =
Expand Down
108 changes: 60 additions & 48 deletions frontend/src/test/scala/bloop/RunSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,81 +120,93 @@ class RunSpec {

@Test
def runCanSeeCompileResources: Unit = {
val mainClassName = "hello.AppWithResources"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), Some(mainClassName), args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Resources were found")))
TestUtil.runOnlyOnJava8 {
val mainClassName = "hello.AppWithResources"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), Some(mainClassName), args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Resources were found")))
}
}
}

@Test
def runIncludesTransitiveResourcesInAggregatedProjects: Unit = {
val target = "cross-test-build-0-6"
val state = loadTestProject("cross-test-build-0.6")
state.build.getProjectFor(target) match {
case Some(rootWithAggregation) =>
val dag = state.build.getDagFor(rootWithAggregation)
// Create dependent resources so that they appear in the full dependency classpath
val dependentResources = Dag.dfs(dag).flatMap(_.resources)
dependentResources.foreach { resource =>
if (resource.exists) ()
else Files.createDirectories(resource.underlying)
}
TestUtil.runOnlyOnJava8 {
val target = "cross-test-build-0-6"
val state = loadTestProject("cross-test-build-0.6")
state.build.getProjectFor(target) match {
case Some(rootWithAggregation) =>
val dag = state.build.getDagFor(rootWithAggregation)
// Create dependent resources so that they appear in the full dependency classpath
val dependentResources = Dag.dfs(dag).flatMap(_.resources)
dependentResources.foreach { resource =>
if (resource.exists) ()
else Files.createDirectories(resource.underlying)
}

val fullClasspath = rootWithAggregation.fullClasspath(dag, state.client).toList
Assert.assertFalse(dependentResources.isEmpty)
dependentResources.foreach { r =>
Assert.assertTrue(s"Missing $r in $fullClasspath", fullClasspath.contains(r))
}
case None => Assert.fail(s"Missing root $target")
val fullClasspath = rootWithAggregation.fullClasspath(dag, state.client).toList
Assert.assertFalse(dependentResources.isEmpty)
dependentResources.foreach { r =>
Assert.assertTrue(s"Missing $r in $fullClasspath", fullClasspath.contains(r))
}
case None => Assert.fail(s"Missing root $target")
}
}
}

@Test
def canRunMainFromSourceDependency: Unit = {
val mainClassName = "hello.App"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project-test"), Some(mainClassName), args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Hello, world!")))
TestUtil.runOnlyOnJava8 {
val mainClassName = "hello.App"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project-test"), Some(mainClassName), args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Hello, world!")))
}
}
}

@Test
def canRunDefaultMainClass: Unit = {
// The default main class is set to hello.App build.sbt. Therefore, no error must be triggered here.
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), None, args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Hello, world!")))
TestUtil.runOnlyOnJava8 {
// The default main class is set to hello.App build.sbt. Therefore, no error must be triggered here.
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), None, args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Hello, world!")))
}
}
}

@Test
def canRunMainFromBinaryDependency: Unit = {
val mainClassName = "App"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), Some(mainClassName), args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Hello, world!")))
TestUtil.runOnlyOnJava8 {
val mainClassName = "App"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), Some(mainClassName), args = List.empty)
runAndCheck(state, command) { messages =>
assert(messages.contains(("info", "Hello, world!")))
}
}
}

@Test
def setCorrectCwd: Unit = {
val mainClassName = "hello.ShowCwd"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), Some(mainClassName), args = List.empty)
val targetMsg = {
if (bloop.util.CrossPlatform.isWindows) "cross-test-build-0.6\\test-project\\jvm"
else "cross-test-build-0.6/test-project/jvm"
}
TestUtil.runOnlyOnJava8 {
val mainClassName = "hello.ShowCwd"
val state = loadTestProject("cross-test-build-0.6")
val command = Commands.Run(List("test-project"), Some(mainClassName), args = List.empty)
val targetMsg = {
if (bloop.util.CrossPlatform.isWindows) "cross-test-build-0.6\\test-project\\jvm"
else "cross-test-build-0.6/test-project/jvm"
}

runAndCheck(state, command) { messages =>
assert(
messages.reverse.find(_._1 == "info").exists(_._2.endsWith(targetMsg))
)
runAndCheck(state, command) { messages =>
assert(
messages.reverse.find(_._1 == "info").exists(_._2.endsWith(targetMsg))
)
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions frontend/src/test/scala/bloop/ScalaVersionsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ object ScalaVersionsSpec extends bloop.testing.BaseSuite {

val `2.10` = compileProjectFor("2.10.7")
val `2.11` = compileProjectFor("2.11.11")
val `2.12` = compileProjectFor("2.12.8")
val `2.13` = compileProjectFor("2.13.0-RC2")
val all = List(`2.10`, `2.11`, `2.12`, `2.13`)
val `2.12` = compileProjectFor("2.12.9")
val `2.13` = compileProjectFor("2.13.0")
val all = {
if (TestUtil.isJdk8) List(`2.10`, `2.11`, `2.12`, `2.13`)
else List(`2.12`, `2.13`)
}

TestUtil.await(FiniteDuration(60, "s"), ExecutionContext.ioScheduler) {
Task.gatherUnordered(all).map(_ => ())
}
Expand Down
Loading