Skip to content

Commit

Permalink
bugfix: Fix tests broken by updating sbt version
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Sep 18, 2024
1 parent 04a16c6 commit 42a2c61
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import bloop.integrations.sbt.BloopDefaults

name := "non-compiling"
val nonCompiling = project
.in(file("."))

val bloopConfigFile = settingKey[File]("Config file to test")
ThisBuild / bloopConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("non-compiling.json")
val config = bloopDir./("nonCompiling.json")
config
}

val bloopTestConfigFile = settingKey[File]("Test config file to test")
ThisBuild / bloopTestConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("non-compiling-test.json")
val config = bloopDir./("nonCompiling-test.json")
config
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
import bloop.integrations.sbt.BloopDefaults

name := "runtime-dependency"

libraryDependencies +=
"ch.qos.logback" % "logback-classic" % "1.2.7" % Runtime
val runtimeDependency = project
.in(file("."))
.settings(
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.7" % Runtime
)

val bloopConfigFile = settingKey[File]("Config file to test")
ThisBuild / bloopConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("runtime-dependency.json")
val config = bloopDir./("runtimeDependency.json")
config
}

val bloopTestConfigFile = settingKey[File]("Test config file to test")
ThisBuild / bloopTestConfigFile := {
val bloopDir = Keys.baseDirectory.value./(".bloop")
val config = bloopDir./("runtime-dependency-test.json")
val config = bloopDir./("runtimeDependency-test.json")
config
}

val checkBloopFiles = taskKey[Unit]("Check bloop file contents")
ThisBuild / checkBloopFiles := {
val configContents = BloopDefaults.unsafeParseConfig(bloopConfigFile.value.toPath)

assert(configContents.project.platform.isDefined)
val platformJvm =
configContents.project.platform.get.asInstanceOf[bloop.config.Config.Platform.Jvm]
val obtainedRuntimeClasspath = platformJvm.classpath.map(_.map(_.getFileName.toString))
val expectedRuntimeClasspath = Some(
List(
"classes",
"logback-core-1.2.7.jar",
"scala-library.jar",
"slf4j-api-1.7.32.jar",
"logback-classic-1.2.7.jar"
"logback-classic-1.2.7.jar",
"logback-core-1.2.7.jar",
"slf4j-api-1.7.32.jar"
)
)
assert(obtainedRuntimeClasspath == expectedRuntimeClasspath)
Expand All @@ -46,14 +48,13 @@ ThisBuild / checkBloopFiles := {
assert(testPlatformJvm.classpath.isEmpty)

val obtainedTestClasspath = configTestContents.project.classpath.map(_.getFileName.toString)
println(obtainedTestClasspath)
val expectedTestClasspath =
List(
"classes",
"logback-core-1.2.7.jar",
"scala-library.jar",
"slf4j-api-1.7.32.jar",
"logback-classic-1.2.7.jar"
"logback-classic-1.2.7.jar",
"logback-core-1.2.7.jar",
"slf4j-api-1.7.32.jar"
)

assert(obtainedTestClasspath == expectedTestClasspath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ val jsProject = project
val lines = IO.read(config).replaceAll("\\s", "")
assert(lines.contains(s""""platform":{"name":"$expected""""))
assert(lines.contains(s""""mode":"debug""""))
assert(lines.contains(s""""version":"0.6.28""""))
assert(lines.contains(s""""version":"1.5.1""""))
}
)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % sys.props.apply("plugin.version"))
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1")
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ checkBloopFiles in ThisBuild := {
config.project.platform.get.asInstanceOf[bloop.config.Config.Platform.Jvm].config.options
}

val userDir = sys.props.get("user.dir").getOrElse("working-dir")
assert(
readJvmOptions(fooConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"foo working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"foo working directory ends with $userDir"
)

assert(
readJvmOptions(fooTestConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"foo test working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"foo test working directory ends with $userDir"
)

assert(
Expand All @@ -75,13 +76,13 @@ checkBloopFiles in ThisBuild := {

assert(
readJvmOptions(bazConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"baz working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"baz working directory ends with $userDir"
)

assert(
readJvmOptions(bazTestConfig)
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith("working-dir")),
"baz test working directory ends with working-dir"
.exists(opt => opt.startsWith("-Duser.dir") && opt.endsWith(userDir)),
s"baz test working directory ends with $userDir"
)
}

0 comments on commit 42a2c61

Please sign in to comment.