Skip to content

Commit

Permalink
Merge pull request #265 from gabro/scala-3.0.0-M2
Browse files Browse the repository at this point in the history
  • Loading branch information
gabro authored Nov 25, 2020
2 parents b5ceed4 + 3ca8ba8 commit 576b50c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ assumeStandardLibraryStripMargin = true
docstrings = JavaDoc
project.git=true
project.excludeFilters = [
".*scala-3"
".*scala-3*"
"LinesSuite.scala"
]
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def previousVersion = "0.7.0"
def scala213 = "2.13.2"
def scala212 = "2.12.11"
def scala211 = "2.11.12"
def scala3Stable = "3.0.0-M1"
def scala3Previous = "0.27.0-RC1"
def scala3Stable = "3.0.0-M2"
def scala3Previous = List("3.0.0-M1", "0.27.0-RC1")
def junitVersion = "4.13"
def gcp = "com.google.cloud" % "google-cloud-storage" % "1.113.4"
inThisBuild(
Expand Down Expand Up @@ -61,7 +61,7 @@ addCommandAlias(
)
val isPreScala213 = Set[Option[(Long, Long)]](Some((2, 11)), Some((2, 12)))
val scala2Versions = List(scala213, scala212, scala211)
val scala3Versions = List(scala3Previous, scala3Stable)
val scala3Versions = scala3Stable :: scala3Previous
val allScalaVersions = scala2Versions ++ scala3Versions
def isNotScala211(v: Option[(Long, Long)]): Boolean = !v.contains((2, 11))
def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2)
Expand Down Expand Up @@ -316,7 +316,7 @@ lazy val docs = project
mdocVariables := Map(
"VERSION" -> version.value.replaceFirst("\\+.*", ""),
"SCALA3_PREVIOUS_VERSION" -> scala3Stable,
"SCALA3_STABLE_VERSION" -> scala3Stable,
"SCALA3_STABLE_VERSION" -> scala3Previous.head,
"SUPPORTED_SCALA_VERSIONS" -> allScalaVersions.mkString(", ")
),
fork := false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package munit.internal

import munit.Clue
import munit.Location
import scala.quoted._

object MacroCompat {

trait LocationMacro {
inline implicit def generate: Location = ${ locationImpl() }
}

def locationImpl()(using qctx: QuoteContext): Expr[Location] = {
import qctx.reflect.{_, given}
val path = rootPosition.sourceFile.jpath.toString
val startLine = rootPosition.startLine + 1
'{ new Location(${Expr(path)}, ${Expr(startLine)}) }
}

trait ClueMacro {
inline implicit def generate[T](value: T): Clue[T] = ${ clueImpl('value) }
}

def clueImpl[T:Type](value: Expr[T])(using qctx: QuoteContext): Expr[Clue[T]] = {
import qctx.reflect.{_, given}
val source = value.unseal.pos.sourceCode
val valueType = implicitly[scala.quoted.Type[T]].show
'{ new Clue(${Expr(source)}, $value, ${Expr(valueType)}) }
}

trait CompileErrorMacro {
inline def compileErrors(inline code: String): String = {
val errors = scala.compiletime.testing.typeCheckErrors(code)
errors.map { error =>
val indent = " " * (error.column - 1)
val trimMessage = error.message.linesIterator.map { line =>
if (line.matches(" +")) ""
else line
}.mkString("\n")
val separator = if (error.message.contains('\n')) "\n" else " "
s"error:${separator}${trimMessage}\n${error.lineContent}\n${indent}^"
}.mkString("\n")
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package munit.internal

import munit.Clue
import munit.Location
import scala.quoted._

object MacroCompat {

trait LocationMacro {
inline implicit def generate: Location = ${ locationImpl() }
}

def locationImpl()(using Quotes): Expr[Location] = {
import quotes.reflect._
val pos = Position.ofMacroExpansion
val path = pos.sourceFile.jpath.toString
val startLine = pos.startLine + 1
'{ new Location(${Expr(path)}, ${Expr(startLine)}) }
}

trait ClueMacro {
inline implicit def generate[T](value: T): Clue[T] = ${ clueImpl('value) }
}

def clueImpl[T: Type](value: Expr[T])(using Quotes): Expr[Clue[T]] = {
import quotes.reflect._
val source = Term.of(value).pos.sourceCode
val valueType = Type.show[T]
'{ new Clue(${Expr(source)}, $value, ${Expr(valueType)}) }
}

trait CompileErrorMacro {
inline def compileErrors(inline code: String): String = {
val errors = scala.compiletime.testing.typeCheckErrors(code)
errors.map { error =>
val indent = " " * (error.column - 1)
val trimMessage = error.message.linesIterator.map { line =>
if (line.matches(" +")) ""
else line
}.mkString("\n")
val separator = if (error.message.contains('\n')) "\n" else " "
s"error:${separator}${trimMessage}\n${error.lineContent}\n${indent}^"
}.mkString("\n")
}
}

}

0 comments on commit 576b50c

Please sign in to comment.