Skip to content

Commit

Permalink
More test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
KuechA committed Sep 20, 2024
1 parent 4c0fbbe commit 7e1adc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ class StatementHandlerTest {

assertEquals(1, tryAll.elseBlock?.statements?.size)
assertEquals(1, tryAll.finallyBlock?.statements?.size)

val tryOnlyFinally = tu.functions["tryOnlyFinally"]?.trys?.singleOrNull()
assertNotNull(tryOnlyFinally)

assertEquals(1, tryOnlyFinally.tryBlock?.statements?.size)

assertEquals(0, tryOnlyFinally.catchClauses.size)

assertNull(tryOnlyFinally.elseBlock)
assertEquals(1, tryOnlyFinally.finallyBlock?.statements?.size)

val tryOnlyExcept = tu.functions["tryOnlyExcept"]?.trys?.singleOrNull()
assertNotNull(tryOnlyExcept)

assertEquals(1, tryOnlyExcept.tryBlock?.statements?.size)

assertEquals(1, tryOnlyExcept.catchClauses.size)
assertNull(tryOnlyExcept.catchClauses.single().parameter)

assertNull(tryOnlyExcept.elseBlock)
assertNull(tryOnlyExcept.finallyBlock)
}

@Test
Expand Down
14 changes: 13 additions & 1 deletion cpg-language-python/src/test/resources/python/try.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,16 @@ def tryAll(a):
else:
print("All good, got " + b)
finally:
print("It's over")
print("It's over")

def tryOnlyFinally(a):
try:
b = a+2
finally:
print("It's over")

def tryOnlyExcept(a):
try:
b = a+2
except:
print("Fail")

0 comments on commit 7e1adc9

Please sign in to comment.