@@ -50,7 +50,7 @@ class ResourceTest extends AnyFlatSpec with Matchers:
5050 trail.get shouldBe Vector (" allocate 1" , " allocate 2" , " release 2" , " release 1" , " exception" )
5151 }
5252
53- it should " release resources when there's an exception during releasing" in {
53+ it should " release resources when there's an exception during releasing (normal resutl) " in {
5454 val trail = Trail ()
5555
5656 try
@@ -60,22 +60,50 @@ class ResourceTest extends AnyFlatSpec with Matchers:
6060 1
6161 } { n =>
6262 trail.add(s " release $n" )
63- throw new RuntimeException ()
63+ throw new RuntimeException (" e1 " )
6464 }
6565 val r2 = useInScope {
6666 trail.add(" allocate 2" );
6767 2
6868 } { n =>
6969 trail.add(s " release $n" )
70- throw new RuntimeException ()
70+ throw new RuntimeException (" e2 " )
7171 }
7272 r1 shouldBe 1
7373 r2 shouldBe 2
74- throw new RuntimeException
74+ r1 + r2
7575 }
76- catch case _ => trail.add(" exception" )
76+ catch case e => trail.add(s " exception ${e.getMessage} " )
7777 end try
78- trail.get shouldBe Vector (" allocate 1" , " allocate 2" , " release 2" , " release 1" , " exception" )
78+ trail.get shouldBe Vector (" allocate 1" , " allocate 2" , " release 2" , " release 1" , " exception e2" )
79+ }
80+
81+ it should " release resources when there's an exception during releasing (exceptional resutl)" in {
82+ val trail = Trail ()
83+
84+ try
85+ unsupervised {
86+ val r1 = useInScope {
87+ trail.add(" allocate 1" );
88+ 1
89+ } { n =>
90+ trail.add(s " release $n" )
91+ throw new RuntimeException (" e1" )
92+ }
93+ val r2 = useInScope {
94+ trail.add(" allocate 2" );
95+ 2
96+ } { n =>
97+ trail.add(s " release $n" )
98+ throw new RuntimeException (" e2" )
99+ }
100+ r1 shouldBe 1
101+ r2 shouldBe 2
102+ throw new RuntimeException (" e3" )
103+ }
104+ catch case e => trail.add(s " exception ${e.getMessage}" )
105+ end try
106+ trail.get shouldBe Vector (" allocate 1" , " allocate 2" , " release 2" , " release 1" , " exception e3" )
79107 }
80108
81109 it should " release registered resources" in {
0 commit comments