mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
C++: Instantiate inline expectation test framework to test model generation.
This commit is contained in:
34
cpp/ql/lib/utils/test/InlineMadTest.qll
Normal file
34
cpp/ql/lib/utils/test/InlineMadTest.qll
Normal file
@@ -0,0 +1,34 @@
|
||||
private import cpp
|
||||
private import codeql.mad.test.InlineMadTest
|
||||
|
||||
class MadRelevantFunction extends Function {
|
||||
MadRelevantFunction() { not this.isFromUninstantiatedTemplate(_) }
|
||||
}
|
||||
|
||||
private module InlineMadTestLang implements InlineMadTestLangSig {
|
||||
class Callable = MadRelevantFunction;
|
||||
|
||||
/**
|
||||
* Holds if `c` is the closest `Callable` that suceeds `comment` in the file.
|
||||
*/
|
||||
private predicate hasClosestCallable(CppStyleComment comment, Callable c) {
|
||||
c =
|
||||
min(Callable cand, int dist |
|
||||
// This has no good join order, but should hopefully be good enough for tests.
|
||||
cand.getFile() = comment.getFile() and
|
||||
dist = cand.getLocation().getStartLine() - comment.getLocation().getStartLine() and
|
||||
dist > 0
|
||||
|
|
||||
cand order by dist
|
||||
)
|
||||
}
|
||||
|
||||
string getComment(Callable c) {
|
||||
exists(CppStyleComment comment |
|
||||
hasClosestCallable(comment, c) and
|
||||
result = comment.getContents().suffix(2)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import InlineMadTestImpl<InlineMadTestLang>
|
||||
Reference in New Issue
Block a user