Merge pull request #12212 from hvitved/util/inline-expect-test-use-end-line

Util: Use end line instead of start line for actual results
This commit is contained in:
Tom Hvitved
2023-02-20 11:41:02 +01:00
committed by GitHub
21 changed files with 94 additions and 94 deletions

View File

@@ -1,30 +1,30 @@
Something.foo.withCallback do |a, b| #$ use=getMember("Something").getMethod("foo").getReturn().getMethod("withCallback").getReturn()
Something.foo.withCallback do |a, b| #$ use=getMember("Something").getMethod("foo").getReturn()
a.something #$ use=getMember("Something").getMethod("foo").getReturn().getMethod("withCallback").getBlock().getParameter(0).getMethod("something").getReturn()
b.somethingElse #$ use=getMember("Something").getMethod("foo").getReturn().getMethod("withCallback").getBlock().getParameter(1).getMethod("somethingElse").getReturn()
end
end #$ use=getMember("Something").getMethod("foo").getReturn().getMethod("withCallback").getReturn()
Something.withNamedArg do |a:, b: nil| #$ use=getMember("Something").getMethod("withNamedArg").getReturn()
Something.withNamedArg do |a:, b: nil| #$ use=getMember("Something")
a.something #$ use=getMember("Something").getMethod("withNamedArg").getBlock().getKeywordParameter("a").getMethod("something").getReturn()
b.somethingElse #$ use=getMember("Something").getMethod("withNamedArg").getBlock().getKeywordParameter("b").getMethod("somethingElse").getReturn()
end
end #$ use=getMember("Something").getMethod("withNamedArg").getReturn()
Something.withLambda ->(a, b) { #$ use=getMember("Something").getMethod("withLambda").getReturn()
Something.withLambda ->(a, b) { #$ use=getMember("Something")
a.something #$ use=getMember("Something").getMethod("withLambda").getParameter(0).getParameter(0).getMethod("something").getReturn()
b.something #$ use=getMember("Something").getMethod("withLambda").getParameter(0).getParameter(1).getMethod("something").getReturn()
}
} #$ use=getMember("Something").getMethod("withLambda").getReturn()
Something.namedCallback( #$ use=getMember("Something").getMethod("namedCallback").getReturn()
Something.namedCallback( #$ use=getMember("Something")
onEvent: ->(a, b) {
a.something #$ use=getMember("Something").getMethod("namedCallback").getKeywordParameter("onEvent").getParameter(0).getMethod("something").getReturn()
b.something #$ use=getMember("Something").getMethod("namedCallback").getKeywordParameter("onEvent").getParameter(1).getMethod("something").getReturn()
}
)
) #$ use=getMember("Something").getMethod("namedCallback").getReturn()
Something.nestedCall1 do |a| #$ use=getMember("Something").getMethod("nestedCall1").getReturn()
a.nestedCall2 do |b:| #$ use=getMember("Something").getMethod("nestedCall1").getBlock().getParameter(0).getMethod("nestedCall2").getReturn()
Something.nestedCall1 do |a| #$ use=getMember("Something")
a.nestedCall2 do |b:| #$ use=getMember("Something").getMethod("nestedCall1").getBlock().getParameter(0)
b.something #$ use=getMember("Something").getMethod("nestedCall1").getBlock().getParameter(0).getMethod("nestedCall2").getBlock().getKeywordParameter("b").getMethod("something").getReturn()
end
end
end #$ use=getMember("Something").getMethod("nestedCall1").getBlock().getParameter(0).getMethod("nestedCall2").getReturn()
end #$ use=getMember("Something").getMethod("nestedCall1").getReturn()
def getCallback()
->(x) {
@@ -33,7 +33,7 @@ def getCallback()
end
Something.indirectCallback(getCallback()) #$ use=getMember("Something").getMethod("indirectCallback").getReturn()
Something.withMixed do |a, *args, b| #$ use=getMember("Something").getMethod("withMixed").getReturn()
Something.withMixed do |a, *args, b| #$ use=getMember("Something")
a.something #$ use=getMember("Something").getMethod("withMixed").getBlock().getParameter(0).getMethod("something").getReturn()
# b.something # not currently handled correctly
end
end #$ use=getMember("Something").getMethod("withMixed").getReturn()

View File

@@ -13,9 +13,9 @@ Unknown.new.run #$ use=getMember("Unknown").getMethod("new").getReturn().getMeth
Foo::Bar::Baz #$ use=getMember("Foo").getMember("Bar").getMember("Baz")
Const = [1, 2, 3] #$ use=getMember("Array").getMethod("[]").getReturn()
Const.each do |c| #$ use=getMember("Const").getMethod("each").getReturn() def=getMember("Const").getMethod("each").getBlock()
Const.each do |c| #$ use=getMember("Const")
puts c #$ use=getMember("Const").getMethod("each").getBlock().getParameter(0) use=getMember("Const").getContent(element)
end
end #$ use=getMember("Const").getMethod("each").getReturn() def=getMember("Const").getMethod("each").getBlock()
foo = Foo #$ use=getMember("Foo")
foo::Bar::Baz #$ use=getMember("Foo").getMember("Bar").getMember("Baz")

View File

@@ -44,7 +44,7 @@ class ApiUseTest extends InlineExpectationsTest {
max(API::Node a2, Location l2, DataFlow::Node n2 |
relevantNode(a2, n2, l2, tag) and
l2.getFile() = location.getFile() and
l2.getStartLine() = location.getStartLine()
l2.getEndLine() = location.getEndLine()
|
a2.getPath()
order by

View File

@@ -44,9 +44,9 @@ end
def m8
sink(s8 { source "a" }) # $ hasValueFlow=a
sink(s8 do # $hasValueFlow=a
sink(s8 do
source "a"
end)
end) # $hasValueFlow=a
end
def m9

View File

@@ -47,54 +47,54 @@ def m6(arg1, arg2)
end
# Bad: method has parameter but only one result is memoized.
def m7(arg) # $result=BAD
def m7(arg)
@m7 ||= begin
arg += 3
end
@m7
end
end # $result=BAD
# Bad: method has parameter but only one result is memoized.
def m8(arg) # $result=BAD
def m8(arg)
@m8 ||= begin
long_running_method(arg)
end
@m8
end
end # $result=BAD
# Bad: method has parameter but only one result is memoized.
def m9(arg) # $result=BAD
def m9(arg)
@m9 ||= long_running_method(arg)
end
end # $result=BAD
# Bad: method has parameter but only one result is memoized.
def m10(arg1, arg2) # $result=BAD
def m10(arg1, arg2)
@m10 ||= long_running_method(arg1, arg2)
end
end # $result=BAD
# Bad: `arg2` not used in key.
def m11(arg1, arg2) # $result=BAD
def m11(arg1, arg2)
@m11 ||= {}
@m11[arg1] ||= long_running_method(arg1, arg2)
end
end # $result=BAD
# Bad: `arg2` not used in key.
def m12(arg1, arg2) # $result=BAD
def m12(arg1, arg2)
@m12 ||= Hash.new do |h1, arg1|
h1[arg1] = result(arg1, arg2)
end
@m12[arg1]
end
end # $result=BAD
# Bad: arg not used in key.
def m13(id:) # $result=BAD
def m13(id:)
@m13 ||= Rails.cache.fetch("product_sku/#{id}", expires_in: 30.minutes) do
ActiveRecord::Base.transaction do
ProductSku.find_by(id: id)
end
end
@m13
end
end # $result=BAD
# Good (FP): arg is used in key via string interpolation.
def m14(arg)

View File

@@ -80,9 +80,9 @@ def m9(x)
x = x.gsub(/^(\.\.\/?)+/, "") # OK
# NOT OK
x = x.gsub(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/) do |match| # $ hasResult=html
x = x.gsub(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/) do |match|
if unknown then match else "" end
end
end # $ hasResult=html
x = x.gsub(/<\/?([a-z][a-z0-9]*)\b[^>]*>/i, "") # NOT OK [INCONSISTENCY] $ hasResult=html
@@ -113,10 +113,10 @@ def m9(x)
x = x.gsub(/<!\-\-DEVEL[\d\D]*?DEVEL\-\->/, "") # OK
x = x # $ hasResult=path
x = x
.gsub(/^\.\//, "")
.gsub(/\/\.\//, "/")
.gsub(/[^\/]*\/\.\.\//, "")
.gsub(/[^\/]*\/\.\.\//, "") # $ hasResult=path
x
end