Ql4Ql: Share the definition of TestFile between multiple tests.

This commit is contained in:
Michael Nebel
2025-07-01 09:42:20 +02:00
parent 60a1d02357
commit af1c4e0896
3 changed files with 7 additions and 10 deletions

View File

@@ -61,3 +61,8 @@ class File extends Container, Impl::File {
/** Holds if this file was extracted from ordinary source code. */ /** Holds if this file was extracted from ordinary source code. */
predicate fromSource() { any() } predicate fromSource() { any() }
} }
/** A test file. */
class TestFile extends File {
TestFile() { this.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%") }
}

View File

@@ -10,10 +10,6 @@
import ql import ql
private predicate unInterestingLocation(File f) {
f.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%")
}
private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" } private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" }
private predicate incorrectTopLevelCategorisation(QueryDoc doc) { private predicate incorrectTopLevelCategorisation(QueryDoc doc) {
@@ -31,7 +27,7 @@ private predicate maintainabilitySubCategory(QueryDoc doc) {
from TopLevel t, QueryDoc doc, string msg from TopLevel t, QueryDoc doc, string msg
where where
doc = t.getQLDoc() and doc = t.getQLDoc() and
not unInterestingLocation(t.getLocation().getFile()) and not t.getLocation().getFile() instanceof TestFile and
hasQualityTag(doc) and hasQualityTag(doc) and
( (
incorrectTopLevelCategorisation(doc) and incorrectTopLevelCategorisation(doc) and

View File

@@ -10,10 +10,6 @@
import ql import ql
private predicate unInterestingLocation(File f) {
f.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%")
}
predicate missingSecuritySeverity(QueryDoc doc) { predicate missingSecuritySeverity(QueryDoc doc) {
doc.getQueryTags() = "security" and doc.getQueryTags() = "security" and
exists(doc.getQueryPrecision()) and exists(doc.getQueryPrecision()) and
@@ -29,7 +25,7 @@ predicate missingSecurityTag(QueryDoc doc) {
from TopLevel t, QueryDoc doc, string msg from TopLevel t, QueryDoc doc, string msg
where where
doc = t.getQLDoc() and doc = t.getQLDoc() and
not unInterestingLocation(t.getLocation().getFile()) and not t.getLocation().getFile() instanceof TestFile and
( (
missingSecuritySeverity(doc) and missingSecuritySeverity(doc) and
msg = "This query file is missing a `@security-severity` tag." msg = "This query file is missing a `@security-severity` tag."