Skip to content

Commit

Permalink
Skip validation for default Scala versions, add build test
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejG604 committed Nov 28, 2023
1 parent 4dfdf69 commit de4bc16
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,10 @@ trait Build extends ScalaCliSbtModule with ScalaCliPublishModule with HasTests
| def toolkitVersion = "${Deps.toolkitTest.dep.version}"
| def typelevelToolkitOrganization = "${Deps.typelevelToolkit.dep.module.organization.value}"
| def typelevelToolkitVersion = "${Deps.typelevelToolkit.dep.version}"
|
| def defaultScalaVersion = "${Scala.defaultUser}"
| def defaultScala212Version = "${Scala.scala212}"
| def defaultScala213Version = "${Scala.scala213}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.build.bsp.{WrappedSourcesItem, WrappedSourcesResult}
import scala.build.internal.ClassCodeWrapper

class BspServerTests extends TestUtil.ScalaCliBuildSuite {
val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-actionable-diagnostic-")
val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-bsp-server-")
val directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
internal = InternalOptions(
Expand Down
71 changes: 71 additions & 0 deletions modules/build/src/test/scala/scala/build/tests/OfflineTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package scala.build.tests

import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.{CacheLogger, FileCache}
import org.scalajs.logging.{NullLogger, Logger as ScalaJsLogger}

import java.util.concurrent.TimeUnit
import scala.build.Ops.*
import scala.build.bsp.{
BspServer,
ScalaScriptBuildServer,
WrappedSourceItem,
WrappedSourcesItem,
WrappedSourcesParams,
WrappedSourcesResult
}
import scala.build.errors.{
InvalidBinaryScalaVersionError,
NoValidScalaVersionFoundError,
ScalaVersionError,
UnsupportedScalaVersionError
}
import scala.build.internal.ClassCodeWrapper
import scala.build.options.{BuildOptions, InternalOptions, Scope}
import scala.build.tests.Constants
import scala.build.{Build, BuildThreads, Directories, GeneratedSource, LocalRepo}
import scala.collection.mutable.ArrayBuffer
import scala.jdk.CollectionConverters.*

class OfflineTests extends TestUtil.ScalaCliBuildSuite {
val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-offline-")
val directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
internal = InternalOptions(
cache = Some(FileCache()
.withLocation(directories.cacheDir.toString)
.withCachePolicies(Seq(coursier.cache.CachePolicy.LocalOnly)))
)
)

val buildThreads = BuildThreads.create()

for (
defaultVersion <- Seq(
Constants.defaultScalaVersion,
Constants.defaultScala212Version,
Constants.defaultScala213Version
)
)
test(s"Default versions of Scala should pass without validation for $defaultVersion") {
val testInputs = TestInputs(
os.rel / "script.sc" ->
s"""//> using scala $defaultVersion
|def msg: String = "Hello"
|
|println(msg)
|""".stripMargin
)

testInputs.withBuild(baseOptions, buildThreads, None) {
(root, _, maybeBuild) =>
maybeBuild match {
case Left(e: ScalaVersionError) =>
munit.Assertions.fail(
s"Validation Failed with:${System.lineSeparator()} ${e.getMessage}"
)
case _ => ()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,21 @@ final case class BuildOptions(
repositories: Seq[Repository] = Nil
): Either[BuildException, Option[ScalaParameters]] = either {

val defaultVersions = Set(
Constants.defaultScalaVersion,
Constants.defaultScala212Version,
Constants.defaultScala213Version
)

val svOpt: Option[String] = scalaOptions.scalaVersion match {
case Some(MaybeScalaVersion(None)) =>
None
// Do not validate Scala version in offline mode
case Some(MaybeScalaVersion(Some(svInput))) if internal.offline.getOrElse(false) =>
Some(svInput)
// Do not validate Scala version if it is a default one
case Some(MaybeScalaVersion(Some(svInput))) if defaultVersions.contains(svInput) =>
Some(svInput)
case Some(MaybeScalaVersion(Some(svInput))) =>
val sv = value {
svInput match {
Expand Down

0 comments on commit de4bc16

Please sign in to comment.