Skip to content

Commit 8cc9c51

Browse files
committed
Skip validation for default Scala versions, add build test
1 parent 9014c2a commit 8cc9c51

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

build.sc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ trait Build extends ScalaCliSbtModule with ScalaCliPublishModule with HasTests
678678
| def toolkitVersion = "${Deps.toolkitTest.dep.version}"
679679
| def typelevelToolkitOrganization = "${Deps.typelevelToolkit.dep.module.organization.value}"
680680
| def typelevelToolkitVersion = "${Deps.typelevelToolkit.dep.version}"
681+
|
682+
| def defaultScalaVersion = "${Scala.defaultUser}"
683+
| def defaultScala212Version = "${Scala.scala212}"
684+
| def defaultScala213Version = "${Scala.scala213}"
681685
|}
682686
|""".stripMargin
683687
if (!os.isFile(dest) || os.read(dest) != code)

modules/build/src/test/scala/scala/build/tests/BspServerTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.build.bsp.{WrappedSourcesItem, WrappedSourcesResult}
2222
import scala.build.internal.ClassCodeWrapper
2323

2424
class BspServerTests extends TestUtil.ScalaCliBuildSuite {
25-
val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-actionable-diagnostic-")
25+
val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-bsp-server-")
2626
val directories = Directories.under(extraRepoTmpDir)
2727
val baseOptions = BuildOptions(
2828
internal = InternalOptions(
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package scala.build.tests
2+
3+
import com.eed3si9n.expecty.Expecty.expect
4+
import coursier.cache.{CacheLogger, FileCache}
5+
import org.scalajs.logging.{NullLogger, Logger as ScalaJsLogger}
6+
7+
import java.util.concurrent.TimeUnit
8+
import scala.build.Ops.*
9+
import scala.build.bsp.{
10+
BspServer,
11+
ScalaScriptBuildServer,
12+
WrappedSourceItem,
13+
WrappedSourcesItem,
14+
WrappedSourcesParams,
15+
WrappedSourcesResult
16+
}
17+
import scala.build.errors.{
18+
InvalidBinaryScalaVersionError,
19+
NoValidScalaVersionFoundError,
20+
ScalaVersionError,
21+
UnsupportedScalaVersionError
22+
}
23+
import scala.build.internal.ClassCodeWrapper
24+
import scala.build.options.{BuildOptions, InternalOptions, Scope}
25+
import scala.build.tests.Constants
26+
import scala.build.{Build, BuildThreads, Directories, GeneratedSource, LocalRepo}
27+
import scala.collection.mutable.ArrayBuffer
28+
import scala.jdk.CollectionConverters.*
29+
30+
class OfflineTests extends TestUtil.ScalaCliBuildSuite {
31+
val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-offline-")
32+
val directories = Directories.under(extraRepoTmpDir)
33+
val baseOptions = BuildOptions(
34+
internal = InternalOptions(
35+
cache = Some(FileCache()
36+
.withLocation(directories.cacheDir.toString)
37+
.withCachePolicies(Seq(coursier.cache.CachePolicy.LocalOnly)))
38+
)
39+
)
40+
41+
val buildThreads = BuildThreads.create()
42+
43+
for (
44+
defaultVersion <- Seq(
45+
Constants.defaultScalaVersion,
46+
Constants.defaultScala212Version,
47+
Constants.defaultScala213Version
48+
)
49+
)
50+
test(s"Default versions of Scala should pass without validation for $defaultVersion") {
51+
val testInputs = TestInputs(
52+
os.rel / "script.sc" ->
53+
s"""//> using scala $defaultVersion
54+
|def msg: String = "Hello"
55+
|
56+
|println(msg)
57+
|""".stripMargin
58+
)
59+
60+
testInputs.withBuild(baseOptions, buildThreads, None) {
61+
(root, _, maybeBuild) =>
62+
maybeBuild match {
63+
case Left(e: ScalaVersionError) =>
64+
munit.Assertions.fail(
65+
s"Validation Failed with:${System.lineSeparator()} ${e.getMessage}"
66+
)
67+
case _ => ()
68+
}
69+
}
70+
}
71+
}

modules/options/src/main/scala/scala/build/options/BuildOptions.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,21 @@ final case class BuildOptions(
312312
repositories: Seq[Repository] = Nil
313313
): Either[BuildException, Option[ScalaParameters]] = either {
314314

315+
val defaultVersions = Set(
316+
Constants.defaultScalaVersion,
317+
Constants.defaultScala212Version,
318+
Constants.defaultScala213Version
319+
)
320+
315321
val svOpt: Option[String] = scalaOptions.scalaVersion match {
316322
case Some(MaybeScalaVersion(None)) =>
317323
None
324+
// Do not validate Scala version in offline mode
318325
case Some(MaybeScalaVersion(Some(svInput))) if internal.offline.getOrElse(false) =>
319326
Some(svInput)
327+
// Do not validate Scala version if it is a default one
328+
case Some(MaybeScalaVersion(Some(svInput))) if defaultVersions.contains(svInput) =>
329+
Some(svInput)
320330
case Some(MaybeScalaVersion(Some(svInput))) =>
321331
val sv = value {
322332
svInput match {

0 commit comments

Comments
 (0)