Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions actions/ql/test/utils/ActionsInlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import T::TestPostProcessing
private module Impl implements T::InlineExpectationsTestSig {
class Location = Locations::Location;

class ExpectationComment extends Yaml::YamlComment {
string getContents() { result = this.getText() }
}
}

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Locations::Location location) {
exists(int startLine, int startColumn, int endLine, int endColumn |
location.hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
Expand All @@ -25,6 +19,10 @@ private module Input implements T::TestPostProcessing::InputSig<Impl> {
":" + endColumn
)
}

class ExpectationComment extends Yaml::YamlComment {
string getContents() { result = this.getText() }
}
}

import T::TestPostProcessing::Make<Impl, Input>
import T::TestPostProcessing::Make<Impl>
14 changes: 1 addition & 13 deletions cpp/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import cpp
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
10 changes: 10 additions & 0 deletions cpp/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ module Impl implements InlineExpectationsTestSig {
}

class Location = C::Location;

string getRelativeUrl(Location location) {
exists(C::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
14 changes: 1 addition & 13 deletions csharp/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import csharp
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ module Impl implements InlineExpectationsTestSig {
}

class Location = CS::Location;

string getRelativeUrl(Location location) {
exists(CS::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
14 changes: 1 addition & 13 deletions go/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import go
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
10 changes: 10 additions & 0 deletions go/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ module Impl implements InlineExpectationsTestSig {
}

class Location = G::Location;

string getRelativeUrl(Location location) {
exists(G::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
14 changes: 1 addition & 13 deletions java/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import java
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
10 changes: 10 additions & 0 deletions java/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ module Impl implements InlineExpectationsTestSig {
}

class Location = J::Location;

string getRelativeUrl(Location location) {
exists(J::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
14 changes: 1 addition & 13 deletions javascript/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import javascript
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ module Impl implements InlineExpectationsTestSig {

class Location = JS::Location;

string getRelativeUrl(Location location) {
exists(JS::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

abstract private class ExpectationCommentImpl extends Locatable {
abstract string getContents();

Expand Down
14 changes: 1 addition & 13 deletions python/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import python
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ module Impl implements InlineExpectationsTestSig {
class ExpectationComment = PY::Comment;

class Location = PY::Location;

string getRelativeUrl(Location location) {
exists(PY::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
14 changes: 1 addition & 13 deletions ql/ql/src/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import ql
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
10 changes: 10 additions & 0 deletions ql/ql/src/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ module Impl implements InlineExpectationsTestSig {
}

class Location = QL::Location;

string getRelativeUrl(Location location) {
exists(QL::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
14 changes: 1 addition & 13 deletions ruby/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import ruby
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
10 changes: 10 additions & 0 deletions ruby/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ module Impl implements InlineExpectationsTestSig {
}

class Location = R::Location;

string getRelativeUrl(Location location) {
exists(R::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
14 changes: 1 addition & 13 deletions rust/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,4 @@ private import rust
private import codeql.util.test.InlineExpectationsTest as T
private import internal.InlineExpectationsTestImpl
import T::TestPostProcessing
import T::TestPostProcessing::Make<Impl, Input>

private module Input implements T::TestPostProcessing::InputSig<Impl> {
string getRelativeUrl(Location location) {
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
import T::TestPostProcessing::Make<Impl>
10 changes: 10 additions & 0 deletions rust/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ module Impl implements InlineExpectationsTestSig {
}

class Location = R::Location;

string getRelativeUrl(Location location) {
exists(R::File f, int startline, int startcolumn, int endline, int endcolumn |
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
f = location.getFile()
|
result =
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}
}
27 changes: 16 additions & 11 deletions shared/util/codeql/util/test/InlineExpectationsTest.qll
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ signature module InlineExpectationsTestSig {
);
}

/** Gets the relative URL of the given location, if any. */
string getRelativeUrl(Location location);

/** A comment that may contain inline expectations. */
class ExpectationComment {
/** Gets the contents of this comment, _excluding_ the comment indicator. */
Expand Down Expand Up @@ -242,9 +245,13 @@ module Make<InlineExpectationsTestSig Impl> {
TActualResult(
Impl::Location location, string element, string tag, string value, boolean optional
) {
TestImpl::hasActualResult(location, element, tag, value) and optional = false
or
TestImpl::hasOptionalResult(location, element, tag, value) and optional = true
(
TestImpl::hasActualResult(location, element, tag, value) and optional = false
or
TestImpl::hasOptionalResult(location, element, tag, value) and optional = true
) and
// test expectations can only be defined in source code
exists(Impl::getRelativeUrl(location))
} or
TValidExpectation(
Impl::ExpectationComment comment, string tag, string value, string knownFailure
Expand Down Expand Up @@ -633,11 +640,7 @@ module TestPostProcessing {

private string getQueryKind() { queryMetadata("kind", result) }

signature module InputSig<InlineExpectationsTestSig Input> {
string getRelativeUrl(Input::Location location);
}

module Make<InlineExpectationsTestSig Input, InputSig<Input> Input2> {
module Make<InlineExpectationsTestSig Input> {
private import InlineExpectationsTest as InlineExpectationsTest

bindingset[loc]
Expand All @@ -655,7 +658,7 @@ module TestPostProcessing {
private string getRelativePathTo(string absolutePath) {
exists(Input::Location loc |
loc.hasLocationInfo(absolutePath, _, _, _, _) and
parseLocationString(Input2::getRelativeUrl(loc), result, _, _, _, _)
parseLocationString(Input::getRelativeUrl(loc), result, _, _, _, _)
)
}

Expand All @@ -665,7 +668,7 @@ module TestPostProcessing {
exists(string data |
queryResults(_, _, _, data) and
parseLocationString(data, relativePath, sl, sc, el, ec) and
not Input2::getRelativeUrl(_) = data // avoid duplicate locations
not Input::getRelativeUrl(_) = data // avoid duplicate locations
)
}

Expand Down Expand Up @@ -711,7 +714,7 @@ module TestPostProcessing {

LocationFromInput() { this = MkInputLocation(loc) }

override string getRelativeUrl() { result = Input2::getRelativeUrl(loc) }
override string getRelativeUrl() { result = Input::getRelativeUrl(loc) }

override predicate hasLocationInfo(string file, int sl, int sc, int el, int ec) {
loc.hasLocationInfo(file, sl, sc, el, ec)
Expand All @@ -723,6 +726,8 @@ module TestPostProcessing {
module TestImpl2 implements InlineExpectationsTestSig {
final class Location = TestLocation;

string getRelativeUrl(Location location) { result = location.getRelativeUrl() }

final private class ExpectationCommentFinal = Input::ExpectationComment;

class ExpectationComment extends ExpectationCommentFinal {
Expand Down
Loading
Loading