Skip to content

Commit

Permalink
Scala 3.0.0-M3 (#158)
Browse files Browse the repository at this point in the history
Additionally:

* BUGFIX: incorrect rendering of durations

* Rename forall to forEach

* Build improvements
  • Loading branch information
keynmol authored Jan 4, 2021
1 parent c1bf3e0 commit 663b891
Show file tree
Hide file tree
Showing 35 changed files with 547 additions and 273 deletions.
4 changes: 4 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ spaces {
}

project.git = true

project.excludeFilters = [
".*-scala-3.*"
]
73 changes: 45 additions & 28 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ ThisBuild / commands += Command.command("ci") { state =>
"test:scalafix --check" ::
"clean" ::
"test:compile" ::
"test:fastLinkJS" :: // do this separately as it's memory intensive
"test" ::
"docs/docusaurusCreateSite" ::
"core/publishLocal" :: state
}

ThisBuild / commands += Command.command("fix") { state =>
"scalafmtAll" ::
"scalafmtSbt" ::
"scalafix" ::
"test:scalafix" :: state
"scalafix" ::
"test:scalafix" ::
"scalafmtAll" ::
"scalafmtSbt" :: state
}

ThisBuild / commands += Command.command("release") { state =>
Expand All @@ -33,7 +34,6 @@ Global / (Test / testOptions) += Tests.Argument("--quickstart")

lazy val root = project
.in(file("."))
.enablePlugins(ScalafixPlugin)
.aggregate(allModules: _*)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.doNotPublishArtifact)
Expand Down Expand Up @@ -71,21 +71,24 @@ lazy val core = projectMatrix
.in(file("modules/core"))
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
.crossCatsEffect
.full
.configure(catsEffectDependencies)
.settings(
libraryDependencies ++= Seq(
"com.eed3si9n.expecty" %%% "expecty" % "0.14.1",
"org.portable-scala" %%% "portable-scala-reflect" % "1.0.0"
"com.eed3si9n.expecty" %%% "expecty" % "0.15.0",
// https://github.com/portable-scala/portable-scala-reflect/issues/23
("org.portable-scala" %%% "portable-scala-reflect" % "1.0.0").withDottyCompat(
scalaVersion.value)
),
libraryDependencies ++= {
if (virtualAxes.value.contains(VirtualAxis.jvm))
Seq(
"org.scala-js" %%% "scalajs-stubs" % "1.0.0" % "provided"
("org.scala-js" %%% "scalajs-stubs" % "1.0.0" % "provided").withDottyCompat(
scalaVersion.value)
)
else {
Seq(
"io.github.cquiroz" %%% "scala-java-time" % "2.0.0"
"io.github.cquiroz" %%% "scala-java-time" % "2.1.0"
)
}
}
Expand All @@ -109,7 +112,7 @@ val allIntegrationsCoresFilter: ScopeFilter =

lazy val docs = projectMatrix
.in(file("modules/docs"))
.jvmPlatform(WeaverPlugin.supportedScalaVersions)
.jvmPlatform(WeaverPlugin.supportedScala2Versions)
.enablePlugins(DocusaurusPlugin, MdocPlugin)
.dependsOn(core, scalacheck, cats, zio, monix, monixBio, specs2)
.settings(
Expand Down Expand Up @@ -157,13 +160,23 @@ lazy val docs = projectMatrix
val integrations =
process(projectsWithAxes.all(allIntegrationsCoresFilter).value)

val artifactsCE2Version = (cats.finder(
VirtualAxis.jvm,
CatsEffect2Axis).apply(scala213) / version).value

val artifactsCE3Version = (cats.finder(
VirtualAxis.jvm,
CatsEffect3Axis).apply(scala213) / version).value

IO.write(
filePath,
s"""
| package weaver.docs
|
| object BuildMatrix {
| val catsEffect3Version = ${q(catsEffect3Version)}
| val artifactsCE2Version = ${q(artifactsCE2Version)}
| val artifactsCE3Version = ${q(artifactsCE3Version)}
| val effects = $effects
| val integrations = $integrations
| }
Expand All @@ -177,18 +190,20 @@ lazy val docs = projectMatrix
lazy val framework = projectMatrix
.in(file("modules/framework"))
.dependsOn(core)
.crossCatsEffect
.full
.settings(
libraryDependencies ++= {
if (virtualAxes.value.contains(VirtualAxis.jvm))
Seq(
"org.scala-sbt" % "test-interface" % "1.0",
"org.scala-js" %%% "scalajs-stubs" % "1.0.0" % "provided"
"org.scala-sbt" % "test-interface" % "1.0",
("org.scala-js" %%% "scalajs-stubs" % "1.0.0" % "provided").withDottyCompat(
scalaVersion.value)
)
else
Seq(
"org.scala-js" %% "scalajs-test-interface" % scalaJSVersion,
"io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.0.0" % Test
("org.scala-js" %% "scalajs-test-interface" % scalaJSVersion).withDottyCompat(
scalaVersion.value),
"io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.1.0" % Test
)
}
)
Expand All @@ -197,7 +212,7 @@ lazy val framework = projectMatrix

lazy val scalacheck = projectMatrix
.in(file("modules/scalacheck"))
.crossCatsEffect
.full
.dependsOn(core, cats % "test->compile")
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -210,7 +225,7 @@ lazy val scalacheck = projectMatrix

lazy val specs2 = projectMatrix
.in(file("modules/specs2"))
.crossCatsEffect
.sparse(withCE3 = true, withJS = true, withScala3 = false)
.dependsOn(core, cats % "test->compile")
.configure(WeaverPlugin.profile)
.settings(
Expand All @@ -231,15 +246,15 @@ lazy val effectCores: Seq[ProjectReference] =

lazy val coreCats = projectMatrix
.in(file("modules/core/cats"))
.crossCatsEffect
.full
.dependsOn(core)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
.settings(name := "cats-core")

lazy val coreMonix = projectMatrix
.in(file("modules/core/monix"))
.onlyCatsEffect2()
.sparse(withCE3 = false, withJS = true, withScala3 = false)
.dependsOn(core)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -252,7 +267,7 @@ lazy val coreMonix = projectMatrix

lazy val coreMonixBio = projectMatrix
.in(file("modules/core/monixBio"))
.onlyCatsEffect2()
.sparse(withCE3 = false, withJS = true, withScala3 = false)
.dependsOn(core)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -265,7 +280,7 @@ lazy val coreMonixBio = projectMatrix

lazy val coreZio = projectMatrix
.in(file("modules/core/zio"))
.onlyCatsEffect2()
.sparse(withCE3 = false, withJS = true, withScala3 = false)
.dependsOn(core)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -290,18 +305,20 @@ lazy val effectFrameworks: Seq[ProjectReference] = Seq(
lazy val cats = projectMatrix
.in(file("modules/framework/cats"))
.dependsOn(framework, coreCats)
.crossCatsEffect
.full
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
.settings(
name := "cats",
testFrameworks := Seq(new TestFramework("weaver.framework.CatsEffect")),
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.0.0" % Test
libraryDependencies += {
"io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.1.0" % Test
}
)

lazy val monix = projectMatrix
.in(file("modules/framework/monix"))
.onlyCatsEffect2()
.sparse(withCE3 = false, withJS = true, withScala3 = false)
.dependsOn(framework, coreMonix)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -312,7 +329,7 @@ lazy val monix = projectMatrix

lazy val monixBio = projectMatrix
.in(file("modules/framework/monix-bio"))
.onlyCatsEffect2()
.sparse(withCE3 = false, withJS = true, withScala3 = false)
.dependsOn(framework, coreMonixBio)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -323,7 +340,7 @@ lazy val monixBio = projectMatrix

lazy val zio = projectMatrix
.in(file("modules/framework/zio"))
.onlyCatsEffect2()
.sparse(withCE3 = false, withJS = true, withScala3 = false)
.dependsOn(framework, coreZio)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -337,7 +354,7 @@ lazy val zio = projectMatrix
// #################################################################################################

lazy val intellijRunner = projectMatrix
.onlyCatsEffect2(withJs = false)
.sparse(withCE3 = false, withJS = false, withScala3 = false)
.in(file("modules/intellij-runner"))
.dependsOn(core, framework, framework % "test->compile")
.configure(WeaverPlugin.profile)
Expand Down
2 changes: 1 addition & 1 deletion docs/expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object MySuite2 extends SimpleIOSuite {
pureTest("Foldable operations") {
val list = List(1,2,3)
import cats.instances.list._
forall(list)(i => expect(i > 0)) and
forEach(list)(i => expect(i > 0)) and
exists(list)(i => expect(i == 3))
}

Expand Down
33 changes: 17 additions & 16 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@ id: installation
title: Installation
---

All of the artifacts from the table below are:
All of the artifacts below are available for both **JVM and Scala.js**.

1. Available for **Scala 2.12 and 2.13**
2. Available for **JVM and Scala.js**
Note, that artifacts that use Cats Effect 3 are published under a different version to those published for Cats Effect 2 (minor version bump), because they're binary incompatible.

```scala mdoc:passthrough
import weaver.docs._

val effects = Table
.create("Effect types", BuildMatrix.effects)
.render(BuildMatrix.catsEffect3Version)

val integrations = Table
.create("Integrations", BuildMatrix.integrations)
.render(BuildMatrix.catsEffect3Version)
import BuildMatrix._

println(effects)
println(integrations)
val effectsTable = Table
.create("Effect types", effects)
.render(catsEffect3Version, artifactsCE2Version, artifactsCE3Version)

val integrationsTable = Table
.create("Integrations", integrations)
.render(catsEffect3Version, artifactsCE2Version, artifactsCE3Version)

println(effectsTable)
println(integrationsTable)
```

Weaver offers effect-type specific test frameworks. The Build setup depends on
the effect-type library you've elected to use (or test against).

Refer yourself to the library specific pages to get the correct configuration.

* [cats](cats_effect_usage.md)
* [monix](monix_usage.md)
* [monix-bio](monix_bio_usage.md)
* [zio](zio_usage.md)
- [cats](cats_effect_usage.md)
- [monix](monix_usage.md)
- [monix-bio](monix_bio_usage.md)
- [zio](zio_usage.md)
7 changes: 4 additions & 3 deletions modules/core/cats/src-ce2/weaver/BaseIOSuite.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package weaver

import cats.effect.IO
import cats.effect.{ ContextShift, IO, Timer }

trait BaseIOSuite extends RunnableSuite[IO] {
implicit protected def effectCompat: UnsafeRun[IO] = CatsUnsafeRun
final implicit protected def contextShift = effectCompat.contextShift
final implicit protected def timer = effectCompat.timer
final implicit protected def contextShift: ContextShift[IO] =
effectCompat.contextShift
final implicit protected def timer: Timer[IO] = effectCompat.timer
}
1 change: 0 additions & 1 deletion modules/core/src-ce2/weaver/CECompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ private[weaver] trait CECompat {
}
}
}

}
13 changes: 13 additions & 0 deletions modules/core/src-scala-2/Expect.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package weaver

import com.eed3si9n.expecty._

class Expect
extends Recorder[Boolean, Expectations]
with UnaryRecorder[Boolean, Expectations] {

def all(recordings: Boolean*): Expectations =
macro VarargsRecorderMacro.apply[Boolean, Expectations]

override lazy val listener = new ExpectyListener
}
5 changes: 5 additions & 0 deletions modules/core/src-scala-2/ScalaCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package weaver

object ScalaCompat {
def isScala3: Boolean = false
}
49 changes: 49 additions & 0 deletions modules/core/src-scala-2/SourceLocationMacro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package weaver

// kudos to https://github.com/monix/minitest
// format: off
import scala.reflect.macros.whitebox

trait SourceLocationMacro {

import macros._

trait Here {
/**
* Pulls source location without being affected by implicit scope.
*/
def here: SourceLocation = macro Macros.fromContext
}

implicit def fromContext: SourceLocation =
macro Macros.fromContext


}

object macros {
class Macros(val c: whitebox.Context) {
import c.universe._

def fromContext: Tree = {
val (pathExpr, relPathExpr, lineExpr) = getSourceLocation
val SourceLocationSym = symbolOf[SourceLocation].companion
q"""$SourceLocationSym($pathExpr, $relPathExpr, $lineExpr)"""
}

private def getSourceLocation = {
val pwd = java.nio.file.Paths.get("").toAbsolutePath
val p = c.enclosingPosition.source.path
val abstractFile = c.enclosingPosition.source.file

val rp = if (!abstractFile.isVirtual){
pwd.relativize(abstractFile.file.toPath()).toString()
} else p

val line = c.Expr[Int](Literal(Constant(c.enclosingPosition.line)))
(p, rp, line)
}

}
}
// format: on
18 changes: 18 additions & 0 deletions modules/core/src-scala-3/ExpectMacro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package weaver

import cats.data.{ NonEmptyList, ValidatedNel }
import cats.syntax.all._

import com.eed3si9n.expecty._

import scala.quoted._

class Expect
extends Recorder[Boolean, Expectations]
with UnaryRecorder[Boolean, Expectations] {

inline def all(inline recordings: Boolean*): Expectations =
${ RecorderMacro.varargs('recordings, 'listener) }

override lazy val listener = new ExpectyListener
}
Loading

0 comments on commit 663b891

Please sign in to comment.