Skip to content

Commit 32d1f05

Browse files
authored
Merge pull request #15159 from github/koesie10/csharp-model-editor-tests
C#: Classify test support files in model editor queries
2 parents 6831775 + d09fadf commit 32d1f05

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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() { this.fromSource() and not this.getFile() instanceof TestRelatedFile }
1111

1212
override predicate isSource() { this instanceof SourceCallable }
1313

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

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

112112
string methodClassification(Call method) {
113-
method.getFile() instanceof TestFile and result = "test"
113+
method.getFile() instanceof TestRelatedFile and result = "test"
114114
or
115-
not method.getFile() instanceof TestFile and
115+
not method.getFile() instanceof TestRelatedFile and
116116
result = "source"
117117
}
118118

@@ -129,3 +129,13 @@ private string qualifiedTypeName(string namespace, Type t) {
129129
private string qualifiedCallableName(string namespace, string type, Callable c) {
130130
exists(string name | hasQualifiedMethodName(c, namespace, type, name) | result = name)
131131
}
132+
133+
/** A file that is either a test file or is only used in tests. */
134+
class TestRelatedFile extends File {
135+
TestRelatedFile() {
136+
this instanceof TestFile
137+
or
138+
this.getAbsolutePath().matches(["%/test/%", "%/tests/%"]) and
139+
not this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
140+
}
141+
}

0 commit comments

Comments
 (0)