Skip to content

Commit 21cd65b

Browse files
committed
adding tests for skipping returns + making skipReturnNode step to first interesting bytecode after having skipped the return node
1 parent 9851661 commit 21cd65b

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/Sindarin-Tests/SindarinDebuggerTest.class.st

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ SindarinDebuggerTest >> methodWithSeveralInstructionsInBlock [
145145
^ 42
146146
]
147147

148+
{ #category : #helpers }
149+
SindarinDebuggerTest >> methodWithSeveralReturns [
150+
"There is only one explicit return but there is also an implicit return after `a := 3`. In that sense, there are several returns in this method"
151+
152+
| a |
153+
a := true.
154+
a
155+
ifFalse: [ ^ a := 1 ]
156+
ifTrue: [ a := 2 ].
157+
a := 3
158+
]
159+
148160
{ #category : #helpers }
149161
SindarinDebuggerTest >> methodWithTwoAssignments [
150162

@@ -1311,6 +1323,52 @@ SindarinDebuggerTest >> testSkipBlockNode [
13111323
self assert: scdbg topStack equals: 43
13121324
]
13131325

1326+
{ #category : #tests }
1327+
SindarinDebuggerTest >> testSkipCanSkipReturnIfItIsNotTheLastReturn [
1328+
1329+
| scdbg |
1330+
scdbg := SindarinDebugger debug: [ self methodWithSeveralReturns ].
1331+
1332+
"we step until we arrive on the node `^ a := 1` in `SindarinDebuggerTest>>#methodWithSeveralReturns`."
1333+
scdbg
1334+
step;
1335+
skip;
1336+
skip;
1337+
step.
1338+
1339+
self assert: scdbg node isReturn.
1340+
self assert: scdbg topStack equals: 1.
1341+
1342+
"We skip the return node"
1343+
self shouldnt: [ scdbg skip ] raise: SindarinSkippingReturnWarning.
1344+
1345+
"We should be on the `a := 2` node"
1346+
self assert: scdbg node isAssignment.
1347+
self assert: scdbg node value value equals: 2
1348+
]
1349+
1350+
{ #category : #tests }
1351+
SindarinDebuggerTest >> testSkipCannotSkipReturnIfItIsTheLastReturn [
1352+
1353+
| scdbg nodeWithImplicitReturn |
1354+
scdbg := SindarinDebugger debug: [ self methodWithSeveralReturns ].
1355+
1356+
"we step until we arrive on the method node in `SindarinDebuggerTest>>#methodWithSeveralReturns`, which is mapped to the implicit return bycode."
1357+
scdbg step.
1358+
nodeWithImplicitReturn := scdbg methodNode.
1359+
3 timesRepeat: [ scdbg step ].
1360+
1361+
self assert: scdbg node identicalTo: nodeWithImplicitReturn.
1362+
self assert: scdbg instructionStream willReturn.
1363+
1364+
"We skip the return node"
1365+
self should: [ scdbg skip ] raise: SindarinSkippingReturnWarning.
1366+
1367+
"We should still be on the method node"
1368+
self assert: scdbg node identicalTo: nodeWithImplicitReturn.
1369+
self assert: scdbg instructionStream willReturn
1370+
]
1371+
13141372
{ #category : #tests }
13151373
SindarinDebuggerTest >> testSkipDoesNotSkipReturn [
13161374

src/Sindarin/SindarinDebugger.class.st

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ SindarinDebugger >> skipReturnNode [
437437
"If this is the last node of the method that is mapped to a return bytecode, we can't skip it and we stop there."
438438
node == allReturnNodes last ifTrue: [
439439
^ SindarinSkippingReturnWarning signal:
440-
'Cannot skip the last return in the method' ]
440+
'Cannot skip the last return in the method' ].
441+
442+
self skipPcToNextBytecode.
443+
self debugSession stepToFirstInterestingBytecodeWithJumpIn:
444+
self debugSession interruptedProcess
441445
]
442446

443447
{ #category : #'stepping - skip' }

0 commit comments

Comments
 (0)