Skip to content

Commit c0382e8

Browse files
committed
Make --offline tests resilient to unannounced Scala versions
1 parent 152d717 commit c0382e8

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

build.sc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
10031003
| def scala3Lts = "${Scala.scala3Lts}"
10041004
| def scala3NextRc = "${Scala.scala3NextRc}"
10051005
| def scala3Next = "${Scala.scala3Next}"
1006+
| def scala3NextAnnounced = "${Scala.scala3NextAnnounced}"
10061007
| def defaultScala = "${Scala.defaultUser}"
10071008
| def defaultScalafmtVersion = "${Deps.scalafmtCli.dep.version}"
10081009
| def maxAmmoniteScala212Version = "${Scala.maxAmmoniteScala212Version}"

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,13 +1967,42 @@ abstract class RunTestDefinitions
19671967
}
19681968
}
19691969

1970-
if (!actualScalaVersion.contains("RC"))
1971-
test("offline mode should fail on missing artifacts") {
1970+
if (!actualScalaVersion.contains("RC")) {
1971+
val actualAnnouncedScalaVersion = actualScalaVersion match {
1972+
case _
1973+
if actualScalaVersion == Constants.scala3Next &&
1974+
Constants.scala3Next != Constants.scala3NextAnnounced =>
1975+
// if the version isn't public yet, Coursier won't be able to install it
1976+
Constants.scala3NextAnnounced
1977+
case s => s
1978+
}
1979+
1980+
test(
1981+
s"offline mode should fail on missing artifacts (with Scala $actualAnnouncedScalaVersion)"
1982+
) {
19721983
// Kill bloop deamon to test scalac fallback
19731984
os.proc(TestUtil.cli, "--power", "bloop", "exit")
19741985
.call(cwd = os.pwd)
19751986

1976-
val depScalaVersion = actualScalaVersion match {
1987+
// ensure extra options use an announced Scala version
1988+
val customExtraOptions: Seq[String] =
1989+
if (
1990+
scalaVersionOpt.isEmpty &&
1991+
Constants.scala3Next != Constants.scala3NextAnnounced
1992+
)
1993+
extraOptions ++ Seq("--scala", actualAnnouncedScalaVersion)
1994+
else if (
1995+
actualScalaVersion == Constants.scala3Next &&
1996+
actualScalaVersion != actualAnnouncedScalaVersion
1997+
)
1998+
extraOptions
1999+
.map {
2000+
case opt if opt == Constants.scala3Next => actualAnnouncedScalaVersion
2001+
case opt => opt
2002+
}
2003+
else extraOptions
2004+
2005+
val depScalaVersion = actualAnnouncedScalaVersion match {
19772006
case sv if sv.startsWith("2.12") => "2.12"
19782007
case sv if sv.startsWith("2.13") => "2.13"
19792008
case _ => "3"
@@ -2008,7 +2037,7 @@ abstract class RunTestDefinitions
20082037
TestUtil.cli,
20092038
"--power",
20102039
"NoDeps.scala",
2011-
extraOptions,
2040+
customExtraOptions,
20122041
"--offline",
20132042
"--cache",
20142043
cachePath.toString
@@ -2020,19 +2049,23 @@ abstract class RunTestDefinitions
20202049
expect(emptyCacheWalkSize == os.walk(cachePath).size)
20212050

20222051
// Download the artifacts for scala
2023-
os.proc(TestUtil.cs, "install", s"scala:$actualScalaVersion")
2052+
os.proc(TestUtil.cs, "install", s"scala:$actualAnnouncedScalaVersion")
20242053
.call(cwd = root, env = extraEnv)
2025-
os.proc(TestUtil.cs, "install", s"scalac:$actualScalaVersion")
2054+
os.proc(TestUtil.cs, "install", s"scalac:$actualAnnouncedScalaVersion")
20262055
.call(cwd = root, env = extraEnv)
2027-
(if (actualScalaVersion.startsWith("3")) Some("scala3-sbt-bridge")
2056+
(if (actualAnnouncedScalaVersion.startsWith("3")) Some("scala3-sbt-bridge")
20282057
else if (
2029-
actualScalaVersion.startsWith("2.13.") &&
2030-
actualScalaVersion.coursierVersion >= "2.13.12".coursierVersion
2058+
actualAnnouncedScalaVersion.startsWith("2.13.") &&
2059+
actualAnnouncedScalaVersion.coursierVersion >= "2.13.12".coursierVersion
20312060
)
20322061
Some("scala2-sbt-bridge")
20332062
else None)
20342063
.foreach { bridgeArtifactName =>
2035-
os.proc(TestUtil.cs, "fetch", s"org.scala-lang:$bridgeArtifactName:$actualScalaVersion")
2064+
os.proc(
2065+
TestUtil.cs,
2066+
"fetch",
2067+
s"org.scala-lang:$bridgeArtifactName:$actualAnnouncedScalaVersion"
2068+
)
20362069
.call(cwd = root, env = extraEnv)
20372070
}
20382071

@@ -2046,7 +2079,7 @@ abstract class RunTestDefinitions
20462079
TestUtil.cli,
20472080
"--power",
20482081
"NoDeps.scala",
2049-
extraOptions,
2082+
customExtraOptions,
20502083
"--offline",
20512084
"--cache",
20522085
cachePath.toString,
@@ -2076,7 +2109,7 @@ abstract class RunTestDefinitions
20762109
"--power",
20772110
cliOption,
20782111
"WithDeps.scala",
2079-
extraOptions,
2112+
customExtraOptions,
20802113
"--cache",
20812114
cachePath.toString
20822115
)
@@ -2098,7 +2131,7 @@ abstract class RunTestDefinitions
20982131
TestUtil.cli,
20992132
"--power",
21002133
"WithDeps.scala",
2101-
extraOptions,
2134+
customExtraOptions,
21022135
"--offline",
21032136
"--cache",
21042137
cachePath.toString,
@@ -2118,6 +2151,7 @@ abstract class RunTestDefinitions
21182151
expect(withDependencyCacheWalkSize == os.walk(cachePath).size)
21192152
}
21202153
}
2154+
}
21212155

21222156
test("JVM id is printed with compilation info correctly") {
21232157
val msg = "Hello"

project/deps.sc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ object Scala {
77
def scala213 = "2.13.14"
88
def runnerScala3 = "3.0.2" // the newest version that is compatible with all Scala 3.x versions
99
def scala3LtsPrefix = "3.3" // used for the LTS version tags
10-
def scala3Lts = s"$scala3LtsPrefix.3" // the LTS version currently used in the build
11-
def scala3Next = "3.4.2" // the newest/next version of Scala
12-
def scala3NextRc = "3.5.0-RC7" // the latest RC version of Scala Next
10+
def scala3Lts = s"$scala3LtsPrefix.3" // the LTS version currently used in the build
11+
def scala3Next = "3.4.2" // the newest/next version of Scala
12+
def scala3NextAnnounced = scala3Next // the newest/next version of Scala that's been announced
13+
def scala3NextRc = "3.5.0-RC7" // the latest RC version of Scala Next
1314

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

0 commit comments

Comments
 (0)