Skip to content

Commit ff32119

Browse files
committed
Rust: improve modules test case
1 parent e5b0397 commit ff32119

File tree

3 files changed

+73
-48
lines changed

3 files changed

+73
-48
lines changed

rust/ql/test/extractor-tests/crate_graph/crates.expected

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
#-----| Crate(allocator_api2@0.2.21)
1+
#-----| Crate(allocator_api2@0.2.18)
22

33
#-----| Crate(core@0.0.0)
44
#-----| -> Crate(rand@0.8.5)
55
#-----| -> Crate(rand_xorshift@0.3.0)
66

7-
#-----| Crate(compiler_builtins@0.1.140)
7+
#-----| Crate(compiler_builtins@0.1.138)
88
#-----| -> Crate(core@0.0.0)
99

1010
#-----| Crate(cfg_if@1.0.0)
1111
#-----| -> Crate(core@0.0.0)
12-
#-----| -> Crate(compiler_builtins@0.1.140)
12+
#-----| -> Crate(compiler_builtins@0.1.138)
1313

1414
#-----| Crate(std@0.0.0)
1515
#-----| -> Crate(core@0.0.0)
16-
#-----| -> Crate(compiler_builtins@0.1.140)
16+
#-----| -> Crate(compiler_builtins@0.1.138)
1717
#-----| -> Crate(cfg_if@1.0.0)
1818
#-----| -> Crate(alloc@0.0.0)
19-
#-----| -> Crate(hashbrown@0.15.2)
20-
#-----| -> Crate(libc@0.2.169)
19+
#-----| -> Crate(hashbrown@0.15.0)
20+
#-----| -> Crate(libc@0.2.162)
2121
#-----| -> Crate(rand@0.8.5)
2222
#-----| -> Crate(rand_xorshift@0.3.0)
2323
#-----| -> Crate(rustc_demangle@0.1.24)
@@ -28,7 +28,7 @@
2828

2929
#-----| Crate(unicode_width@0.1.14)
3030
#-----| -> Crate(core@0.0.0)
31-
#-----| -> Crate(compiler_builtins@0.1.140)
31+
#-----| -> Crate(compiler_builtins@0.1.138)
3232
#-----| -> Crate(std@0.0.0)
3333

3434
#-----| Crate(getopts@0.2.21)
@@ -38,17 +38,17 @@
3838

3939
#-----| Crate(alloc@0.0.0)
4040
#-----| -> Crate(core@0.0.0)
41-
#-----| -> Crate(compiler_builtins@0.1.140)
41+
#-----| -> Crate(compiler_builtins@0.1.138)
4242
#-----| -> Crate(rand@0.8.5)
4343
#-----| -> Crate(rand_xorshift@0.3.0)
4444

45-
#-----| Crate(hashbrown@0.15.2)
46-
#-----| -> Crate(allocator_api2@0.2.21)
45+
#-----| Crate(hashbrown@0.15.0)
46+
#-----| -> Crate(allocator_api2@0.2.18)
4747
#-----| -> Crate(core@0.0.0)
48-
#-----| -> Crate(compiler_builtins@0.1.140)
48+
#-----| -> Crate(compiler_builtins@0.1.138)
4949
#-----| -> Crate(alloc@0.0.0)
5050

51-
#-----| Crate(libc@0.2.169)
51+
#-----| Crate(libc@0.2.162)
5252
#-----| -> Crate(core@0.0.0)
5353

5454
#-----| Crate(rand_core@0.6.4)
@@ -61,27 +61,27 @@
6161

6262
#-----| Crate(rustc_demangle@0.1.24)
6363
#-----| -> Crate(core@0.0.0)
64-
#-----| -> Crate(compiler_builtins@0.1.140)
64+
#-----| -> Crate(compiler_builtins@0.1.138)
6565

6666
#-----| Crate(panic_abort@0.0.0)
6767
#-----| -> Crate(core@0.0.0)
68-
#-----| -> Crate(compiler_builtins@0.1.140)
68+
#-----| -> Crate(compiler_builtins@0.1.138)
6969
#-----| -> Crate(cfg_if@1.0.0)
7070
#-----| -> Crate(alloc@0.0.0)
71-
#-----| -> Crate(libc@0.2.169)
71+
#-----| -> Crate(libc@0.2.162)
7272

7373
#-----| Crate(unwind@0.0.0)
7474
#-----| -> Crate(core@0.0.0)
75-
#-----| -> Crate(compiler_builtins@0.1.140)
75+
#-----| -> Crate(compiler_builtins@0.1.138)
7676
#-----| -> Crate(cfg_if@1.0.0)
77-
#-----| -> Crate(libc@0.2.169)
77+
#-----| -> Crate(libc@0.2.162)
7878

7979
#-----| Crate(panic_unwind@0.0.0)
8080
#-----| -> Crate(core@0.0.0)
81-
#-----| -> Crate(compiler_builtins@0.1.140)
81+
#-----| -> Crate(compiler_builtins@0.1.138)
8282
#-----| -> Crate(cfg_if@1.0.0)
8383
#-----| -> Crate(alloc@0.0.0)
84-
#-----| -> Crate(libc@0.2.169)
84+
#-----| -> Crate(libc@0.2.162)
8585
#-----| -> Crate(unwind@0.0.0)
8686

8787
#-----| Crate(proc_macro@0.0.0)
@@ -90,16 +90,16 @@
9090

9191
#-----| Crate(std_detect@0.1.5)
9292
#-----| -> Crate(core@0.0.0)
93-
#-----| -> Crate(compiler_builtins@0.1.140)
93+
#-----| -> Crate(compiler_builtins@0.1.138)
9494
#-----| -> Crate(cfg_if@1.0.0)
9595
#-----| -> Crate(alloc@0.0.0)
96-
#-----| -> Crate(libc@0.2.169)
96+
#-----| -> Crate(libc@0.2.162)
9797

9898
#-----| Crate(test@0.0.0)
9999
#-----| -> Crate(core@0.0.0)
100100
#-----| -> Crate(std@0.0.0)
101101
#-----| -> Crate(getopts@0.2.21)
102-
#-----| -> Crate(libc@0.2.169)
102+
#-----| -> Crate(libc@0.2.162)
103103

104104
#-----| Crate(test@0.0.1)
105105
#-----| -> Crate(core@0.0.0)
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
1-
#-----| fn as_string
1+
#-----| Const
22

3-
#-----| fn length
3+
#-----| Static
44

5-
#-----| fn write
5+
#-----| enum X
6+
7+
#-----| fn as_string
68

79
#-----| fn as_string
810

911
#-----| fn fmt
1012

11-
#-----| struct X_List
13+
#-----| fn length
1214

13-
#-----| Static
15+
#-----| impl ...::Display for ...::X { ... }
16+
#-----| -> fn fmt
17+
18+
#-----| impl AsString for ...::X { ... }
19+
#-----| -> fn as_string
20+
21+
#-----| mod crate
22+
#-----| -> mod module
1423

1524
#-----| mod module
25+
#-----| -> Const
26+
#-----| -> Static
27+
#-----| -> enum X
1628
#-----| -> fn length
17-
#-----| -> fn write
29+
#-----| -> impl ...::Display for ...::X { ... }
30+
#-----| -> impl AsString for ...::X { ... }
1831
#-----| -> struct X_List
19-
#-----| -> Static
2032
#-----| -> trait AsString
21-
#-----| -> Const
22-
#-----| -> impl AsString for ...::X { ... }
23-
#-----| -> impl ...::Display for ...::X { ... }
24-
#-----| -> enum X
2533

26-
#-----| mod crate
27-
#-----| -> mod module
34+
#-----| struct X_List
2835

2936
#-----| trait AsString
3037
#-----| -> fn as_string
31-
32-
#-----| Const
33-
34-
#-----| impl AsString for ...::X { ... }
35-
#-----| -> fn as_string
36-
37-
#-----| impl ...::Display for ...::X { ... }
38-
#-----| -> fn fmt
39-
40-
#-----| enum X

rust/ql/test/extractor-tests/crate_graph/modules.ql

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,40 @@
66

77
import rust
88

9-
query predicate nodes(Item i) {
10-
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
9+
predicate nodes(Item i) { i instanceof RelevantNode }
10+
11+
class RelevantNode extends Item {
12+
RelevantNode() {
13+
this.getParentNode*() =
14+
any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
15+
}
1116
}
1217

13-
query predicate edges(Item container, Item element) {
18+
predicate edges(RelevantNode container, RelevantNode element) {
1419
element = container.(Module).getItemList().getAnItem() or
1520
element = container.(Impl).getAssocItemList().getAnAssocItem() or
1621
element = container.(Trait).getAssocItemList().getAnAssocItem()
1722
}
23+
24+
query predicate nodes(RelevantNode node, string attr, string val) {
25+
nodes(node) and
26+
(
27+
attr = "semmle.label" and
28+
val = node.toString()
29+
or
30+
attr = "semmle.order" and
31+
val =
32+
any(int i | node = rank[i](RelevantNode n | nodes(n) | n order by n.toString())).toString()
33+
)
34+
}
35+
36+
query predicate edges(RelevantNode pred, RelevantNode succ, string attr, string val) {
37+
edges(pred, succ) and
38+
(
39+
attr = "semmle.label" and
40+
val = ""
41+
or
42+
attr = "semmle.order" and
43+
val = any(int i | succ = rank[i](Item s | edges(pred, s) | s order by s.toString())).toString()
44+
)
45+
}

0 commit comments

Comments
 (0)