Skip to content

Commit

Permalink
WIP-Scala 3.0.0-M3
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Dec 22, 2020
1 parent d146d21 commit 8620d9d
Show file tree
Hide file tree
Showing 30 changed files with 341 additions and 121 deletions.
53 changes: 32 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ lazy val allModules = Seq(
effectFrameworks
).flatten

lazy val catsEffect3Version = "3.0.0-M4"
lazy val catsEffect3Version = "3.0.0-M5"

def catsEffectDependencies(proj: Project): Project = {
proj.settings(
libraryDependencies ++= {
if (virtualAxes.value.contains(CatsEffect2Axis))
Seq(
"co.fs2" %%% "fs2-core" % "2.4.6",
"co.fs2" %%% "fs2-core" % "2.5.0",
"org.typelevel" %%% "cats-effect" % "2.3.1"
)
else
Seq(
"co.fs2" %%% "fs2-core" % "3.0.0-M6",
"co.fs2" %%% "fs2-core" % "3.0.0-M7",
"org.typelevel" %%% "cats-effect" % catsEffect3Version
)
}
Expand All @@ -75,17 +75,20 @@ lazy val core = projectMatrix
.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.14.1-SNAPSHOT",
("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.0.0").withDottyCompat(
scalaVersion.value)
)
}
}
Expand All @@ -109,7 +112,7 @@ val allIntegrationsCoresFilter: ScopeFilter =

lazy val docs = projectMatrix
.in(file("modules/docs"))
.jvmPlatform(WeaverPlugin.supportedScalaVersions)
.jvmPlatform(WeaverPlugin.suppertedScala2Versions)
.enablePlugins(DocusaurusPlugin, MdocPlugin)
.dependsOn(core, scalacheck, cats, zio, monix, monixBio, specs2)
.settings(
Expand Down Expand Up @@ -182,13 +185,16 @@ lazy val framework = projectMatrix
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.0.0" % Test).withDottyCompat(
scalaVersion.value)
)
}
)
Expand Down Expand Up @@ -217,7 +223,8 @@ lazy val specs2 = projectMatrix
name := "specs2",
testFrameworks := Seq(new TestFramework("weaver.framework.CatsEffect")),
libraryDependencies ++= Seq(
"org.specs2" %%% "specs2-matcher" % "4.10.5"
("org.specs2" %%% "specs2-matcher" % "4.10.5").withDottyCompat(
scalaVersion.value)
)
)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -239,7 +246,7 @@ lazy val coreCats = projectMatrix

lazy val coreMonix = projectMatrix
.in(file("modules/core/monix"))
.onlyCatsEffect2()
.onlyCatsEffect2(onlyScala2 = true)
.dependsOn(core)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -252,7 +259,7 @@ lazy val coreMonix = projectMatrix

lazy val coreMonixBio = projectMatrix
.in(file("modules/core/monixBio"))
.onlyCatsEffect2()
.onlyCatsEffect2(onlyScala2 = true)
.dependsOn(core)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -265,7 +272,7 @@ lazy val coreMonixBio = projectMatrix

lazy val coreZio = projectMatrix
.in(file("modules/core/zio"))
.onlyCatsEffect2()
.onlyCatsEffect2(onlyScala2 = true)
.dependsOn(core)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand Down Expand Up @@ -296,12 +303,16 @@ lazy val cats = projectMatrix
.settings(
name := "cats",
testFrameworks := Seq(new TestFramework("weaver.framework.CatsEffect")),
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.0.0" % Test
libraryDependencies += {
// if(virtualAxes.contains(VirtualAxis.js))
("io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.0.0" % Test).withDottyCompat(
scalaVersion.value)
}
)

lazy val monix = projectMatrix
.in(file("modules/framework/monix"))
.onlyCatsEffect2()
.onlyCatsEffect2(onlyScala2 = true)
.dependsOn(framework, coreMonix)
.configure(WeaverPlugin.profile)
.settings(WeaverPlugin.simpleLayout)
Expand All @@ -312,7 +323,7 @@ lazy val monix = projectMatrix

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

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

lazy val intellijRunner = projectMatrix
.onlyCatsEffect2(withJs = false)
.onlyCatsEffect2(withJs = false, onlyScala2 = true)
.in(file("modules/intellij-runner"))
.dependsOn(core, framework, framework % "test->compile")
.configure(WeaverPlugin.profile)
Expand Down
6 changes: 4 additions & 2 deletions modules/core/cats/src-ce2/weaver/BaseIOSuite.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package weaver

import cats.effect.IO
import cats.effect.ContextShift
import cats.effect.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
}
22 changes: 22 additions & 0 deletions modules/core/src-ce2/weaver/CECompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package weaver
import cats.effect.Concurrent
import cats.effect.ExitCase.{ Canceled, Completed }
import cats.effect.syntax.all._
import cats.syntax.all._
import cats.effect.Resource
import cats.Applicative

private[weaver] object CECompat extends CECompat

Expand Down Expand Up @@ -34,4 +37,23 @@ private[weaver] trait CECompat {
f: F[A] => F[B]): F[B] =
fa.background.use(f)

private[weaver] def resourceLift[F[_]: Applicative, A](
fa: F[A]): Resource[F, A] = Resource.liftF(fa)

private[weaver] trait Queue[F[_], A] {
protected def fs2Queue: fs2.concurrent.Queue[F, A]

def enqueue(a: A): F[Unit] = fs2Queue.enqueue1(a)
def dequeueStream: fs2.Stream[F, A] = fs2Queue.dequeue
}

private[weaver] object Queue {
def unbounded[F[_]: Concurrent, A] =
fs2.concurrent.Queue.unbounded[F, A].map {
q =>
new Queue[F, A] {
override val fs2Queue = q
}
}
}
}
23 changes: 23 additions & 0 deletions modules/core/src-ce3/weaver/CECompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package weaver
import cats.effect.Async
import cats.effect.syntax.all._
import cats.syntax.all._
import cats.effect.Resource
import cats.Applicative
import cats.effect.kernel.GenConcurrent

private[weaver] object CECompat extends CECompat

Expand Down Expand Up @@ -32,4 +35,24 @@ private[weaver] trait CECompat {
fa.background.use(fOutcome =>
f(fOutcome.flatMap(_.embed(onCancel = Async[F].pure(default)))))

private[weaver] def resourceLift[F[_]: Applicative, A](
fa: F[A]): Resource[F, A] = Resource.eval(fa)

private[weaver] trait Queue[F[_], A] {
protected def ceQueue: cats.effect.std.Queue[F, A]

def enqueue(a: A): F[Unit] = ceQueue.offer(a)
def dequeueStream: fs2.Stream[F, A] = fs2.Stream.repeatEval(ceQueue.take)
}

object Queue {
def unbounded[F[_], A](implicit gc: GenConcurrent[F, _]) =
cats.effect.std.Queue.unbounded[F, A].map {
q =>
new Queue[F, A] {
override val ceQueue = q
}
}
}

}
2 changes: 1 addition & 1 deletion modules/core/src-js/PlatformCompat.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package weaver

private[weaver] object PlatformCompat {
private[weaver] object PlatformCompat {
val platform: Platform = Platform.JS

def getClassLoader(clazz: java.lang.Class[_]): ClassLoader =
Expand Down
16 changes: 16 additions & 0 deletions modules/core/src-scala-2/Expect.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package weaver

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

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
}
5 changes: 5 additions & 0 deletions modules/core/src-scala-3/ScalaCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package weaver

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

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

import scala.quoted._

trait SourceLocationMacro {
trait Here {
/**
* Pulls source location without being affected by implicit scope.
*/
inline def here: SourceLocation = ${macros.fromContextImpl}
}

implicit inline def fromContext: SourceLocation = ${macros.fromContextImpl}
}

object macros {
def fromContextImpl(using ctx: Quotes): Expr[SourceLocation] = {
import ctx.reflect.Position._
import ctx.reflect._

val pwd = java.nio.file.Paths.get("").toAbsolutePath

val position = Position.ofMacroExpansion

val rp = Expr(pwd.relativize(position.sourceFile.jpath).toString)
val absPath = Expr(position.sourceFile.jpath.toAbsolutePath.toString)
val l = Expr(position.startLine + 1)

'{new SourceLocation($absPath, $rp, $l) }
}
}

// format: on
Loading

0 comments on commit 8620d9d

Please sign in to comment.