C#: Classify test support files in model editor queries

This commit is contained in:
Koen Vlaswinkel
2023-12-19 13:49:53 +01:00
parent 2305d55967
commit d22acfb449
2 changed files with 17 additions and 2 deletions

View File

@@ -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 }

View File

@@ -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
}
}