-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests about source positions during runtime error reporting
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
shared/src/test/scala/cpstest/stacktraceReporting/SourcePos.scala
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,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)}) } | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
shared/src/test/scala/cpstest/stacktraceReporting/TestBasicStacktraceReporting.scala
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,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)) | ||
} | ||
|
||
|
||
} |