Skip to content

Commit 4485560

Browse files
committed
Ruby: Rewrite inline expectation tests to use parameterized module
1 parent 9633f00 commit 4485560

File tree

12 files changed

+43
-34
lines changed

12 files changed

+43
-34
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

ruby/ql/test/library-tests/concepts/CryptographicOperation.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import codeql.ruby.AST
22
import codeql.ruby.Concepts
33
import TestUtilities.InlineExpectationsTest
44

5-
class CryptographicOperationTest extends InlineExpectationsTest {
6-
CryptographicOperationTest() { this = "CryptographicOperationTest" }
7-
8-
override string getARelevantTag() {
5+
module CryptographicOperationTest implements TestSig {
6+
string getARelevantTag() {
97
result in [
108
"CryptographicOperation", "CryptographicOperationInput", "CryptographicOperationAlgorithm",
119
"CryptographicOperationBlockMode"
1210
]
1311
}
1412

15-
override predicate hasActualResult(Location location, string element, string tag, string value) {
13+
predicate hasActualResult(Location location, string element, string tag, string value) {
1614
exists(Cryptography::CryptographicOperation cryptoOperation |
1715
location = cryptoOperation.getLocation() and
1816
(
@@ -31,3 +29,5 @@ class CryptographicOperationTest extends InlineExpectationsTest {
3129
)
3230
}
3331
}
32+
33+
import MakeTest<CryptographicOperationTest>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

ruby/ql/test/library-tests/dataflow/api-graphs/use.ql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ class CustomEntryPointUse extends API::EntryPoint {
1717
}
1818
}
1919

20-
class ApiUseTest extends InlineExpectationsTest {
21-
ApiUseTest() { this = "ApiUseTest" }
22-
23-
override string getARelevantTag() { result = ["use", "def", "call"] }
20+
module ApiUseTest implements TestSig {
21+
string getARelevantTag() { result = ["use", "def", "call"] }
2422

2523
private predicate relevantNode(API::Node a, DataFlow::Node n, Location l, string tag) {
2624
l = n.getLocation() and
@@ -36,13 +34,13 @@ class ApiUseTest extends InlineExpectationsTest {
3634
)
3735
}
3836

39-
override predicate hasActualResult(Location location, string element, string tag, string value) {
37+
predicate hasActualResult(Location location, string element, string tag, string value) {
4038
tag = "use" and // def tags are always optional
41-
exists(DataFlow::Node n | this.relevantNode(_, n, location, tag) |
39+
exists(DataFlow::Node n | relevantNode(_, n, location, tag) |
4240
// Only report the longest path on this line:
4341
value =
4442
max(API::Node a2, Location l2, DataFlow::Node n2 |
45-
this.relevantNode(a2, n2, l2, tag) and
43+
relevantNode(a2, n2, l2, tag) and
4644
l2.getFile() = location.getFile() and
4745
l2.getEndLine() = location.getEndLine()
4846
|
@@ -56,14 +54,16 @@ class ApiUseTest extends InlineExpectationsTest {
5654

5755
// We also permit optional annotations for any other path on the line.
5856
// This is used to test subclass paths, which typically have a shorter canonical path.
59-
override predicate hasOptionalResult(Location location, string element, string tag, string value) {
60-
exists(API::Node a, DataFlow::Node n | this.relevantNode(a, n, location, tag) |
57+
predicate hasOptionalResult(Location location, string element, string tag, string value) {
58+
exists(API::Node a, DataFlow::Node n | relevantNode(a, n, location, tag) |
6159
element = n.toString() and
6260
value = getAPath(a, _)
6361
)
6462
}
6563
}
6664

65+
import MakeTest<ApiUseTest>
66+
6767
private int size(AstNode n) { not n instanceof StmtSequence and result = count(n.getAChild*()) }
6868

6969
/**

ruby/ql/test/library-tests/dataflow/barrier-guards/barrier-guards.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
WARNING: Type BarrierGuard has been deprecated and may be removed in future (barrier-guards.ql:10,3-15)
22
failures
3+
testFailures
34
oldStyleBarrierGuards
45
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:5:4:7 | foo | barrier-guards.rb:3:4:3:6 | foo | true |
56
| barrier-guards.rb:3:4:3:15 | ... == ... | barrier-guards.rb:4:5:4:7 | foo | barrier-guards.rb:3:11:3:15 | "foo" | true |

ruby/ql/test/library-tests/dataflow/barrier-guards/barrier-guards.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ query predicate controls(CfgNode condition, BasicBlock bb, SuccessorTypes::Condi
2424
)
2525
}
2626

27-
class BarrierGuardTest extends InlineExpectationsTest {
28-
BarrierGuardTest() { this = "BarrierGuardTest" }
27+
module BarrierGuardTest implements TestSig {
28+
string getARelevantTag() { result = "guarded" }
2929

30-
override string getARelevantTag() { result = "guarded" }
31-
32-
override predicate hasActualResult(Location location, string element, string tag, string value) {
30+
predicate hasActualResult(Location location, string element, string tag, string value) {
3331
tag = "guarded" and
3432
exists(DataFlow::Node n |
3533
newStyleBarrierGuards(n) and
@@ -39,3 +37,5 @@ class BarrierGuardTest extends InlineExpectationsTest {
3937
)
4038
}
4139
}
40+
41+
import MakeTest<BarrierGuardTest>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
failures
2+
testFailures
23
| improper_memoization.rb:100:1:104:3 | m14 | Unexpected result: result=BAD |
34
#select
45
| improper_memoization.rb:50:1:55:3 | m7 | improper_memoization.rb:50:8:50:10 | arg | improper_memoization.rb:51:3:53:5 | ... \|\|= ... |

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import codeql.ruby.AST
22
import TestUtilities.InlineExpectationsTest
33
import codeql.ruby.security.ImproperMemoizationQuery
44

5-
class ImproperMemoizationTest extends InlineExpectationsTest {
6-
ImproperMemoizationTest() { this = "ImproperMemoizationTest" }
5+
module ImproperMemoizationTest implements TestSig {
6+
string getARelevantTag() { result = "result" }
77

8-
override string getARelevantTag() { result = "result" }
9-
10-
override predicate hasActualResult(Location location, string element, string tag, string value) {
8+
predicate hasActualResult(Location location, string element, string tag, string value) {
119
tag = "result" and
1210
value = "BAD" and
1311
exists(Expr e |
@@ -18,6 +16,8 @@ class ImproperMemoizationTest extends InlineExpectationsTest {
1816
}
1917
}
2018

19+
import MakeTest<ImproperMemoizationTest>
20+
2121
from Method m, Parameter p, AssignLogicalOrExpr s
2222
where isImproperMemoizationMethod(m, p, s)
2323
select m, p, s
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failures
2+
testFailures

ruby/ql/test/query-tests/security/cwe-116/IncompleteMultiCharacterSanitization/IncompleteMultiCharacterSanitization.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import codeql.ruby.DataFlow
88
import codeql.ruby.security.IncompleteMultiCharacterSanitizationQuery as Query
99
import TestUtilities.InlineExpectationsTest
1010

11-
class Test extends InlineExpectationsTest {
12-
Test() { this = "IncompleteMultiCharacterSanitizationTest" }
11+
module Test implements TestSig {
12+
string getARelevantTag() { result = "hasResult" }
1313

14-
override string getARelevantTag() { result = "hasResult" }
15-
16-
override predicate hasActualResult(Location location, string element, string tag, string value) {
14+
predicate hasActualResult(Location location, string element, string tag, string value) {
1715
tag = "hasResult" and
1816
hasResult(location, element, value)
1917
}
2018
}
2119

20+
import MakeTest<Test>
21+
2222
predicate hasResult(Location location, string element, string value) {
2323
exists(DataFlow::Node replace, string kind |
2424
replace.getLocation() = location and

0 commit comments

Comments
 (0)