Skip to content

Commit 3737248

Browse files
authored
Merge pull request #8879 from github/nickrolfe/graph_ordering
Ruby: fix graph query tests by defining total ordering
2 parents 76f2eca + a2f66e8 commit 3737248

File tree

4 files changed

+195
-135
lines changed

4 files changed

+195
-135
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
calls.rb:
2-
# 102| Hash
3-
#-----| super -> Object
4-
5-
# 77| Integer
6-
#-----| super -> Numeric
7-
8-
# 86| Kernel
9-
10-
# 90| Module
11-
#-----| super -> Object
12-
13-
# 97| Object
14-
#-----| include -> Kernel
15-
#-----| super -> BasicObject
16-
#-----| prepend -> A
17-
18-
# 106| Array
19-
#-----| super -> Object
20-
211
#-----| BasicObject
222

233
#-----| Class
@@ -48,18 +28,38 @@ calls.rb:
4828
#-----| TrueClass
4929
#-----| super -> Object
5030

31+
calls.rb:
5132
# 15| M
5233

5334
# 29| C
54-
#-----| super -> Object
5535
#-----| include -> M
36+
#-----| super -> Object
5637

5738
# 51| D
5839
#-----| super -> C
5940

41+
# 77| Integer
42+
#-----| super -> Numeric
43+
6044
# 82| String
6145
#-----| super -> Object
6246

47+
# 86| Kernel
48+
49+
# 90| Module
50+
#-----| super -> Object
51+
52+
# 97| Object
53+
#-----| super -> BasicObject
54+
#-----| include -> Kernel
55+
#-----| prepend -> A
56+
57+
# 102| Hash
58+
#-----| super -> Object
59+
60+
# 106| Array
61+
#-----| super -> Object
62+
6363
# 144| S
6464
#-----| super -> Object
6565

@@ -86,61 +86,73 @@ modules.rb:
8686

8787
# 4| Foo
8888

89+
# 5| Foo::Bar
90+
91+
# 6| Foo::Bar::ClassInFooBar
92+
#-----| super -> Object
93+
94+
# 19| Foo::ClassInFoo
95+
#-----| super -> Object
96+
97+
# 30| Foo::ClassInAnotherDefinitionOfFoo
98+
#-----| super -> Object
99+
89100
# 37| Bar
90101
#-----| super -> Object
91102

103+
# 49| Foo::Bar::ClassInAnotherDefinitionOfFooBar
104+
#-----| super -> Object
105+
92106
# 60| MyModuleInGlobalScope
93107

94108
# 63| Test
95109

110+
# 65| Test::Foo1
111+
112+
# 66| Test::Foo1::Bar
113+
#-----| super -> Object
114+
115+
# 70| Test::Foo2
116+
117+
# 71| Test::Foo2::Foo2
118+
119+
# 72| Test::Foo2::Foo2::Bar
120+
#-----| super -> Object
121+
122+
# 76| Test::Foo3
123+
96124
# 83| Other
97125

126+
# 84| Other::Foo1
127+
98128
# 88| IncludeTest
99129
#-----| include -> Test
100130

131+
# 91| Test::Foo1::Y
132+
101133
# 95| IncludeTest2
102134
#-----| include -> Test
103135

136+
# 97| Test::Foo1::Z
137+
104138
# 101| PrependTest
105139
#-----| prepend -> Test
106140

141+
# 103| Test::Foo2::Y
142+
107143
# 107| MM
108144

145+
# 108| MM::MM
146+
109147
# 112| YY
110148
#-----| super -> Object
111149

112150
# 115| XX
113151

114-
private.rb:
115-
# 1| E
116-
#-----| super -> Object
117-
118-
# 42| F
119-
120-
modules.rb:
121-
# 5| Foo::Bar
122-
123-
# 19| Foo::ClassInFoo
124-
#-----| super -> Object
125-
126-
# 30| Foo::ClassInAnotherDefinitionOfFoo
127-
#-----| super -> Object
128-
129152
# 116| XX::YY
130153
#-----| super -> YY
131154

132-
# 65| Test::Foo1
133-
134-
# 70| Test::Foo2
135-
136-
# 76| Test::Foo3
137-
138-
# 84| Other::Foo1
139-
140-
# 6| Foo::Bar::ClassInFooBar
141-
#-----| super -> Object
142-
143-
# 71| Test::Foo2::Foo2
155+
# 120| Test::Foo1::Bar::Baz
144156

145157
modules_rec.rb:
146158
# 1| B::A
@@ -149,22 +161,8 @@ modules_rec.rb:
149161
# 4| A::B
150162
#-----| super -> Object
151163

152-
modules.rb:
153-
# 108| MM::MM
154-
155-
# 49| Foo::Bar::ClassInAnotherDefinitionOfFooBar
156-
#-----| super -> Object
157-
158-
# 66| Test::Foo1::Bar
159-
#-----| super -> Object
160-
161-
# 91| Test::Foo1::Y
162-
163-
# 97| Test::Foo1::Z
164-
165-
# 103| Test::Foo2::Y
166-
167-
# 72| Test::Foo2::Foo2::Bar
164+
private.rb:
165+
# 1| E
168166
#-----| super -> Object
169167

170-
# 120| Test::Foo1::Bar::Baz
168+
# 42| F

ruby/ql/test/library-tests/modules/ancestors.ql

+38-7
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,46 @@ import ruby
77

88
query predicate nodes(Module node, string key, string value) {
99
key = "semmle.label" and value = node.toString()
10+
or
11+
key = "semmle.order" and
12+
value =
13+
any(int i |
14+
node =
15+
rank[i](Module m, Location l |
16+
l = m.getLocation()
17+
|
18+
m
19+
order by
20+
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
21+
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), m.toString()
22+
)
23+
).toString()
24+
}
25+
26+
Module getATarget(Module source, string value) {
27+
result = source.getSuperClass() and value = "super"
28+
or
29+
result = source.getAPrependedModule() and value = "prepend"
30+
or
31+
result = source.getAnIncludedModule() and value = "include"
1032
}
1133

1234
query predicate edges(Module source, Module target, string key, string value) {
1335
key = "semmle.label" and
14-
(
15-
target = source.getSuperClass() and value = "super"
16-
or
17-
target = source.getAPrependedModule() and value = "prepend"
18-
or
19-
target = source.getAnIncludedModule() and value = "include"
20-
)
36+
target = getATarget(source, value)
37+
or
38+
key = "semmle.order" and
39+
value =
40+
any(int i |
41+
target =
42+
rank[i](Module t, Location l |
43+
t = getATarget(source, _) and
44+
l = t.getLocation()
45+
|
46+
t
47+
order by
48+
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
49+
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), t.toString()
50+
)
51+
).toString()
2152
}

0 commit comments

Comments
 (0)