Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ trait AlignmentManager:
val currentPath = Path(stack.toSeq*)
val invocationCount = trace.get(currentPath).map(_ + 1).getOrElse(0)
stack.push(InvocationCoordinate(key, invocationCount))
val result = body()
val _ = stack.pop()
trace.update(currentPath, invocationCount)
result
try body()
finally
val _ = stack.pop()
trace.update(currentPath, invocationCount)
end AlignmentManager
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package it.unibo.scafi.utils

import it.unibo.scafi.message.Path

import org.scalatest.flatspec.AnyFlatSpecLike
import org.scalatest.matchers.should

class AlignmentManagerTest extends AnyFlatSpecLike, should.Matchers:
private class Probe extends AlignmentManager:
def path: Path = currentPath
def scope[A](key: String)(body: => A): A = alignmentScope(key)(() => body)

"AlignmentManager" should "restore the stack when an aligned body throws" in:
val probe = Probe()

assertThrows[RuntimeException]:
probe.scope("outer"):
probe.scope("inner"):
throw RuntimeException("boom")

probe.path shouldBe empty

val nextPath = probe.scope("next")(probe.path)
nextPath.map(_.key) shouldBe Seq("next")
end AlignmentManagerTest
Loading