Skip to content

Commit

Permalink
Enable forking when running tests.
Browse files Browse the repository at this point in the history
The Scalafix test suite uses `this.getClass.getClassLoader` to lookup
symbols from scala-library.jar. In sbt v1.3.x, the default classloader
layering strategy changed so that `this.getClass.getClassLoader` only
contains Scalafix-defined classes, with classes from dependency classes
coming from a parent classloader.

This commit makes the tests pass on sbt v1.3.x by enabling forking so
that `this.getClass.getClassLoader` is always a flat classloader
containing all classes.
  • Loading branch information
Olafur Pall Geirsson committed Apr 14, 2020
1 parent 94c5c69 commit be6798e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions build.sbt
Expand Up @@ -4,7 +4,7 @@ inThisBuild(
onLoadMessage := s"Welcome to scalafix ${version.value}",
scalaVersion := scala212,
crossScalaVersions := List(scala212, scala211),
fork.in(Test, test) := true
fork := true
)
)

Expand Down Expand Up @@ -169,7 +169,8 @@ lazy val unit = project
.in(file("scalafix-tests/unit"))
.settings(
noPublish,
fork := false,
// Change working directory to match when `fork := false`.
baseDirectory.in(Test) := baseDirectory.in(ThisBuild).value,
javaOptions := Nil,
buildInfoPackage := "scalafix.tests",
buildInfoObject := "BuildInfo",
Expand Down Expand Up @@ -251,6 +252,7 @@ lazy val docs = project
.in(file("scalafix-docs"))
.settings(
noMima,
baseDirectory.in(run) := baseDirectory.in(ThisBuild).value,
skip in publish := true,
moduleName := "scalafix-docs",
scalaVersion := scala212,
Expand Down
Expand Up @@ -82,7 +82,7 @@ class ScalafixImplSuite extends FunSuite with DiffAssertions {
}

test("error") {
val cl = new URLClassLoader(Array())
val cl = new URLClassLoader(Array(), null)
val ex = intercept[ScalafixException] {
i.Scalafix.classloadInstance(cl)
}
Expand Down

0 comments on commit be6798e

Please sign in to comment.