File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ import scala .quoted .*
2+
3+ case class Position (fileName : String , filePathname : String , lineNumber : Int )
4+
5+ object Position :
6+ def withPosition [T ](fun : Expr [Position => T ])(using quotes : Quotes , typeOfT : Type [T ]): Expr [T ] =
7+ val pos = quotes.reflect.Position .ofMacroExpansion
8+ val file = pos.sourceFile
9+ val fileName : String = Option (file.path).getOrElse(" <unknown>" )
10+ val filePath : String = file.toString
11+ val lineNo : Int = pos.startLine + 1
12+ ' {$ {fun}.apply(Position ($ {Expr (fileName)}, $ {Expr (filePath)}, $ {Expr (lineNo)}))}
Original file line number Diff line number Diff line change 1+ class TestSuite :
2+ protected val it = new ItWord
3+
4+ protected final class ItWord :
5+ def should (string : String ) = new ItVerbString (" should" , string)
6+
7+ private def registerTestToRun (fun : => Any ): Unit = ()
8+
9+ protected final class ItVerbString (verb : String , name : String ):
10+ inline def in (testFun : => Any ): Unit =
11+ $ { Position .withPosition[Unit ](' {(pos : Position ) => registerTestToRun(testFun) }) }
12+
13+ class MyTest extends TestSuite :
14+ it should " not cause outer select errors" in {
15+ assert(1 + 1 == 2 )
16+ }
17+
18+ val n = 10
You can’t perform that action at this time.
0 commit comments