-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
341 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package weaver | ||
|
||
object ScalaCompat { | ||
def isScala3: Boolean = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package weaver | ||
|
||
object ScalaCompat { | ||
def isScala3: Boolean = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.