Support post-procesed inline expectations for query predicates in unit tests#19211
Support post-procesed inline expectations for query predicates in unit tests#19211asgerf merged 2 commits intogithub:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for inline expectations for query predicates in unit tests, providing a convenient way to specify expected values directly in test files.
- Updated test cases to include inline expectation annotations.
- Added inline annotations for sensitive expressions and process termination.
Files not reviewed (4)
- javascript/ql/test/library-tests/SensitiveActions/tests.expected: Language not supported
- javascript/ql/test/library-tests/SensitiveActions/tests.ql: Language not supported
- javascript/ql/test/library-tests/SensitiveActions/tests.qlref: Language not supported
- shared/util/codeql/util/test/InlineExpectationsTest.qll: Language not supported
Comments suppressed due to low confidence (2)
javascript/ql/test/library-tests/SensitiveActions/tst.js:1
- [nitpick] The inline expectation uses 'cleartextPasswordExpr' as the location while the predicate is 'sensitiveExpr'. Consider aligning the naming for consistency so that the entity type clearly reflects the expected predicate.
password; // $ cleartextPasswordExpr sensitiveExpr=password
javascript/ql/test/library-tests/SensitiveActions/tst.js:18
- [nitpick] The inline expectation comment for process termination includes a location 'processTermination' with a value of 'sensitiveAction'. Verify that this naming reflects the intended query predicate and entity type, and adjust if necessary for clarity and consistency.
e(); // $ processTermination sensitiveAction
Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more
Which |
See the backlinked PR. Only the |
This adds a low-friction way to add inline expectations to a unit test.
Any
.qlfile in a test folder can now use inline expectations without doing the dance of importing and instantiating a parameterised module.Example
Suppose we have a file
test.qlwith this content:We can now add a
test.qlrefin the same folder with the contents:And now the test will run with inline expectation checking. For example the test file might look like this:
Details
string, becomes the value. This column may be omitted.test.qlfile must have no query kind for this to take effect. Queries of kindproblemorpath-problemare already supported in their own way.This PR ports a single test to use this in order to keep the PR small while ensuring the behaviour is exercised.
Thanks to @hmakholm for some corresponding fixes in the CLI, to ensure the same-named
.qland.qlreffiles can coexist in the same folder without fighting over the same.actualand.expectedfile.