mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Add tests (WIP)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @name Unreachable 'except' block
|
||||
* @name Unreachable `except` block
|
||||
* @description Handling general exceptions before specific exceptions means that the specific
|
||||
* handlers are never executed.
|
||||
* @kind problem
|
||||
@@ -23,7 +23,7 @@ predicate builtinException(string name) {
|
||||
}
|
||||
|
||||
predicate builtinExceptionSubclass(string base, string sub) {
|
||||
typeModel("builtins." + base + "~Subclass", sub, "")
|
||||
typeModel("builtins." + base + "~Subclass", "builtins." + sub, "")
|
||||
}
|
||||
|
||||
newtype TExceptType =
|
||||
@@ -48,7 +48,7 @@ class ExceptType extends TExceptType {
|
||||
DataFlow::Node getAUse() {
|
||||
result = classTracker(this.asClass())
|
||||
or
|
||||
result = API::builtin(this.asBuiltinName()).asSource()
|
||||
API::builtin(this.asBuiltinName()).asSource().flowsTo(result)
|
||||
}
|
||||
|
||||
ExceptType getADirectSuperclass() {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
Exceptions/IncorrectExceptOrder.ql
|
||||
query: Exceptions/IncorrectExceptOrder.ql
|
||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
||||
@@ -61,8 +61,34 @@ try:
|
||||
val.attr
|
||||
except Exception:
|
||||
print (2)
|
||||
except AttributeError:
|
||||
except AttributeError: # $Alert[py/unreachable-except]
|
||||
print (3)
|
||||
|
||||
class MyExc(ValueError):
|
||||
pass
|
||||
|
||||
try:
|
||||
pass
|
||||
except ValueError:
|
||||
pass
|
||||
except MyExc: # $Alert[py/unreachable-except]
|
||||
pass
|
||||
|
||||
class MyBaseExc(Exception):
|
||||
pass
|
||||
|
||||
class MySubExc(MyBaseExc):
|
||||
pass
|
||||
|
||||
try:
|
||||
pass
|
||||
except MyBaseExc:
|
||||
pass
|
||||
except MySubExc: # $Alert[py/unreachable-except]
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
#Catch BaseException
|
||||
def catch_base_exception():
|
||||
|
||||
Reference in New Issue
Block a user