Java: Generalize the inline mad test to allow further re-use.

This commit is contained in:
Michael Nebel
2024-05-06 13:34:03 +02:00
parent 51e7f3be1a
commit 95ddd6ec74
5 changed files with 47 additions and 31 deletions

View File

@@ -1,34 +1,50 @@
signature module InlineMadTestConfigSig { import java
private signature module InlineMadTestLangSig {
/** /**
* Gets a relevant code comment, if any. * Gets a relevant code comment, if any.
*/ */
string getComment(); string getComment();
}
signature module InlineMadTestConfigSig {
/**
* Gets the kind of the captured model.
*/
string getKind();
/** /**
* Gets an identified summary, if any. * Gets a captured model, if any.
*/ */
string getCapturedSummary(); string getCapturedModel();
}
private module InlineMadTestImpl<InlineMadTestLangSig Lang, InlineMadTestConfigSig Input> {
private string expects() {
Lang::getComment().regexpCapture(" *(SPURIOUS-)?" + Input::getKind() + "=(.*)", 2) = result
}
query predicate unexpectedModel(string msg) {
exists(string flow |
flow = Input::getCapturedModel() and
not flow = expects() and
msg = "Unexpected " + Input::getKind() + " found: " + flow
)
}
query predicate expectedModel(string msg) {
exists(string e |
e = expects() and
not e = Input::getCapturedModel() and
msg = "Expected " + Input::getKind() + " missing: " + e
)
}
}
private module InlineMadTestLang implements InlineMadTestLangSig {
string getComment() { result = any(Javadoc doc).getChild(0).toString() }
} }
module InlineMadTest<InlineMadTestConfigSig Input> { module InlineMadTest<InlineMadTestConfigSig Input> {
bindingset[kind] import InlineMadTestImpl<InlineMadTestLang, Input>
private string expects(string kind) {
Input::getComment().regexpCapture(" *(SPURIOUS-)?" + kind + "=(.*)", 2) = result
}
query predicate unexpectedSummary(string msg) {
exists(string flow |
flow = Input::getCapturedSummary() and
not flow = expects("summary") and
msg = "Unexpected summary found: " + flow
)
}
query predicate expectedSummary(string msg) {
exists(string e |
e = expects("summary") and
not e = Input::getCapturedSummary() and
msg = "Expected summary missing: " + e
)
}
} }

View File

@@ -1,2 +1,2 @@
unexpectedSummary unexpectedModel
expectedSummary expectedModel

View File

@@ -3,9 +3,9 @@ import utils.modelgenerator.internal.CaptureSummaryFlowQuery
import TestUtilities.InlineMadTest import TestUtilities.InlineMadTest
module InlineMadTestConfig implements InlineMadTestConfigSig { module InlineMadTestConfig implements InlineMadTestConfigSig {
string getComment() { result = any(Javadoc doc).getChild(0).toString() } string getCapturedModel() { result = captureFlow(_) }
string getCapturedSummary() { result = captureFlow(_) } string getKind() { result = "summary" }
} }
import InlineMadTest<InlineMadTestConfig> import InlineMadTest<InlineMadTestConfig>

View File

@@ -1,2 +1,2 @@
unexpectedSummary unexpectedModel
expectedSummary expectedModel

View File

@@ -3,9 +3,9 @@ import TestUtilities.InlineMadTest
import utils.modelgenerator.internal.CaptureTypeBasedSummaryModels import utils.modelgenerator.internal.CaptureTypeBasedSummaryModels
module InlineMadTestConfig implements InlineMadTestConfigSig { module InlineMadTestConfig implements InlineMadTestConfigSig {
string getComment() { result = any(Javadoc doc).getChild(0).toString() } string getCapturedModel() { result = captureFlow(_) }
string getCapturedSummary() { result = captureFlow(_) } string getKind() { result = "summary" }
} }
import InlineMadTest<InlineMadTestConfig> import InlineMadTest<InlineMadTestConfig>