mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
C#: Classify test support files in model editor queries
This commit is contained in:
@@ -7,7 +7,11 @@ private import ModelEditor
|
||||
* A class of effectively public callables from source code.
|
||||
*/
|
||||
class PublicEndpointFromSource extends Endpoint {
|
||||
PublicEndpointFromSource() { this.fromSource() and not this.getFile() instanceof TestFile }
|
||||
PublicEndpointFromSource() {
|
||||
this.fromSource() and
|
||||
not this.getFile() instanceof TestFile and
|
||||
not this.getFile() instanceof TestSupportFile
|
||||
}
|
||||
|
||||
override predicate isSource() { this instanceof SourceCallable }
|
||||
|
||||
|
||||
@@ -110,9 +110,11 @@ string supportedType(Endpoint endpoint) {
|
||||
}
|
||||
|
||||
string methodClassification(Call method) {
|
||||
method.getFile() instanceof TestFile and result = "test"
|
||||
(method.getFile() instanceof TestFile or method.getFile() instanceof TestSupportFile) and
|
||||
result = "test"
|
||||
or
|
||||
not method.getFile() instanceof TestFile and
|
||||
not method.getFile() instanceof TestSupportFile and
|
||||
result = "source"
|
||||
}
|
||||
|
||||
@@ -129,3 +131,12 @@ private string qualifiedTypeName(string namespace, Type t) {
|
||||
private string qualifiedCallableName(string namespace, string type, Callable c) {
|
||||
exists(string name | hasQualifiedMethodName(c, namespace, type, name) | result = name)
|
||||
}
|
||||
|
||||
/** A file that doesn't contain tests itself, but is only used in tests. */
|
||||
class TestSupportFile extends File {
|
||||
TestSupportFile() {
|
||||
not this instanceof TestFile and
|
||||
this.getAbsolutePath().matches(["%/test/%", "%/tests/%"]) and
|
||||
not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user