Skip to content

Commit 780a6a9

Browse files
committed
Python: Add concept tests
1 parent 41743b6 commit 780a6a9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try:
2+
1+2
3+
except Exception as e: #$ exceptionSource errorInfoSource
4+
e
5+
6+
def test_exception():
7+
try:
8+
1+2
9+
except Exception as e: #$ exceptionSource errorInfoSource
10+
e
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys, traceback
2+
3+
try:
4+
1/0
5+
except:
6+
exc_type, exc_value, exc_traceback = sys.exc_info() #$ errorInfoSource
7+
8+
tb = traceback.extract_tb(exc_traceback) #$ errorInfoSource
9+
stack = traceback.extract_stack() #$ errorInfoSource
10+
print(traceback.format_exc(1, tb)) #$ errorInfoSource
11+
print(traceback.format_exception(exc_type, exc_value, exc_traceback)) #$ errorInfoSource
12+
print(traceback.format_exception_only(None, exc_value)) #$ errorInfoSource
13+
print(traceback.format_list(stack)) #$ errorInfoSource
14+
print(traceback.format_stack()) #$ errorInfoSource
15+
print(traceback.format_tb(exc_traceback)) #$ errorInfoSource

python/ql/test/experimental/meta/ConceptsTest.qll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,35 @@ class SafeAccessCheckTest extends InlineExpectationsTest {
319319
)
320320
}
321321
}
322+
323+
class ErrorInfoSourceTest extends InlineExpectationsTest {
324+
ErrorInfoSourceTest() { this = "ErrorInfoSourceTest" }
325+
326+
override string getARelevantTag() { result = "errorInfoSource" }
327+
328+
override predicate hasActualResult(Location location, string element, string tag, string value) {
329+
exists(location.getFile().getRelativePath()) and
330+
exists(ErrorInfoSource e |
331+
location = e.getLocation() and
332+
element = e.toString() and
333+
value = "" and
334+
tag = "errorInfoSource"
335+
)
336+
}
337+
}
338+
339+
class ExceptionSourceTest extends InlineExpectationsTest {
340+
ExceptionSourceTest() { this = "ExceptionSourceTest" }
341+
342+
override string getARelevantTag() { result = "exceptionSource" }
343+
344+
override predicate hasActualResult(Location location, string element, string tag, string value) {
345+
exists(location.getFile().getRelativePath()) and
346+
exists(ExceptionSource e |
347+
location = e.getLocation() and
348+
element = e.toString() and
349+
value = "" and
350+
tag = "exceptionSource"
351+
)
352+
}
353+
}

0 commit comments

Comments
 (0)