diff --git a/shared/src/test/scala/cpstest/stacktraceReporting/SourcePos.scala b/shared/src/test/scala/cpstest/stacktraceReporting/SourcePos.scala new file mode 100644 index 00000000..1c4ea94d --- /dev/null +++ b/shared/src/test/scala/cpstest/stacktraceReporting/SourcePos.scala @@ -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)}) } + } + +} diff --git a/shared/src/test/scala/cpstest/stacktraceReporting/TestBasicStacktraceReporting.scala b/shared/src/test/scala/cpstest/stacktraceReporting/TestBasicStacktraceReporting.scala new file mode 100644 index 00000000..9d6ace7c --- /dev/null +++ b/shared/src/test/scala/cpstest/stacktraceReporting/TestBasicStacktraceReporting.scala @@ -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)) + } + + +}