Skip to content

Commit ce5f119

Browse files
committed
Ql4Ql: Share the definition of TestFile between multiple tests.
1 parent 033ea97 commit ce5f119

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

ql/ql/src/codeql/files/FileSystem.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ class File extends Container, Impl::File {
6161
/** Holds if this file was extracted from ordinary source code. */
6262
predicate fromSource() { any() }
6363
}
64+
65+
/** A test file. */
66+
class TestFile extends File {
67+
TestFile() { this.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%") }
68+
}

ql/ql/src/queries/style/MissingQualityMetadata.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
import ql
1212

13-
private predicate unInterestingLocation(File f) {
14-
f.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%")
15-
}
16-
1713
private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" }
1814

1915
private predicate incorrectTopLevelCategorisation(QueryDoc doc) {
@@ -31,7 +27,7 @@ private predicate maintainabilitySubCategory(QueryDoc doc) {
3127
from TopLevel t, QueryDoc doc, string msg
3228
where
3329
doc = t.getQLDoc() and
34-
not unInterestingLocation(t.getLocation().getFile()) and
30+
not t.getLocation().getFile() instanceof TestFile and
3531
hasQualityTag(doc) and
3632
(
3733
incorrectTopLevelCategorisation(doc) and

ql/ql/src/queries/style/MissingSecurityMetadata.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
import ql
1212

13-
private predicate unInterestingLocation(File f) {
14-
f.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%")
15-
}
16-
1713
predicate missingSecuritySeverity(QueryDoc doc) {
1814
doc.getQueryTags() = "security" and
1915
exists(doc.getQueryPrecision()) and
@@ -29,7 +25,7 @@ predicate missingSecurityTag(QueryDoc doc) {
2925
from TopLevel t, QueryDoc doc, string msg
3026
where
3127
doc = t.getQLDoc() and
32-
not unInterestingLocation(t.getLocation().getFile()) and
28+
not t.getLocation().getFile() instanceof TestFile and
3329
(
3430
missingSecuritySeverity(doc) and
3531
msg = "This query file is missing a `@security-severity` tag."

0 commit comments

Comments
 (0)