mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Merge pull request #15159 from github/koesie10/csharp-model-editor-tests
C#: Classify test support files in model editor queries
This commit is contained in:
@@ -7,7 +7,7 @@ private import ModelEditor
|
|||||||
* A class of effectively public callables from source code.
|
* A class of effectively public callables from source code.
|
||||||
*/
|
*/
|
||||||
class PublicEndpointFromSource extends Endpoint {
|
class PublicEndpointFromSource extends Endpoint {
|
||||||
PublicEndpointFromSource() { this.fromSource() and not this.getFile() instanceof TestFile }
|
PublicEndpointFromSource() { this.fromSource() and not this.getFile() instanceof TestRelatedFile }
|
||||||
|
|
||||||
override predicate isSource() { this instanceof SourceCallable }
|
override predicate isSource() { this instanceof SourceCallable }
|
||||||
|
|
||||||
|
|||||||
@@ -110,9 +110,9 @@ string supportedType(Endpoint endpoint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string methodClassification(Call method) {
|
string methodClassification(Call method) {
|
||||||
method.getFile() instanceof TestFile and result = "test"
|
method.getFile() instanceof TestRelatedFile and result = "test"
|
||||||
or
|
or
|
||||||
not method.getFile() instanceof TestFile and
|
not method.getFile() instanceof TestRelatedFile and
|
||||||
result = "source"
|
result = "source"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,3 +129,13 @@ private string qualifiedTypeName(string namespace, Type t) {
|
|||||||
private string qualifiedCallableName(string namespace, string type, Callable c) {
|
private string qualifiedCallableName(string namespace, string type, Callable c) {
|
||||||
exists(string name | hasQualifiedMethodName(c, namespace, type, name) | result = name)
|
exists(string name | hasQualifiedMethodName(c, namespace, type, name) | result = name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A file that is either a test file or is only used in tests. */
|
||||||
|
class TestRelatedFile extends File {
|
||||||
|
TestRelatedFile() {
|
||||||
|
this instanceof TestFile
|
||||||
|
or
|
||||||
|
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