From 2a8a8224f171bddaea41e61c0b2c8bd5f2531e94 Mon Sep 17 00:00:00 2001 From: Michael Nebel <michaelnebel@github.com> Date: Mon, 24 Mar 2025 15:08:45 +0100 Subject: [PATCH 1/3] Ql4Ql: Add PrintAst test case for QlRefInlineExpectations. --- .../queries/style/QlRefInlineExpectations/PrintAst.expected | 1 + ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.qlref | 1 + .../QlRefInlineExpectations/QlRefInlineExpectations.expected | 2 ++ ql/ql/test/queries/style/QlRefInlineExpectations/Test4.expected | 1 + ql/ql/test/queries/style/QlRefInlineExpectations/Test4.qlref | 1 + .../style/QlRefInlineExpectations/dummy/PrintAst.expected | 1 + .../queries/style/QlRefInlineExpectations/dummy/PrintAst.ql | 1 + 7 files changed, 8 insertions(+) create mode 100644 ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.expected create mode 100644 ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.qlref create mode 100644 ql/ql/test/queries/style/QlRefInlineExpectations/Test4.expected create mode 100644 ql/ql/test/queries/style/QlRefInlineExpectations/Test4.qlref create mode 100644 ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.expected create mode 100644 ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.ql diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.expected b/ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.expected new file mode 100644 index 000000000000..14a5f4f77197 --- /dev/null +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.expected @@ -0,0 +1 @@ +| | diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.qlref b/ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.qlref new file mode 100644 index 000000000000..b6fe7e93204a --- /dev/null +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/PrintAst.qlref @@ -0,0 +1 @@ +dummy/PrintAst.ql diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected b/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected index 7dd57a3ef860..44094970f1ff 100644 --- a/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected @@ -1,2 +1,4 @@ +| PrintAst.qlref:1:1:1:17 | dummy/PrintAst.ql | Query test does not use inline test expectations. | | QlRefInlineExpectations.qlref:1:1:1:40 | queries ... ions.ql | Query test does not use inline test expectations. | | Test3.qlref:1:1:1:39 | query: ... ists.ql | Query test does not use inline test expectations. | +| Test4.qlref:1:1:1:25 | query: ... tAst.ql | Query test does not use inline test expectations. | diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/Test4.expected b/ql/ql/test/queries/style/QlRefInlineExpectations/Test4.expected new file mode 100644 index 000000000000..14a5f4f77197 --- /dev/null +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/Test4.expected @@ -0,0 +1 @@ +| | diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/Test4.qlref b/ql/ql/test/queries/style/QlRefInlineExpectations/Test4.qlref new file mode 100644 index 000000000000..43dd92b5c777 --- /dev/null +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/Test4.qlref @@ -0,0 +1 @@ +query: dummy/PrintAst.ql diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.expected b/ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.expected new file mode 100644 index 000000000000..14a5f4f77197 --- /dev/null +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.expected @@ -0,0 +1 @@ +| | diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.ql b/ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.ql new file mode 100644 index 000000000000..205315977441 --- /dev/null +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/dummy/PrintAst.ql @@ -0,0 +1 @@ +select "" From 7dda951a51449f41973c768815d30c1b2a7aba58 Mon Sep 17 00:00:00 2001 From: Michael Nebel <michaelnebel@github.com> Date: Mon, 24 Mar 2025 16:20:51 +0100 Subject: [PATCH 2/3] Ql4Ql: Exclude files named PrintAst.qlref and qlref files that uses a query with a PrintAst name from QlRefInlineExpectations. --- ql/ql/src/codeql_ql/ast/Yaml.qll | 11 +++++++++++ ql/ql/src/queries/style/QlRefInlineExpectations.ql | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ql/ql/src/codeql_ql/ast/Yaml.qll b/ql/ql/src/codeql_ql/ast/Yaml.qll index 142820226a41..d5e80365ff4a 100644 --- a/ql/ql/src/codeql_ql/ast/Yaml.qll +++ b/ql/ql/src/codeql_ql/ast/Yaml.qll @@ -64,4 +64,15 @@ class QlRefDocument extends YamlDocument { value = n.lookup("postprocess").(YamlSequence).getElement(_) ) } + + predicate isPrintAst() { + this.getFile().getStem() = "PrintAst" + or + exists(YamlMapping n, YamlScalar value | + n.getDocument() = this and + value.getValue().matches("%PrintAst%") + | + value = n.lookup("query") + ) + } } diff --git a/ql/ql/src/queries/style/QlRefInlineExpectations.ql b/ql/ql/src/queries/style/QlRefInlineExpectations.ql index 870dd0f437c9..66c139f683f6 100644 --- a/ql/ql/src/queries/style/QlRefInlineExpectations.ql +++ b/ql/ql/src/queries/style/QlRefInlineExpectations.ql @@ -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." From be4c9d8815bcb134f3f340a7ba291849a47a4c1b Mon Sep 17 00:00:00 2001 From: Michael Nebel <michaelnebel@github.com> Date: Mon, 24 Mar 2025 16:23:55 +0100 Subject: [PATCH 3/3] Ql4Ql: Update test expected file. --- .../QlRefInlineExpectations/QlRefInlineExpectations.expected | 2 -- 1 file changed, 2 deletions(-) diff --git a/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected b/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected index 44094970f1ff..7dd57a3ef860 100644 --- a/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected +++ b/ql/ql/test/queries/style/QlRefInlineExpectations/QlRefInlineExpectations.expected @@ -1,4 +1,2 @@ -| PrintAst.qlref:1:1:1:17 | dummy/PrintAst.ql | Query test does not use inline test expectations. | | QlRefInlineExpectations.qlref:1:1:1:40 | queries ... ions.ql | Query test does not use inline test expectations. | | Test3.qlref:1:1:1:39 | query: ... ists.ql | Query test does not use inline test expectations. | -| Test4.qlref:1:1:1:25 | query: ... tAst.ql | Query test does not use inline test expectations. |