Skip to content

Commit f353a17

Browse files
authored
Merge pull request #22081 from geoffw0/rubyinline2
Ruby: Address testFailures in inline expectations tests (part 2)
2 parents f1cc1e5 + d519f79 commit f353a17

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

ruby/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,35 @@ private import codeql.util.test.InlineExpectationsTest
44
module Impl implements InlineExpectationsTestSig {
55
private import codeql.ruby.ast.internal.TreeSitter
66

7+
private newtype TAnyComment =
8+
RubyComment(Ruby::Comment comment) or
9+
ErbComment(R::ErbComment comment)
10+
711
/**
8-
* A class representing line comments in Ruby.
12+
* A class representing comments that may contain inline expectations (Ruby line comments and ERB comments).
913
*/
10-
class ExpectationComment extends Ruby::Comment {
11-
string getContents() { result = this.getValue().suffix(1) }
14+
class ExpectationComment extends TAnyComment {
15+
Ruby::Comment asRubyComment() { this = RubyComment(result) }
16+
17+
R::ErbComment asErbComment() { this = ErbComment(result) }
18+
19+
string toString() {
20+
result = this.asRubyComment().toString()
21+
or
22+
result = this.asErbComment().toString()
23+
}
24+
25+
Location getLocation() {
26+
result = this.asRubyComment().getLocation()
27+
or
28+
result = this.asErbComment().getLocation()
29+
}
30+
31+
string getContents() {
32+
result = this.asRubyComment().getValue().suffix(1)
33+
or
34+
result = this.asErbComment().getValue().suffix(1)
35+
}
1236
}
1337

1438
class Location = R::Location;

ruby/ql/test/library-tests/frameworks/sinatra/Flow.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ nodes
2323
| views/index.erb:2:10:2:12 | call to foo | semmle.label | call to foo |
2424
subpaths
2525
testFailures
26-
| views/index.erb:2:10:2:12 | call to foo | Unexpected result: hasTaintFlow |
2726
#select
2827
| app.rb:95:10:95:14 | @user | app.rb:103:13:103:22 | call to source | app.rb:95:10:95:14 | @user | $@ | app.rb:103:13:103:22 | call to source | call to source |
2928
| views/index.erb:2:10:2:12 | call to foo | app.rb:75:12:75:17 | call to params | views/index.erb:2:10:2:12 | call to foo | $@ | app.rb:75:12:75:17 | call to params | call to params |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<%= @foo %>
2-
<%= sink foo %>
2+
<%= sink foo %> <%# $ hasTaintFlow %>

ruby/ql/test/query-tests/experimental/improper-memoization/ImproperMemoization.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
testFailures
2-
| improper_memoization.rb:100:1:104:3 | m14 | Unexpected result: result=BAD |
32
#select
43
| improper_memoization.rb:50:1:55:3 | m7 | improper_memoization.rb:50:8:50:10 | arg | improper_memoization.rb:51:3:53:5 | ... \|\|= ... |
54
| improper_memoization.rb:58:1:63:3 | m8 | improper_memoization.rb:58:8:58:10 | arg | improper_memoization.rb:59:3:61:5 | ... \|\|= ... |

ruby/ql/test/query-tests/experimental/improper-memoization/improper_memoization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ def m14(arg)
101101
@m14 ||= {}
102102
key = "foo/#{arg}"
103103
@m14[key] ||= long_running_method(arg)
104-
end
104+
end # $ SPURIOUS: result=BAD

0 commit comments

Comments
 (0)