Kotlin: Copy TestUtilities into the kotlin testsuites

This commit is contained in:
Ian Lynagh
2023-11-21 17:16:54 +00:00
parent 7ba199a8c3
commit 45bbcccd1a
6 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
/**
* Inline expectation tests for Java.
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
*/
private import codeql.util.test.InlineExpectationsTest
private import internal.InlineExpectationsTestImpl
import Make<Impl>

View File

@@ -0,0 +1,33 @@
/**
* Inline flow tests for Java.
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
*/
import java
import semmle.code.java.dataflow.DataFlow
private import codeql.dataflow.test.InlineFlowTest
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<JavaDataFlow> {
predicate defaultSource(DataFlow::Node source) {
source.asExpr().(MethodCall).getMethod().getName() = ["source", "taint"]
}
predicate defaultSink(DataFlow::Node sink) {
exists(MethodCall ma | ma.getMethod().hasName("sink") | sink.asExpr() = ma.getAnArgument())
}
private string getSourceArgString(DataFlow::Node src) {
defaultSource(src) and
src.asExpr().(MethodCall).getAnArgument().(StringLiteral).getValue() = result
}
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
exists(sink)
}
}
import InlineFlowTestMake<JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

View File

@@ -0,0 +1,35 @@
private import java as J
private import codeql.util.test.InlineExpectationsTest
module Impl implements InlineExpectationsTestSig {
/**
* A class representing line comments in Java, which is simply Javadoc restricted
* to EOL comments, with an extra accessor used by the InlineExpectations core code
*/
abstract class ExpectationComment extends J::Top {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
abstract string getContents();
}
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
JavadocExpectationComment() { isEolComment(this) }
override string getContents() { result = this.getChild(0).toString() }
}
private class KtExpectationComment extends J::KtComment, ExpectationComment {
KtExpectationComment() { this.isEolComment() }
override string getContents() { result = this.getText().suffix(2).trim() }
}
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
override string getContents() { result = super.getText().trim() }
override Location getLocation() { result = J::XmlComment.super.getLocation() }
override string toString() { result = J::XmlComment.super.toString() }
}
class Location = J::Location;
}

View File

@@ -0,0 +1,8 @@
/**
* Inline expectation tests for Java.
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
*/
private import codeql.util.test.InlineExpectationsTest
private import internal.InlineExpectationsTestImpl
import Make<Impl>

View File

@@ -0,0 +1,33 @@
/**
* Inline flow tests for Java.
* See `shared/util/codeql/dataflow/test/InlineFlowTest.qll`
*/
import java
import semmle.code.java.dataflow.DataFlow
private import codeql.dataflow.test.InlineFlowTest
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific
private import internal.InlineExpectationsTestImpl
private module FlowTestImpl implements InputSig<JavaDataFlow> {
predicate defaultSource(DataFlow::Node source) {
source.asExpr().(MethodCall).getMethod().getName() = ["source", "taint"]
}
predicate defaultSink(DataFlow::Node sink) {
exists(MethodCall ma | ma.getMethod().hasName("sink") | sink.asExpr() = ma.getAnArgument())
}
private string getSourceArgString(DataFlow::Node src) {
defaultSource(src) and
src.asExpr().(MethodCall).getAnArgument().(StringLiteral).getValue() = result
}
string getArgString(DataFlow::Node src, DataFlow::Node sink) {
(if exists(getSourceArgString(src)) then result = getSourceArgString(src) else result = "") and
exists(sink)
}
}
import InlineFlowTestMake<JavaDataFlow, JavaTaintTracking, Impl, FlowTestImpl>

View File

@@ -0,0 +1,35 @@
private import java as J
private import codeql.util.test.InlineExpectationsTest
module Impl implements InlineExpectationsTestSig {
/**
* A class representing line comments in Java, which is simply Javadoc restricted
* to EOL comments, with an extra accessor used by the InlineExpectations core code
*/
abstract class ExpectationComment extends J::Top {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
abstract string getContents();
}
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
JavadocExpectationComment() { isEolComment(this) }
override string getContents() { result = this.getChild(0).toString() }
}
private class KtExpectationComment extends J::KtComment, ExpectationComment {
KtExpectationComment() { this.isEolComment() }
override string getContents() { result = this.getText().suffix(2).trim() }
}
private class XmlExpectationComment extends ExpectationComment instanceof J::XmlComment {
override string getContents() { result = super.getText().trim() }
override Location getLocation() { result = J::XmlComment.super.getLocation() }
override string toString() { result = J::XmlComment.super.toString() }
}
class Location = J::Location;
}