Skip to content

Commit

Permalink
Make --offline tests resilient to unannounced Scala versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Aug 14, 2024
1 parent 152d717 commit c0382e8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
1 change: 1 addition & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
| def scala3Lts = "${Scala.scala3Lts}"
| def scala3NextRc = "${Scala.scala3NextRc}"
| def scala3Next = "${Scala.scala3Next}"
| def scala3NextAnnounced = "${Scala.scala3NextAnnounced}"
| def defaultScala = "${Scala.defaultUser}"
| def defaultScalafmtVersion = "${Deps.scalafmtCli.dep.version}"
| def maxAmmoniteScala212Version = "${Scala.maxAmmoniteScala212Version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1967,13 +1967,42 @@ abstract class RunTestDefinitions
}
}

if (!actualScalaVersion.contains("RC"))
test("offline mode should fail on missing artifacts") {
if (!actualScalaVersion.contains("RC")) {
val actualAnnouncedScalaVersion = actualScalaVersion match {
case _
if actualScalaVersion == Constants.scala3Next &&
Constants.scala3Next != Constants.scala3NextAnnounced =>
// if the version isn't public yet, Coursier won't be able to install it
Constants.scala3NextAnnounced
case s => s
}

test(
s"offline mode should fail on missing artifacts (with Scala $actualAnnouncedScalaVersion)"
) {
// Kill bloop deamon to test scalac fallback
os.proc(TestUtil.cli, "--power", "bloop", "exit")
.call(cwd = os.pwd)

val depScalaVersion = actualScalaVersion match {
// ensure extra options use an announced Scala version
val customExtraOptions: Seq[String] =
if (
scalaVersionOpt.isEmpty &&
Constants.scala3Next != Constants.scala3NextAnnounced
)
extraOptions ++ Seq("--scala", actualAnnouncedScalaVersion)
else if (
actualScalaVersion == Constants.scala3Next &&
actualScalaVersion != actualAnnouncedScalaVersion
)
extraOptions
.map {
case opt if opt == Constants.scala3Next => actualAnnouncedScalaVersion
case opt => opt
}
else extraOptions

val depScalaVersion = actualAnnouncedScalaVersion match {
case sv if sv.startsWith("2.12") => "2.12"
case sv if sv.startsWith("2.13") => "2.13"
case _ => "3"
Expand Down Expand Up @@ -2008,7 +2037,7 @@ abstract class RunTestDefinitions
TestUtil.cli,
"--power",
"NoDeps.scala",
extraOptions,
customExtraOptions,
"--offline",
"--cache",
cachePath.toString
Expand All @@ -2020,19 +2049,23 @@ abstract class RunTestDefinitions
expect(emptyCacheWalkSize == os.walk(cachePath).size)

// Download the artifacts for scala
os.proc(TestUtil.cs, "install", s"scala:$actualScalaVersion")
os.proc(TestUtil.cs, "install", s"scala:$actualAnnouncedScalaVersion")
.call(cwd = root, env = extraEnv)
os.proc(TestUtil.cs, "install", s"scalac:$actualScalaVersion")
os.proc(TestUtil.cs, "install", s"scalac:$actualAnnouncedScalaVersion")
.call(cwd = root, env = extraEnv)
(if (actualScalaVersion.startsWith("3")) Some("scala3-sbt-bridge")
(if (actualAnnouncedScalaVersion.startsWith("3")) Some("scala3-sbt-bridge")
else if (
actualScalaVersion.startsWith("2.13.") &&
actualScalaVersion.coursierVersion >= "2.13.12".coursierVersion
actualAnnouncedScalaVersion.startsWith("2.13.") &&
actualAnnouncedScalaVersion.coursierVersion >= "2.13.12".coursierVersion
)
Some("scala2-sbt-bridge")
else None)
.foreach { bridgeArtifactName =>
os.proc(TestUtil.cs, "fetch", s"org.scala-lang:$bridgeArtifactName:$actualScalaVersion")
os.proc(
TestUtil.cs,
"fetch",
s"org.scala-lang:$bridgeArtifactName:$actualAnnouncedScalaVersion"
)
.call(cwd = root, env = extraEnv)
}

Expand All @@ -2046,7 +2079,7 @@ abstract class RunTestDefinitions
TestUtil.cli,
"--power",
"NoDeps.scala",
extraOptions,
customExtraOptions,
"--offline",
"--cache",
cachePath.toString,
Expand Down Expand Up @@ -2076,7 +2109,7 @@ abstract class RunTestDefinitions
"--power",
cliOption,
"WithDeps.scala",
extraOptions,
customExtraOptions,
"--cache",
cachePath.toString
)
Expand All @@ -2098,7 +2131,7 @@ abstract class RunTestDefinitions
TestUtil.cli,
"--power",
"WithDeps.scala",
extraOptions,
customExtraOptions,
"--offline",
"--cache",
cachePath.toString,
Expand All @@ -2118,6 +2151,7 @@ abstract class RunTestDefinitions
expect(withDependencyCacheWalkSize == os.walk(cachePath).size)
}
}
}

test("JVM id is printed with compilation info correctly") {
val msg = "Hello"
Expand Down
7 changes: 4 additions & 3 deletions project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ object Scala {
def scala213 = "2.13.14"
def runnerScala3 = "3.0.2" // the newest version that is compatible with all Scala 3.x versions
def scala3LtsPrefix = "3.3" // used for the LTS version tags
def scala3Lts = s"$scala3LtsPrefix.3" // the LTS version currently used in the build
def scala3Next = "3.4.2" // the newest/next version of Scala
def scala3NextRc = "3.5.0-RC7" // the latest RC version of Scala Next
def scala3Lts = s"$scala3LtsPrefix.3" // the LTS version currently used in the build
def scala3Next = "3.4.2" // the newest/next version of Scala
def scala3NextAnnounced = scala3Next // the newest/next version of Scala that's been announced
def scala3NextRc = "3.5.0-RC7" // the latest RC version of Scala Next

// The Scala version used to build the CLI itself.
def defaultInternal = sys.props.get("scala.version.internal").getOrElse(scala3Lts)
Expand Down

0 comments on commit c0382e8

Please sign in to comment.