Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build.mill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ trait BuildMacros extends ScalaCliCrossSbtModule
else super.compileIvyDeps() ++ Agg(Deps.scalaReflect(crossScalaVersion))
}

object test extends ScalaCliTests {
object test extends ScalaCliTests with ScalaCliScalafixModule {
override def scalacOptions: T[Seq[String]] = Task {
super.scalacOptions() ++ asyncScalacOptions(scalaVersion())
super.scalacOptions() ++ Seq("-deprecation")
}

def testNegativeCompilation(): Command[Unit] = Task.Command(exclusive = true) {
Expand Down Expand Up @@ -669,7 +669,8 @@ trait Options extends ScalaCliCrossSbtModule with ScalaCliPublishModule with Has
override def repositoriesTask: Task[Seq[Repository]] =
Task.Anon(super.repositoriesTask() ++ deps.customRepositories)

object test extends ScalaCliTests {
object test extends ScalaCliTests with ScalaCliScalafixModule {
override def scalacOptions = super.scalacOptions() ++ Seq("-deprecation")
// uncomment below to debug tests in attach mode on 5005 port
// def forkArgs = Task {
// super.forkArgs() ++ Seq("-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:5005,suspend=y")
Expand Down Expand Up @@ -716,8 +717,9 @@ trait Build extends ScalaCliCrossSbtModule
override def repositoriesTask: Task[Seq[Repository]] =
Task.Anon(super.repositoriesTask() ++ deps.customRepositories)

object test extends ScalaCliTests {
override def ivyDeps: T[Loose.Agg[Dep]] = super.ivyDeps() ++ Agg(
object test extends ScalaCliTests with ScalaCliScalafixModule {
override def scalacOptions: T[Seq[String]] = super.scalacOptions() ++ Seq("-deprecation")
override def ivyDeps: T[Loose.Agg[Dep]] = super.ivyDeps() ++ Agg(
Deps.pprint,
Deps.slf4jNop
)
Expand Down
4 changes: 2 additions & 2 deletions modules/build-macros/src/test/scala/scala/build/CPSTest.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package scala.build

import EitherCps._
import scala.build.EitherCps.*

class CPSTest extends munit.FunSuite {

val failed1: Either[Int, String] = Left(1)
val ok: Either[Int, String] = Right("OK")

def checkResult(expected: Either[Int, String])(res: => Either[Int, String]) =
def checkResult(expected: Either[Int, String])(res: => Either[Int, String]): Unit =
assertEquals(expected, res)

test("Basic CPS test") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package scala.build.options.publish
import scala.build.Positioned
import scala.build.errors.{BuildException, MalformedInputError}

import munit.Assertions.assertEquals

class VcsParseTest extends munit.FunSuite {
test("valid GitHub") {
val actual = Vcs.parse(Positioned.none("github:VirtusLab/scala-cli"))
Expand All @@ -18,24 +16,33 @@ class VcsParseTest extends munit.FunSuite {
}

test("invalid GitHub: missing /") {
val actual = Vcs.parse(Positioned.none("github:scala-cli"))
val expected =
val actual: Either[BuildException, Vcs] = Vcs.parse(Positioned.none("github:scala-cli"))
val expected =
Left(new MalformedInputError("github-vcs", "github:scala-cli", "github:org/project", Nil))

assert(actual.isInstanceOf[Left[BuildException, Vcs]])
assert {
actual match {
case Left(_: BuildException) => true
case _ => sys.error("incorrect type")
}
}
assertEquals(expected.toString, actual.toString)
}

test("invalid GitHub: too many /") {
val actual = Vcs.parse(Positioned.none("github:github.com/VirtusLab/scala-cli"))
val actual: Either[BuildException, Vcs] =
Vcs.parse(Positioned.none("github:github.com/VirtusLab/scala-cli"))
val expected = Left(new MalformedInputError(
"github-vcs",
"github:github.com/VirtusLab/scala-cli",
"github:org/project",
Nil
))

assert(actual.isInstanceOf[Left[BuildException, Vcs]])
assert {
actual match {
case Left(_: BuildException) => true
case _ => sys.error("incorrect type")
}
}
assertEquals(expected.toString, actual.toString)
}

Expand All @@ -53,7 +60,7 @@ class VcsParseTest extends munit.FunSuite {
}

test("invalid generic: missing |") {
val actual = Vcs.parse(Positioned.none(
val actual: Either[BuildException, Vcs] = Vcs.parse(Positioned.none(
"https://github.com/VirtusLab/scala-cli|scm:git:github.com/VirtusLab/scala-cli.git"
))
val expected = Left(new MalformedInputError(
Expand All @@ -63,29 +70,44 @@ class VcsParseTest extends munit.FunSuite {
Nil
))

assert(actual.isInstanceOf[Left[BuildException, Vcs]])
assert {
actual match {
case Left(_: BuildException) => true
case _ => sys.error("incorrect type")
}
}
assertEquals(expected.toString, actual.toString)
}

test("invalid generic: extra |") {
val actual = Vcs.parse(Positioned.none("a|b|c|d"))
val expected =
val actual: Either[BuildException, Vcs] = Vcs.parse(Positioned.none("a|b|c|d"))
val expected =
Left(new MalformedInputError("vcs", "a|b|c|d", "url|connection|developer-connection", Nil))

assert(actual.isInstanceOf[Left[BuildException, Vcs]])
assert {
actual match {
case Left(_: BuildException) => true
case _ => sys.error("incorrect type")
}
}
assertEquals(expected.toString, actual.toString)
}

test("invalid generic: gibberish") {
val actual = Vcs.parse(Positioned.none("sfrgt pagdhn"))
val expected = Left(new MalformedInputError(
val actual: Either[BuildException, Vcs] = Vcs.parse(Positioned.none("sfrgt pagdhn"))
val expected = Left(new MalformedInputError(
"vcs",
"sfrgt pagdhn",
"url|connection|developer-connection",
Nil
))

assert(actual.isInstanceOf[Left[BuildException, Vcs]])
assert {
actual match {
case Left(_: BuildException) => true
case _ => sys.error("incorrect type")
}
}
assertEquals(expected.toString, actual.toString)
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package scala.build.tests

import com.eed3si9n.expecty.Expecty.expect
import coursier.version.Version

import scala.build.options.{BuildOptions, InternalOptions, SuppressWarningOptions}
import scala.build.Ops.*
import scala.build.{BuildThreads, Directories, LocalRepo}
import scala.build.actionable.ActionablePreprocessor
import scala.build.actionable.ActionableDiagnostic.*
import scala.build.Position.File
import coursier.core.Version

import scala.build.errors.{BuildException, CompositeBuildException}
import scala.build.actionable.ActionableDiagnostic.*
import scala.build.actionable.ActionablePreprocessor
import scala.build.options.{BuildOptions, InternalOptions, SuppressWarningOptions}
import scala.build.{BuildThreads, Directories, LocalRepo}

class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {

val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-actionable-diagnostic-")
val directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-actionable-diagnostic-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
)
)
val buildThreads = BuildThreads.create()
val buildThreads: BuildThreads = BuildThreads.create()

def path2url(p: os.Path): String = p.toIO.toURI.toURL.toString

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package scala.build.tests

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

import java.util.concurrent.TimeUnit

import scala.build.Ops.*
import scala.build.{Build, BuildThreads, Directories, GeneratedSource, LocalRepo}
import scala.build.options.{BuildOptions, InternalOptions, Scope}
import scala.build.bsp.{
BspServer,
ScalaScriptBuildServer,
Expand All @@ -16,20 +13,20 @@ import scala.build.bsp.{
WrappedSourcesParams,
WrappedSourcesResult
}
import scala.build.options.{BuildOptions, InternalOptions, Scope}
import scala.build.{Build, BuildThreads, Directories, GeneratedSource, LocalRepo}
import scala.collection.mutable.ArrayBuffer
import scala.jdk.CollectionConverters.*
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-bsp-server-")
val directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-bsp-server-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
)
)
val buildThreads = BuildThreads.create()
val buildThreads: BuildThreads = BuildThreads.create()

def getScriptBuildServer(
generatedSources: Seq[GeneratedSource],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
package scala.build.tests

import com.eed3si9n.expecty.Expecty.assert as expect
import coursier.{Repositories, Repository}
import coursier.Repositories
import coursier.cache.FileCache
import coursier.core.Version
import coursier.maven.MavenRepository
import coursier.version.Version
import dependency.ScalaParameters

import scala.build.Ops.*
import scala.build.errors.{
InvalidBinaryScalaVersionError,
NoValidScalaVersionFoundError,
ScalaVersionError,
UnsupportedScalaVersionError
}
import scala.build.internal.Constants.*
import scala.build.internal.Regexes.scala2NightlyRegex
import scala.build.options.{
BuildOptions,
BuildRequirements,
ClassPathOptions,
InternalOptions,
MaybeScalaVersion,
ScalaOptions,
ScalaVersionUtil,
ScalacOpt,
ShadowingSeq
}
import scala.build.{Build, BuildThreads, Directories, LocalRepo, Positioned, RepositoryUtils}
import scala.build.internal.Regexes.{scala2NightlyRegex, scala3LtsRegex}
import scala.build.options.*
import scala.build.tests.util.BloopServer
import scala.build.{Build, BuildThreads, Directories, LocalRepo, Positioned, RepositoryUtils}
import scala.concurrent.duration.DurationInt
import scala.build.internal.Regexes.scala3LtsRegex
import scala.build.errors.ScalaVersionError

class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
override def munitFlakyOK: Boolean = TestUtil.isCI

val extraRepoTmpDir = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories = Directories.under(extraRepoTmpDir)
val buildThreads = BuildThreads.create()
val baseOptions = BuildOptions(
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val buildThreads: BuildThreads = BuildThreads.create()
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
Expand All @@ -64,7 +52,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("3.nightly"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
assert(
scalaParams.scalaVersion.startsWith("3") && scalaParams.scalaVersion.endsWith("-NIGHTLY"),
"-S 3.nightly argument does not lead to scala3 nightly build option"
Expand All @@ -76,7 +64,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("3.1.nightly"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
expect(
scalaParams.scalaVersion.startsWith("3.1.") && scalaParams.scalaVersion.endsWith("-NIGHTLY"),
"-S 3.1.nightly argument does not lead to scala 3.1. nightly build option"
Expand Down Expand Up @@ -181,7 +169,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("3.1.2-RC1"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
assert(
scalaParams.scalaVersion == "3.1.2-RC1",
"-S 3.1.2-RC1 argument does not lead to 3.1.2-RC1 build option"
Expand Down Expand Up @@ -224,7 +212,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("2.nightly"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
assert(
scala2NightlyRegex.unapplySeq(scalaParams.scalaVersion).isDefined,
"-S 2.nightly argument does not lead to scala2 nightly build option"
Expand All @@ -237,7 +225,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("2.13.nightly"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
assert(
scala2NightlyRegex.unapplySeq(scalaParams.scalaVersion).isDefined,
"-S 2.13.nightly argument does not lead to scala2 nightly build option"
Expand All @@ -250,7 +238,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("3.lts"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
assert(
scala3LtsRegex.unapplySeq(scalaParams.scalaVersion).isDefined,
"-S 3.lts argument does not lead to scala3 LTS"
Expand All @@ -263,7 +251,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("2.12.nightly"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
assert(
scala2NightlyRegex.unapplySeq(scalaParams.scalaVersion).isDefined,
"-S 2.12.nightly argument does not lead to scala2 nightly build option"
Expand All @@ -276,7 +264,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
scalaVersion = Some(MaybeScalaVersion("2.13.9-bin-4505094"))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))
assert(
scalaParams.scalaVersion == "2.13.9-bin-4505094",
"-S 2.13.9-bin-4505094 argument does not lead to 2.13.9-bin-4505094 scala version in build option"
Expand All @@ -292,7 +280,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
)
}

val expectedScalaVersions = Seq(
val expectedScalaVersions: Seq[(Option[String], String)] = Seq(
None -> defaultScalaVersion,
Some("2.13.2") -> "2.13.2",
Some("3.0.1") -> "3.0.1",
Expand All @@ -311,7 +299,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
cache = Some(FileCache().withTtl(0.seconds))
)
)
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))

val expectedScalaParams = ScalaParameters(expectedScalaVersion)

Expand Down Expand Up @@ -375,7 +363,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
testDescription =
s"-S $prefix should choose the $expectedVersionDescription version ($expectedVersion), not necessarily the latest stable ($latestMatchingVersion) $launcherDefaultVersionDescription"
} test(testDescription) {
val scalaParams = options.scalaParams.orThrow.getOrElse(???)
val scalaParams = options.scalaParams.orThrow.getOrElse(sys.error("should not happen"))

val expectedScalaParams = ScalaParameters(expectedVersion)

Expand Down
Loading
Loading