Skip to content

Commit d22acfb

Browse files
committed
C#: Classify test support files in model editor queries
1 parent 2305d55 commit d22acfb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

csharp/ql/src/utils/modeleditor/FrameworkModeEndpointsQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ private import ModelEditor
77
* A class of effectively public callables from source code.
88
*/
99
class PublicEndpointFromSource extends Endpoint {
10-
PublicEndpointFromSource() { this.fromSource() and not this.getFile() instanceof TestFile }
10+
PublicEndpointFromSource() {
11+
this.fromSource() and
12+
not this.getFile() instanceof TestFile and
13+
not this.getFile() instanceof TestSupportFile
14+
}
1115

1216
override predicate isSource() { this instanceof SourceCallable }
1317

csharp/ql/src/utils/modeleditor/ModelEditor.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ string supportedType(Endpoint endpoint) {
110110
}
111111

112112
string methodClassification(Call method) {
113-
method.getFile() instanceof TestFile and result = "test"
113+
(method.getFile() instanceof TestFile or method.getFile() instanceof TestSupportFile) and
114+
result = "test"
114115
or
115116
not method.getFile() instanceof TestFile and
117+
not method.getFile() instanceof TestSupportFile and
116118
result = "source"
117119
}
118120

@@ -129,3 +131,12 @@ private string qualifiedTypeName(string namespace, Type t) {
129131
private string qualifiedCallableName(string namespace, string type, Callable c) {
130132
exists(string name | hasQualifiedMethodName(c, namespace, type, name) | result = name)
131133
}
134+
135+
/** A file that doesn't contain tests itself, but is only used in tests. */
136+
class TestSupportFile extends File {
137+
TestSupportFile() {
138+
not this instanceof TestFile and
139+
this.getAbsolutePath().matches(["%/test/%", "%/tests/%"]) and
140+
not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
141+
}
142+
}

0 commit comments

Comments
 (0)