Python: Add concept tests

This commit is contained in:
Rasmus Lerchedahl Petersen
2021-02-25 08:54:42 +01:00
parent 41743b6afa
commit 780a6a96f8
3 changed files with 57 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
try:
1+2
except Exception as e: #$ exceptionSource errorInfoSource
e
def test_exception():
try:
1+2
except Exception as e: #$ exceptionSource errorInfoSource
e

View File

@@ -0,0 +1,15 @@
import sys, traceback
try:
1/0
except:
exc_type, exc_value, exc_traceback = sys.exc_info() #$ errorInfoSource
tb = traceback.extract_tb(exc_traceback) #$ errorInfoSource
stack = traceback.extract_stack() #$ errorInfoSource
print(traceback.format_exc(1, tb)) #$ errorInfoSource
print(traceback.format_exception(exc_type, exc_value, exc_traceback)) #$ errorInfoSource
print(traceback.format_exception_only(None, exc_value)) #$ errorInfoSource
print(traceback.format_list(stack)) #$ errorInfoSource
print(traceback.format_stack()) #$ errorInfoSource
print(traceback.format_tb(exc_traceback)) #$ errorInfoSource

View File

@@ -319,3 +319,35 @@ class SafeAccessCheckTest extends InlineExpectationsTest {
)
}
}
class ErrorInfoSourceTest extends InlineExpectationsTest {
ErrorInfoSourceTest() { this = "ErrorInfoSourceTest" }
override string getARelevantTag() { result = "errorInfoSource" }
override predicate hasActualResult(Location location, string element, string tag, string value) {
exists(location.getFile().getRelativePath()) and
exists(ErrorInfoSource e |
location = e.getLocation() and
element = e.toString() and
value = "" and
tag = "errorInfoSource"
)
}
}
class ExceptionSourceTest extends InlineExpectationsTest {
ExceptionSourceTest() { this = "ExceptionSourceTest" }
override string getARelevantTag() { result = "exceptionSource" }
override predicate hasActualResult(Location location, string element, string tag, string value) {
exists(location.getFile().getRelativePath()) and
exists(ExceptionSource e |
location = e.getLocation() and
element = e.toString() and
value = "" and
tag = "exceptionSource"
)
}
}