Skip to content

QL4QL: Exclude PrintAst like tests from being reported as having missing InlineExpectations. #19104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ql/ql/src/codeql_ql/ast/Yaml.qll
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,15 @@ class QlRefDocument extends YamlDocument {
value = n.lookup("postprocess").(YamlSequence).getElement(_)
)
}

predicate isPrintAst() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more ambitious solution would be to resolve the the query pointed to by the .qlref file, and then only flag cases where the query has kind problem or path-problem, but we can leave that for a future improvement.

this.getFile().getStem() = "PrintAst"
or
exists(YamlMapping n, YamlScalar value |
n.getDocument() = this and
value.getValue().matches("%PrintAst%")
|
value = n.lookup("query")
)
Comment on lines +71 to +76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that this is for .qlref files.
And maybe check that the file-extension is .qlref?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! That is included in the char pred and description of the class QlRefDocument. Is that acceptable?
However, I do need to add a comment for the predicate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't notice that context.

LGTM 👍

}
}
4 changes: 3 additions & 1 deletion ql/ql/src/queries/style/QlRefInlineExpectations.ql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ import ql
import codeql_ql.ast.Yaml

from QlRefDocument f
where not f.usesInlineExpectations()
where
not f.usesInlineExpectations() and
not f.isPrintAst()
select f, "Query test does not use inline test expectations."
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy/PrintAst.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
query: dummy/PrintAst.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select ""
Loading