mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Revert "Merge pull request #37 from erik-krogh/shared/inline-tests"
This reverts commit65fe9abcfe, reversing changes made to08e9d3391f.
This commit is contained in:
@@ -6,27 +6,30 @@
|
||||
import cpp as C
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
private newtype TExpectationComment = MkExpectationComment(C::CppStyleComment c)
|
||||
private module Impl implements InlineExpectationsTestSig {
|
||||
private newtype TExpectationComment = MkExpectationComment(C::CppStyleComment c)
|
||||
|
||||
/**
|
||||
* Represents a line comment in the CPP style.
|
||||
* Unlike the `CppStyleComment` class, however, the string returned by `getContents` does _not_
|
||||
* include the preceding comment marker (`//`).
|
||||
*/
|
||||
private class ExpectationComment extends TExpectationComment {
|
||||
C::CppStyleComment comment;
|
||||
/**
|
||||
* Represents a line comment in the CPP style.
|
||||
* Unlike the `CppStyleComment` class, however, the string returned by `getContents` does _not_
|
||||
* include the preceding comment marker (`//`).
|
||||
*/
|
||||
class ExpectationComment extends TExpectationComment {
|
||||
C::CppStyleComment comment;
|
||||
|
||||
ExpectationComment() { this = MkExpectationComment(comment) }
|
||||
ExpectationComment() { this = MkExpectationComment(comment) }
|
||||
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = comment.getContents().suffix(2) }
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = comment.getContents().suffix(2) }
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString() { result = comment.toString() }
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString() { result = comment.toString() }
|
||||
|
||||
predicate hasLocationInfo(string file, int line, int column, int endLine, int endColumn) {
|
||||
comment.getLocation().hasLocationInfo(file, line, column, endLine, endColumn)
|
||||
/** Gets the location of this comment. */
|
||||
Location getLocation() { result = comment.getLocation() }
|
||||
}
|
||||
|
||||
class Location = C::Location;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
private import csharp as CS
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
/**
|
||||
* A class representing line comments in C# used by the InlineExpectations core code
|
||||
*/
|
||||
private class ExpectationComment extends CS::SinglelineComment {
|
||||
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = this.getText() }
|
||||
|
||||
predicate hasLocationInfo(string file, int line, int column, int endLine, int endColumn) {
|
||||
this.getLocation().hasLocationInfo(file, line, column, endLine, endColumn)
|
||||
private module Impl implements InlineExpectationsTestSig {
|
||||
/**
|
||||
* A class representing line comments in C# used by the InlineExpectations core code
|
||||
*/
|
||||
class ExpectationComment extends CS::SinglelineComment {
|
||||
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = this.getText() }
|
||||
}
|
||||
|
||||
class Location = CS::Location;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
@@ -6,13 +6,17 @@
|
||||
private import go as G
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
/**
|
||||
* Represents a line comment in the Go style.
|
||||
* include the preceding comment marker (`//`).
|
||||
*/
|
||||
private class ExpectationComment extends G::Comment {
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = this.getText() }
|
||||
private module Impl implements InlineExpectationsTestSig {
|
||||
/**
|
||||
* Represents a line comment in the Go style.
|
||||
* include the preceding comment marker (`//`).
|
||||
*/
|
||||
class ExpectationComment extends G::Comment {
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = this.getText() }
|
||||
}
|
||||
|
||||
class Location = G::Location;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
@@ -6,35 +6,37 @@
|
||||
private import java as J
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
/**
|
||||
* 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 private 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 predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
|
||||
J::XmlComment.super.hasLocationInfo(path, sl, sc, el, ec)
|
||||
private 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();
|
||||
}
|
||||
|
||||
override string toString() { result = J::XmlComment.super.toString() }
|
||||
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;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
private import python as PY
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
/**
|
||||
* A class representing line comments in Python. As this is the only form of comment Python
|
||||
* permits, we simply reuse the `Comment` class.
|
||||
*/
|
||||
private class ExpectationComment extends PY::Comment {
|
||||
predicate hasLocationInfo(string file, int line, int column, int endLine, int endColumn) {
|
||||
this.getLocation().hasLocationInfo(file, line, column, endLine, endColumn)
|
||||
}
|
||||
private module Impl implements InlineExpectationsTestSig {
|
||||
/**
|
||||
* A class representing line comments in Python. As this is the only form of comment Python
|
||||
* permits, we simply reuse the `Comment` class.
|
||||
*/
|
||||
class ExpectationComment = PY::Comment;
|
||||
|
||||
class Location = PY::Location;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
@@ -5,27 +5,31 @@
|
||||
|
||||
private import ql as QL
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
private import codeql_ql.ast.internal.TreeSitter as TS
|
||||
|
||||
private newtype TExpectationComment = MkExpectationComment(TS::QL::LineComment comment)
|
||||
private module Impl implements InlineExpectationsTestSig {
|
||||
private import codeql_ql.ast.internal.TreeSitter as TS
|
||||
|
||||
/**
|
||||
* Represents a line comment.
|
||||
*/
|
||||
private class ExpectationComment extends TExpectationComment {
|
||||
TS::QL::LineComment comment;
|
||||
private newtype TExpectationComment = MkExpectationComment(TS::QL::LineComment comment)
|
||||
|
||||
ExpectationComment() { this = MkExpectationComment(comment) }
|
||||
/**
|
||||
* Represents a line comment.
|
||||
*/
|
||||
class ExpectationComment extends TExpectationComment {
|
||||
TS::QL::LineComment comment;
|
||||
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = comment.getValue().suffix(2) }
|
||||
ExpectationComment() { this = MkExpectationComment(comment) }
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString() { result = comment.toString() }
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = comment.getValue().suffix(2) }
|
||||
|
||||
predicate hasLocationInfo(string file, int line, int column, int endLine, int endColumn) {
|
||||
comment.getLocation().hasLocationInfo(file, line, column, endLine, endColumn)
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString() { result = comment.toString() }
|
||||
|
||||
/** Gets the location of this comment. */
|
||||
Location getLocation() { result = comment.getLocation() }
|
||||
}
|
||||
|
||||
class Location = QL::Location;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
@@ -3,18 +3,20 @@
|
||||
* See `shared/util/codeql/util/test/InlineExpectationsTest.qll`
|
||||
*/
|
||||
|
||||
private import codeql.ruby.AST as R
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
private import codeql.ruby.ast.internal.TreeSitter
|
||||
|
||||
/**
|
||||
* A class representing line comments in Ruby.
|
||||
*/
|
||||
private class ExpectationComment extends Ruby::Comment {
|
||||
string getContents() { result = this.getValue().suffix(1) }
|
||||
private module Impl implements InlineExpectationsTestSig {
|
||||
private import codeql.ruby.ast.internal.TreeSitter
|
||||
|
||||
predicate hasLocationInfo(string file, int line, int column, int endLine, int endColumn) {
|
||||
this.getLocation().hasLocationInfo(file, line, column, endLine, endColumn)
|
||||
/**
|
||||
* A class representing line comments in Ruby.
|
||||
*/
|
||||
class ExpectationComment extends Ruby::Comment {
|
||||
string getContents() { result = this.getValue().suffix(1) }
|
||||
}
|
||||
|
||||
class Location = R::Location;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
* To add this framework to a new language, add a new file
|
||||
* (usually called `InlineExpectationsTest.qll`) with:
|
||||
* - `private import codeql.util.test.InlineExpectationsTest` (this file)
|
||||
* - An implementation of the class signature in `ExpectationCommentSig`.
|
||||
* This class can e.g. be called `ExpectationComment`.
|
||||
* - An implementation of the signature in `InlineExpectationsTestSig`.
|
||||
* Usually this is done in a mdule called `Impl`.
|
||||
* `Impl` has to define a `Location` class, and an `ExpectationComment` class.
|
||||
* The `ExpectationComment` class must support a `getContents` method that returns
|
||||
* the contents of the given comment, _excluding_ the comment indicator itself.
|
||||
* It should also define `toString` and `hasLocationInfo` as usual.
|
||||
* - `import Make<ExpectationComment>` to expose the query predicates constructed in the `Make` module.
|
||||
* It should also define `toString` and `getLocation` as usual.
|
||||
* - `import Make<Impl>` to expose the query predicates constructed in the `Make` module.
|
||||
*
|
||||
* To create a new inline expectations test:
|
||||
* - Declare a class that extends `InlineExpectationsTest`. In the characteristic predicate of the
|
||||
@@ -95,67 +96,36 @@
|
||||
* `tag1=expected-value tag2=expected-value`
|
||||
*/
|
||||
|
||||
/** A comment that may contain inline expectations. */
|
||||
signature class ExpectationCommentSig {
|
||||
/** Gets the contents of this comment, _excluding_ the comment indicator. */
|
||||
string getContents();
|
||||
/**
|
||||
* A signature specifying the required parts for
|
||||
* constructing inline expectations.
|
||||
*/
|
||||
signature module InlineExpectationsTestSig {
|
||||
/** The location of an element in the source code. */
|
||||
class Location {
|
||||
predicate hasLocationInfo(
|
||||
string filename, int startLine, int startColumn, int endLine, int endColumn
|
||||
);
|
||||
}
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString();
|
||||
/** A comment that may contain inline expectations. */
|
||||
class ExpectationComment {
|
||||
/** Gets the contents of this comment, _excluding_ the comment indicator. */
|
||||
string getContents();
|
||||
|
||||
predicate hasLocationInfo(
|
||||
string filename, int startLine, int startColumn, int endLine, int endColumn
|
||||
);
|
||||
/** Gets the location of this comment. */
|
||||
Location getLocation();
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Classes and predicates implementing inline expectations.
|
||||
*/
|
||||
module Make<ExpectationCommentSig ExpectationComment> {
|
||||
private newtype TTLocation =
|
||||
TLocation(string filename, int startLine, int startColumn, int endLine, int endColumn) {
|
||||
any(ExpectationComment c)
|
||||
.hasLocationInfo(filename, startLine, startColumn, endLine, endColumn)
|
||||
}
|
||||
|
||||
private class Location extends TLocation {
|
||||
string filename;
|
||||
int startLine;
|
||||
int startColumn;
|
||||
int endLine;
|
||||
int endColumn;
|
||||
|
||||
Location() { this = TLocation(filename, startLine, startColumn, endLine, endColumn) }
|
||||
|
||||
string getFilename() { result = filename }
|
||||
|
||||
int getStartLine() { result = startLine }
|
||||
|
||||
int getStartColumn() { result = startColumn }
|
||||
|
||||
int getEndLine() { result = endLine }
|
||||
|
||||
int getEndColumn() { result = endColumn }
|
||||
|
||||
string toString() {
|
||||
result = filename + ":" + startLine + ":" + startColumn + "-" + endLine + ":" + endColumn
|
||||
}
|
||||
|
||||
predicate hasLocationInfo(string f, int sl, int sc, int el, int ec) {
|
||||
f = filename and
|
||||
sl = startLine and
|
||||
sc = startColumn and
|
||||
el = endLine and
|
||||
ec = endColumn
|
||||
}
|
||||
}
|
||||
|
||||
private Location getLocation(ExpectationComment c) {
|
||||
exists(string filename, int startLine, int startColumn, int endLine, int endColumn |
|
||||
c.hasLocationInfo(filename, startLine, startColumn, endLine, endColumn) and
|
||||
result = TLocation(filename, startLine, startColumn, endLine, endColumn)
|
||||
)
|
||||
}
|
||||
module Make<InlineExpectationsTestSig Impl> {
|
||||
private import Impl
|
||||
|
||||
/**
|
||||
* The base class for tests with inline expectations. The test extends this class to provide the actual
|
||||
@@ -402,7 +372,7 @@ module Make<ExpectationCommentSig ExpectationComment> {
|
||||
|
||||
override string toString() { result = comment.toString() }
|
||||
|
||||
override Location getLocation() { result = getLocation(comment) }
|
||||
override Location getLocation() { result = comment.getLocation() }
|
||||
}
|
||||
|
||||
private predicate onSameLine(ValidExpectation a, ActualResult b) {
|
||||
|
||||
@@ -6,27 +6,30 @@
|
||||
private import swift as S
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
private newtype TExpectationComment = MkExpectationComment(S::SingleLineComment c)
|
||||
private module Impl implements InlineExpectationsTestSig {
|
||||
private newtype TExpectationComment = MkExpectationComment(S::SingleLineComment c)
|
||||
|
||||
/**
|
||||
* Represents a line comment.
|
||||
* Unlike the `SingleLineComment` class, however, the string returned by `getContents` does _not_
|
||||
* include the preceding comment marker (`//`).
|
||||
*/
|
||||
private class ExpectationComment extends TExpectationComment {
|
||||
S::SingleLineComment comment;
|
||||
/**
|
||||
* Represents a line comment.
|
||||
* Unlike the `SingleLineComment` class, however, the string returned by `getContents` does _not_
|
||||
* include the preceding comment marker (`//`).
|
||||
*/
|
||||
class ExpectationComment extends TExpectationComment {
|
||||
S::SingleLineComment comment;
|
||||
|
||||
ExpectationComment() { this = MkExpectationComment(comment) }
|
||||
ExpectationComment() { this = MkExpectationComment(comment) }
|
||||
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = comment.getText().suffix(2) }
|
||||
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = comment.getText().suffix(2) }
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString() { result = comment.toString() }
|
||||
/** Gets a textual representation of this element. */
|
||||
string toString() { result = comment.toString() }
|
||||
|
||||
predicate hasLocationInfo(string file, int line, int column, int endLine, int endColumn) {
|
||||
comment.getLocation().hasLocationInfo(file, line, column, endLine, endColumn)
|
||||
/** Gets the location of this comment. */
|
||||
Location getLocation() { result = comment.getLocation() }
|
||||
}
|
||||
|
||||
class Location = S::Location;
|
||||
}
|
||||
|
||||
import Make<ExpectationComment>
|
||||
import Make<Impl>
|
||||
|
||||
Reference in New Issue
Block a user