mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
Fix testing methods with 2-qualifier or deeper input specifications
For example, an identity function on lists-of-maps, which might convey MapValue of Element of Argument[0] to MapValue of Element of ReturnValue, requiring `newWithElement(newWithMapValue(source())` on the input side but `getMapValue(getElement(out))` on the output side.
This commit is contained in:
@@ -271,10 +271,26 @@ class RowTestSnippet extends TRowTestSnippet {
|
||||
*/
|
||||
string getInputTypeString() { result = getShortNameIfPossible(this.getInputType()) }
|
||||
|
||||
/**
|
||||
* Returns the next-highest stack item in `input`, treating the list as circular, so
|
||||
* the top item's successor is `baseInput`, the bottom of the stack.
|
||||
*/
|
||||
SummaryComponentStack nextInput(SummaryComponentStack prev) {
|
||||
exists(SummaryComponentStack next | next.tail() = prev and next = input.drop(_) | result = next)
|
||||
or
|
||||
not exists(SummaryComponentStack next | next.tail() = prev and next = input.drop(_)) and
|
||||
result = baseInput
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a call to `source()` wrapped in `newWith` methods as needed according to `input`.
|
||||
* For example, if the input specification is `ArrayElement of MapValue of Argument[0]`, this
|
||||
* will return `newWithArrayElement(newWithMapValue(source()))`.
|
||||
* will return `newWithMapValue(newWithArrayElement(source()))`.
|
||||
*
|
||||
* This requires a slightly awkward walk, out from the element above the root (`Argument[0]` above)
|
||||
* climbing up towards the outer `ArrayElement of...`. This is implemented by treating the stack as
|
||||
* a circular list, walking it backwards and treating the root as a sentinel indicating we should
|
||||
* emit `source()`.
|
||||
*/
|
||||
string getInput(SummaryComponentStack componentStack) {
|
||||
componentStack = input.drop(_) and
|
||||
@@ -284,7 +300,7 @@ class RowTestSnippet extends TRowTestSnippet {
|
||||
else
|
||||
result =
|
||||
"newWith" + contentToken(getContent(componentStack.head())) + "(" +
|
||||
this.getInput(componentStack.tail()) + ")"
|
||||
this.getInput(nextInput(componentStack)) + ")"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -364,8 +380,9 @@ class RowTestSnippet extends TRowTestSnippet {
|
||||
result =
|
||||
"\t\t{\n\t\t\t// \"" + row + "\"\n\t\t\t" + getShortNameIfPossible(this.getOutputType()) +
|
||||
" out = null;\n\t\t\t" + this.getInputTypeString() + " in = (" + this.getInputTypeString() +
|
||||
")" + this.getInput(input) + ";\n\t\t\t" + this.getInstancePrefix() + this.makeCall() +
|
||||
";\n\t\t\t" + "sink(" + this.getOutput(output) + "); " + this.getExpectation() + "\n\t\t}\n"
|
||||
")" + this.getInput(this.nextInput(baseInput)) + ";\n\t\t\t" + this.getInstancePrefix() +
|
||||
this.makeCall() + ";\n\t\t\t" + "sink(" + this.getOutput(output) + "); " +
|
||||
this.getExpectation() + "\n\t\t}\n"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user