mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
Share the Models as Data inline expect predicates.
This commit is contained in:
@@ -1,54 +1,5 @@
|
||||
import java as J
|
||||
|
||||
private signature module InlineMadTestLangSig {
|
||||
/**
|
||||
* A base class of callables for modeling.
|
||||
*/
|
||||
class Callable;
|
||||
|
||||
/**
|
||||
* Gets a relevant code comment for `c`, if any.
|
||||
*/
|
||||
string getComment(Callable c);
|
||||
}
|
||||
|
||||
private module InlineMadTestImpl<InlineMadTestLangSig Lang> {
|
||||
private class Callable = Lang::Callable;
|
||||
|
||||
signature module InlineMadTestConfigSig {
|
||||
/**
|
||||
* Gets the kind of a captured model.
|
||||
*/
|
||||
string getKind();
|
||||
|
||||
/**
|
||||
* Gets a captured model for `c`, if any.
|
||||
*/
|
||||
string getCapturedModel(Callable c);
|
||||
}
|
||||
|
||||
module InlineMadTest<InlineMadTestConfigSig Input> {
|
||||
private string expects(Callable c) {
|
||||
Lang::getComment(c).regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
|
||||
}
|
||||
|
||||
query predicate unexpectedModel(string msg) {
|
||||
exists(Callable c, string flow |
|
||||
flow = Input::getCapturedModel(c) and
|
||||
not flow = expects(c) and
|
||||
msg = "Unexpected " + Input::getKind() + " found: " + flow
|
||||
)
|
||||
}
|
||||
|
||||
query predicate expectedModel(string msg) {
|
||||
exists(Callable c, string e |
|
||||
e = expects(c) and
|
||||
not e = Input::getCapturedModel(c) and
|
||||
msg = "Expected " + Input::getKind() + " missing: " + e
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
private import java as J
|
||||
private import codeql.mad.test.InlineMadTest
|
||||
|
||||
private module InlineMadTestLang implements InlineMadTestLangSig {
|
||||
class Callable = J::Callable;
|
||||
|
||||
Reference in New Issue
Block a user