mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Python: Add concept tests
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user