Skip to content

Commit fce637f

Browse files
committed
Rust: add some tests for the crate graph
1 parent 8ec8824 commit fce637f

File tree

6 files changed

+230
-0
lines changed

6 files changed

+230
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#-----| Crate(allocator_api2@0.2.21)
2+
3+
#-----| Crate(core@0.0.0)
4+
#-----| -> Crate(rand@0.8.5)
5+
#-----| -> Crate(rand_xorshift@0.3.0)
6+
7+
#-----| Crate(compiler_builtins@0.1.140)
8+
#-----| -> Crate(core@0.0.0)
9+
10+
#-----| Crate(cfg_if@1.0.0)
11+
#-----| -> Crate(core@0.0.0)
12+
#-----| -> Crate(compiler_builtins@0.1.140)
13+
14+
#-----| Crate(std@0.0.0)
15+
#-----| -> Crate(core@0.0.0)
16+
#-----| -> Crate(compiler_builtins@0.1.140)
17+
#-----| -> Crate(cfg_if@1.0.0)
18+
#-----| -> Crate(alloc@0.0.0)
19+
#-----| -> Crate(hashbrown@0.15.2)
20+
#-----| -> Crate(libc@0.2.169)
21+
#-----| -> Crate(rand@0.8.5)
22+
#-----| -> Crate(rand_xorshift@0.3.0)
23+
#-----| -> Crate(rustc_demangle@0.1.24)
24+
#-----| -> Crate(panic_abort@0.0.0)
25+
#-----| -> Crate(unwind@0.0.0)
26+
#-----| -> Crate(panic_unwind@0.0.0)
27+
#-----| -> Crate(std_detect@0.1.5)
28+
29+
#-----| Crate(unicode_width@0.1.14)
30+
#-----| -> Crate(core@0.0.0)
31+
#-----| -> Crate(compiler_builtins@0.1.140)
32+
#-----| -> Crate(std@0.0.0)
33+
34+
#-----| Crate(getopts@0.2.21)
35+
#-----| -> Crate(core@0.0.0)
36+
#-----| -> Crate(std@0.0.0)
37+
#-----| -> Crate(unicode_width@0.1.14)
38+
39+
#-----| Crate(alloc@0.0.0)
40+
#-----| -> Crate(core@0.0.0)
41+
#-----| -> Crate(compiler_builtins@0.1.140)
42+
#-----| -> Crate(rand@0.8.5)
43+
#-----| -> Crate(rand_xorshift@0.3.0)
44+
45+
#-----| Crate(hashbrown@0.15.2)
46+
#-----| -> Crate(allocator_api2@0.2.21)
47+
#-----| -> Crate(core@0.0.0)
48+
#-----| -> Crate(compiler_builtins@0.1.140)
49+
#-----| -> Crate(alloc@0.0.0)
50+
51+
#-----| Crate(libc@0.2.169)
52+
#-----| -> Crate(core@0.0.0)
53+
54+
#-----| Crate(rand_core@0.6.4)
55+
56+
#-----| Crate(rand@0.8.5)
57+
#-----| -> Crate(rand_core@0.6.4)
58+
59+
#-----| Crate(rand_xorshift@0.3.0)
60+
#-----| -> Crate(rand_core@0.6.4)
61+
62+
#-----| Crate(rustc_demangle@0.1.24)
63+
#-----| -> Crate(core@0.0.0)
64+
#-----| -> Crate(compiler_builtins@0.1.140)
65+
66+
#-----| Crate(panic_abort@0.0.0)
67+
#-----| -> Crate(core@0.0.0)
68+
#-----| -> Crate(compiler_builtins@0.1.140)
69+
#-----| -> Crate(cfg_if@1.0.0)
70+
#-----| -> Crate(alloc@0.0.0)
71+
#-----| -> Crate(libc@0.2.169)
72+
73+
#-----| Crate(unwind@0.0.0)
74+
#-----| -> Crate(core@0.0.0)
75+
#-----| -> Crate(compiler_builtins@0.1.140)
76+
#-----| -> Crate(cfg_if@1.0.0)
77+
#-----| -> Crate(libc@0.2.169)
78+
79+
#-----| Crate(panic_unwind@0.0.0)
80+
#-----| -> Crate(core@0.0.0)
81+
#-----| -> Crate(compiler_builtins@0.1.140)
82+
#-----| -> Crate(cfg_if@1.0.0)
83+
#-----| -> Crate(alloc@0.0.0)
84+
#-----| -> Crate(libc@0.2.169)
85+
#-----| -> Crate(unwind@0.0.0)
86+
87+
#-----| Crate(proc_macro@0.0.0)
88+
#-----| -> Crate(core@0.0.0)
89+
#-----| -> Crate(std@0.0.0)
90+
91+
#-----| Crate(std_detect@0.1.5)
92+
#-----| -> Crate(core@0.0.0)
93+
#-----| -> Crate(compiler_builtins@0.1.140)
94+
#-----| -> Crate(cfg_if@1.0.0)
95+
#-----| -> Crate(alloc@0.0.0)
96+
#-----| -> Crate(libc@0.2.169)
97+
98+
#-----| Crate(test@0.0.0)
99+
#-----| -> Crate(core@0.0.0)
100+
#-----| -> Crate(std@0.0.0)
101+
#-----| -> Crate(getopts@0.2.21)
102+
#-----| -> Crate(libc@0.2.169)
103+
104+
#-----| Crate(test@0.0.1)
105+
#-----| -> Crate(core@0.0.0)
106+
#-----| -> Crate(std@0.0.0)
107+
#-----| -> Crate(alloc@0.0.0)
108+
#-----| -> Crate(proc_macro@0.0.0)
109+
#-----| -> Crate(test@0.0.0)
110+
111+
#-----| Crate(main@0.0.1)
112+
#-----| -> Crate(core@0.0.0)
113+
#-----| -> Crate(std@0.0.0)
114+
#-----| -> Crate(alloc@0.0.0)
115+
#-----| -> Crate(proc_macro@0.0.0)
116+
#-----| -> Crate(test@0.0.0)
117+
#-----| -> Crate(test@0.0.1)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @id crate-graph
3+
* @name Crate Graph
4+
* @kind graph
5+
*/
6+
7+
import rust
8+
9+
query predicate nodes(Crate c) { any() }
10+
11+
query predicate edges(Crate c1, Crate c2) { c1.getADependency() = c2 }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println! {"Hello world"}
3+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::fmt;
2+
3+
pub enum X {
4+
A,
5+
B,
6+
}
7+
8+
pub struct X_List {
9+
x: X,
10+
tail: Option<Box<X_List>>,
11+
}
12+
13+
pub fn length(list: X_List) -> usize {
14+
match list {
15+
X_List { x: _, tail: None } => 1,
16+
X_List {
17+
x: _,
18+
tail: Some(tail),
19+
} => 1 + length(*tail),
20+
}
21+
}
22+
pub trait AsString {
23+
fn as_string(&self) -> &str;
24+
}
25+
26+
impl AsString for X {
27+
fn as_string(&self) -> &str {
28+
match self {
29+
X::A => "a",
30+
X::B => "b",
31+
}
32+
}
33+
}
34+
35+
impl fmt::Display for X {
36+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37+
write!(f, "{}", self.as_string())
38+
}
39+
}
40+
41+
pub const X_A: X = X::A;
42+
pub static X_B: X = X::B;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#-----| fn as_string
2+
3+
#-----| fn length
4+
5+
#-----| fn write
6+
7+
#-----| fn as_string
8+
9+
#-----| fn fmt
10+
11+
#-----| struct X_List
12+
13+
#-----| Static
14+
15+
#-----| mod module
16+
#-----| -> fn length
17+
#-----| -> fn write
18+
#-----| -> struct X_List
19+
#-----| -> Static
20+
#-----| -> trait AsString
21+
#-----| -> Const
22+
#-----| -> impl AsString for ...::X { ... }
23+
#-----| -> impl ...::Display for ...::X { ... }
24+
#-----| -> enum X
25+
26+
#-----| mod crate
27+
#-----| -> mod module
28+
29+
#-----| trait AsString
30+
#-----| -> 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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @id module-graph
3+
* @name Module and Item Graph
4+
* @kind graph
5+
*/
6+
7+
import rust
8+
9+
query predicate nodes(Item i) {
10+
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
11+
}
12+
13+
query predicate edges(Item container, Item element) {
14+
element = container.(Module).getItemList().getAnItem() or
15+
element = container.(Impl).getAssocItemList().getAnAssocItem() or
16+
element = container.(Trait).getAssocItemList().getAnAssocItem()
17+
}

0 commit comments

Comments
 (0)