Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ module Impl implements InlineExpectationsTestSig {
class ExpectationComment extends Yaml::YamlComment {
/** Gets the contents of this comment. */
string getContents() { result = this.getText() }

/** YAML comments use line-comment syntax. */
predicate isLineComment() { any() }
}

class Location = L::Location;
Expand All @@ -21,4 +24,10 @@ module Impl implements InlineExpectationsTestSig {
":" + endColumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
relativePath.regexpMatch(".*\\.ya?ml") and
result = "#"
Comment thread
d10c marked this conversation as resolved.
}
}
9 changes: 9 additions & 0 deletions actions/ql/test/utils/ActionsInlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import codeql.Locations as Locations
Expand All @@ -20,8 +21,16 @@ private module Impl implements T::InlineExpectationsTestSig {
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
relativePath.regexpMatch(".*\\.ya?ml") and
result = "#"
Comment thread
d10c marked this conversation as resolved.
}

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

predicate isLineComment() { any() }
}
}

Expand Down
1 change: 1 addition & 0 deletions cpp/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import cpp
Expand Down
13 changes: 13 additions & 0 deletions cpp/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module Impl implements InlineExpectationsTestSig {
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
string getContents() { result = comment.getContents().suffix(2) }

/** C++ expectation comments use line-comment syntax. */
predicate isLineComment() { any() }

/** Gets a textual representation of this element. */
string toString() { result = comment.toString() }

Expand All @@ -35,4 +38,14 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// C/C++ databases can also contain XML (e.g. `.xml`, `.props`), whose block-comment
// syntax is not yet supported, so we only render for C/C++ sources.
relativePath
.toLowerCase()
.regexpMatch(".*\\.(c|i|cc|cp|cpp|cxx|c\\+\\+|icc|ipp|ixx|i\\+\\+|ii|h|r|hh|hp|hpp|hxx|h\\+\\+|tcc|tpp|txx|t\\+\\+|inl|cu|cuh)") and
result = "//"
}
}
1 change: 1 addition & 0 deletions csharp/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import csharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ module Impl implements InlineExpectationsTestSig {
result = this.asAspComment().getBody()
}

/** Holds if this is a C# `//` comment. */
predicate isLineComment() { exists(this.asCSharpComment()) }

/** Gets the location of this comment. */
Location getLocation() {
result = this.asCSharpComment().getLocation()
Expand Down Expand Up @@ -59,4 +62,12 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// C# databases can also contain XML (e.g. `.csproj`, `.config`) and Razor markup, whose
// comment syntaxes are not yet supported, so we only render for C# sources.
relativePath.regexpMatch(".*\\.(cs|csx)") and
result = "//"
}
}
1 change: 1 addition & 0 deletions go/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import go
Expand Down
11 changes: 11 additions & 0 deletions go/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module Impl implements InlineExpectationsTestSig {
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
string getContents() { result = this.getText() }

/** Holds if this comment uses `//` syntax. */
predicate isLineComment() { this instanceof G::LineComment }

/** Gets this element's location. */
G::Location getLocation() { result = super.getLocation() }
}
Expand All @@ -30,4 +33,12 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// Go databases can also contain XML, whose block-comment syntax is not yet supported, so
// we only render for Go sources.
relativePath.matches("%.go") and
result = "//"
Comment thread
d10c marked this conversation as resolved.
}
}
1 change: 1 addition & 0 deletions java/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import java
Expand Down
11 changes: 11 additions & 0 deletions java/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module Impl implements InlineExpectationsTestSig {
abstract class ExpectationComment extends J::Top {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
abstract string getContents();

/** Java expectation comments use line-comment syntax. */
predicate isLineComment() { any() }
}

private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
Expand Down Expand Up @@ -45,4 +48,12 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// Java databases can also contain XML; those files use a different (block) comment
// syntax that is not yet supported, so we only render for Java and Kotlin sources.
relativePath.matches(["%.java", "%.kt"]) and
result = "//"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module Impl implements InlineExpectationsTestSig {
abstract class ExpectationComment extends J::Top {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
abstract string getContents();

/** Java and Kotlin expectation comments use line-comment syntax. */
predicate isLineComment() { any() }
}

private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
Expand Down Expand Up @@ -42,4 +45,10 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
relativePath.matches(["%.java", "%.kt"]) and
result = "//"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module Impl implements InlineExpectationsTestSig {
abstract class ExpectationComment extends J::Top {
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
abstract string getContents();

/** Java and Kotlin expectation comments use line-comment syntax. */
predicate isLineComment() { any() }
}

private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {
Expand Down Expand Up @@ -42,4 +45,10 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
relativePath.matches(["%.java", "%.kt"]) and
result = "//"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import javascript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ module Impl implements InlineExpectationsTestSig {
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// JavaScript databases can also contain HTML, whose block-comment syntax is not yet
// supported, so we only render for line-comment source files.
relativePath.regexpMatch(".*\\.(js|cjs|mjs|jsx|ts|cts|mts|tsx)") and
result = "//"
Comment thread
d10c marked this conversation as resolved.
}

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

/** Holds if this comment uses line-comment syntax. */
predicate isLineComment() { this instanceof LineComment }

/** Gets this element's location. */
Location getLocation() { result = super.getLocation() }
}
Expand Down
1 change: 1 addition & 0 deletions python/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ 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 ExpectationComment extends PY::Comment {
/** Python comments use line-comment syntax. */
predicate isLineComment() { any() }
}

class Location = PY::Location;

Expand All @@ -19,4 +22,12 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// Python databases can also contain XML, whose block-comment syntax is not yet supported,
// so we only render for Python sources.
relativePath.regexpMatch(".*\\.(py|pyi)") and
result = "#"
}
}
1 change: 1 addition & 0 deletions ql/ql/src/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import ql
Expand Down
11 changes: 11 additions & 0 deletions ql/ql/src/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module Impl implements InlineExpectationsTestSig {
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
string getContents() { result = comment.getValue().suffix(2) }

/** QL expectation comments use line-comment syntax. */
predicate isLineComment() { any() }

/** Gets a textual representation of this element. */
string toString() { result = comment.toString() }

Expand All @@ -35,4 +38,12 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// The QL extractor can also extract YAML (e.g. `qlpack.yml`), whose `#` comment syntax
// differs, so we only render for QL sources and dbscheme files.
relativePath.regexpMatch(".*\\.(ql|qll|dbscheme)") and
result = "//"
}
}
1 change: 1 addition & 0 deletions ruby/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import ruby
Expand Down
11 changes: 11 additions & 0 deletions ruby/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module Impl implements InlineExpectationsTestSig {
or
result = this.asErbComment().getValue().suffix(1)
}

/** Holds if this is a Ruby `#` comment. */
predicate isLineComment() { exists(this.asRubyComment()) }
}

class Location = R::Location;
Expand All @@ -46,4 +49,12 @@ module Impl implements InlineExpectationsTestSig {
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
)
}

bindingset[relativePath]
string getStartCommentMarker(string relativePath) {
// Ruby databases can also contain ERB, whose comment syntax is not yet supported, so we
// only render for plain Ruby sources.
relativePath.matches("%.rb") and
result = "#"
}
}
12 changes: 6 additions & 6 deletions ruby/ql/test/library-tests/dataflow/array-flow/array_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,24 +371,24 @@ def m41
def m42(i)
a = [0, 1, source(42.1), source(42.2)]
b = a.drop(i)
sink(b[0]) # $ hasValueFlow=42.1 # $ hasValueFlow=42.2
sink(b[0]) # $ hasValueFlow=42.1 hasValueFlow=42.2
b = a.drop(1)
sink(b[0])
sink(b[1]) # $ hasValueFlow=42.1
sink(b[i]) # $ hasValueFlow=42.1 # $ hasValueFlow=42.2
sink(b[i]) # $ hasValueFlow=42.1 hasValueFlow=42.2
a[i] = source(42.3)
b = a.drop(1)
sink(b[1]) # $ hasValueFlow=42.1 # $ hasValueFlow=42.3
sink(b[1]) # $ hasValueFlow=42.1 hasValueFlow=42.3
c = b.drop(100)
sink(c[1]) # $ hasValueFlow=42.3
end

def m43
a = [0, 1, source(43.1), source(43.2)]
b = a.drop_while do |x|
sink x # $ hasValueFlow=43.1 # $ hasValueFlow=43.2
sink x # $ hasValueFlow=43.1 hasValueFlow=43.2
end
sink(b[0]) # $ hasValueFlow=43.1 # $ hasValueFlow=43.2
sink(b[0]) # $ hasValueFlow=43.1 hasValueFlow=43.2
end

def m44
Expand Down Expand Up @@ -1464,7 +1464,7 @@ def m121(i)
sink(b[i]) # $ hasValueFlow=121.1 $ hasValueFlow=121.2
a[i] = source(121.3)
b = a.take(3)
sink(b[2]) # $ hasValueFlow=121.1 # $ hasValueFlow=121.3
sink(b[2]) # $ hasValueFlow=121.1 hasValueFlow=121.3
end

def m122
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def call_method3 x
end

def self.singleton_method1 x
sink x # $ hasValueFlow=14 $ hasValueFlow=15 # $ hasValueFlow=16 $ hasValueFlow=17
sink x # $ hasValueFlow=14 hasValueFlow=15 hasValueFlow=16 hasValueFlow=17
end

def method4(x, y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def m43()
:c => taint(43.2)
}
a = hash.values
sink (a[0]) # $ hasValueFlow=43.1 # $ hasValueFlow=43.2
sink (a[0]) # $ hasValueFlow=43.1 hasValueFlow=43.2
end

m43()
Expand Down
1 change: 1 addition & 0 deletions rust/ql/lib/utils/test/InlineExpectationsTestQuery.ql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @kind test-postprocess
* @tags inline-expectation-test
*/

private import rust
Expand Down
Loading
Loading