Skip to content

Commit 04beeef

Browse files
committed
Add convenience module that merges two inline expectation tests
1 parent 9228e0d commit 04beeef

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

shared/util/codeql/util/test/InlineExpectationsTest.qll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,40 @@ module Make<InlineExpectationsTestSig Impl> {
356356
else value = ""
357357
}
358358

359+
/**
360+
* A module that merges two test signatures.
361+
*
362+
* This module can be used when multiple inline expectation tests occur in a single file. For example:
363+
* ```ql
364+
* module Test1 implements TestSig {
365+
* ...
366+
* }
367+
*
368+
* module Test2 implements TestSig {
369+
* ...
370+
* }
371+
*
372+
* import MakeTest<MergeTests<Test1, Test2>>
373+
* ```
374+
*/
375+
module MergeTests<TestSig TestImpl1, TestSig TestImpl2> implements TestSig {
376+
string getARelevantTag() {
377+
result = TestImpl1::getARelevantTag() or result = TestImpl2::getARelevantTag()
378+
}
379+
380+
predicate hasActualResult(Impl::Location location, string element, string tag, string value) {
381+
TestImpl1::hasActualResult(location, element, tag, value)
382+
or
383+
TestImpl2::hasActualResult(location, element, tag, value)
384+
}
385+
386+
predicate hasOptionalResult(Impl::Location location, string element, string tag, string value) {
387+
TestImpl1::hasOptionalResult(location, element, tag, value)
388+
or
389+
TestImpl2::hasOptionalResult(location, element, tag, value)
390+
}
391+
}
392+
359393
private module LegacyImpl implements TestSig {
360394
string getARelevantTag() { result = any(InlineExpectationsTest t).getARelevantTag() }
361395

0 commit comments

Comments
 (0)