Skip to content

Commit

Permalink
added tests about source positions during runtime error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
rssh committed Oct 17, 2023
1 parent 456179c commit 1e04e2d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
20 changes: 20 additions & 0 deletions shared/src/test/scala/cpstest/stacktraceReporting/SourcePos.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cpstest.stacktraceReporting

import scala.quoted._

case class SourcePos(file: String, line: Int)

object SourcePos {

inline def current: SourcePos =
${ currentImpl }

def currentImpl(using Quotes): Expr[SourcePos] = {
import quotes.reflect._
val pos = Position.ofMacroExpansion
val file = pos.sourceFile.name
val line = pos.startLine + 1 // 1-based
'{ SourcePos(${Expr(file)}, ${Expr(line)}) }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cpstest.stacktraceReporting

import scala.util.*
import cps.*
import org.junit.Test

class TestBasicStacktraceReporting {


@Test
def basicStackTrace() = {
val startPos = SourcePos.current
val c = async[ComputationBound]{
val x = await(T1.cbi(1))
val y = await(T1.cbi(2))
throw new RuntimeException("test")
x+y
}
val endPos = SourcePos.current

val r = c.run()
assert(r.isFailure)
r match
case Failure(ex) =>
//ex.printStackTrace()
//println(s"startPos = ${startPos}")
assert(ex.getStackTrace().exists(_.getLineNumber() == startPos.line + 4))
}


}

0 comments on commit 1e04e2d

Please sign in to comment.