mirror of
https://github.com/github/codeql.git
synced 2026-04-22 07:15:15 +02:00
Rust: add some tests for the crate graph
This commit is contained in:
117
rust/ql/test/extractor-tests/crate_graph/crates.expected
Normal file
117
rust/ql/test/extractor-tests/crate_graph/crates.expected
Normal file
@@ -0,0 +1,117 @@
|
||||
#-----| Crate(allocator_api2@0.2.21)
|
||||
|
||||
#-----| Crate(core@0.0.0)
|
||||
#-----| -> Crate(rand@0.8.5)
|
||||
#-----| -> Crate(rand_xorshift@0.3.0)
|
||||
|
||||
#-----| Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
|
||||
#-----| Crate(cfg_if@1.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
|
||||
#-----| Crate(std@0.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(cfg_if@1.0.0)
|
||||
#-----| -> Crate(alloc@0.0.0)
|
||||
#-----| -> Crate(hashbrown@0.15.2)
|
||||
#-----| -> Crate(libc@0.2.169)
|
||||
#-----| -> Crate(rand@0.8.5)
|
||||
#-----| -> Crate(rand_xorshift@0.3.0)
|
||||
#-----| -> Crate(rustc_demangle@0.1.24)
|
||||
#-----| -> Crate(panic_abort@0.0.0)
|
||||
#-----| -> Crate(unwind@0.0.0)
|
||||
#-----| -> Crate(panic_unwind@0.0.0)
|
||||
#-----| -> Crate(std_detect@0.1.5)
|
||||
|
||||
#-----| Crate(unicode_width@0.1.14)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(std@0.0.0)
|
||||
|
||||
#-----| Crate(getopts@0.2.21)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(std@0.0.0)
|
||||
#-----| -> Crate(unicode_width@0.1.14)
|
||||
|
||||
#-----| Crate(alloc@0.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(rand@0.8.5)
|
||||
#-----| -> Crate(rand_xorshift@0.3.0)
|
||||
|
||||
#-----| Crate(hashbrown@0.15.2)
|
||||
#-----| -> Crate(allocator_api2@0.2.21)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(alloc@0.0.0)
|
||||
|
||||
#-----| Crate(libc@0.2.169)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
|
||||
#-----| Crate(rand_core@0.6.4)
|
||||
|
||||
#-----| Crate(rand@0.8.5)
|
||||
#-----| -> Crate(rand_core@0.6.4)
|
||||
|
||||
#-----| Crate(rand_xorshift@0.3.0)
|
||||
#-----| -> Crate(rand_core@0.6.4)
|
||||
|
||||
#-----| Crate(rustc_demangle@0.1.24)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
|
||||
#-----| Crate(panic_abort@0.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(cfg_if@1.0.0)
|
||||
#-----| -> Crate(alloc@0.0.0)
|
||||
#-----| -> Crate(libc@0.2.169)
|
||||
|
||||
#-----| Crate(unwind@0.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(cfg_if@1.0.0)
|
||||
#-----| -> Crate(libc@0.2.169)
|
||||
|
||||
#-----| Crate(panic_unwind@0.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(cfg_if@1.0.0)
|
||||
#-----| -> Crate(alloc@0.0.0)
|
||||
#-----| -> Crate(libc@0.2.169)
|
||||
#-----| -> Crate(unwind@0.0.0)
|
||||
|
||||
#-----| Crate(proc_macro@0.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(std@0.0.0)
|
||||
|
||||
#-----| Crate(std_detect@0.1.5)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(compiler_builtins@0.1.140)
|
||||
#-----| -> Crate(cfg_if@1.0.0)
|
||||
#-----| -> Crate(alloc@0.0.0)
|
||||
#-----| -> Crate(libc@0.2.169)
|
||||
|
||||
#-----| Crate(test@0.0.0)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(std@0.0.0)
|
||||
#-----| -> Crate(getopts@0.2.21)
|
||||
#-----| -> Crate(libc@0.2.169)
|
||||
|
||||
#-----| Crate(test@0.0.1)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(std@0.0.0)
|
||||
#-----| -> Crate(alloc@0.0.0)
|
||||
#-----| -> Crate(proc_macro@0.0.0)
|
||||
#-----| -> Crate(test@0.0.0)
|
||||
|
||||
#-----| Crate(main@0.0.1)
|
||||
#-----| -> Crate(core@0.0.0)
|
||||
#-----| -> Crate(std@0.0.0)
|
||||
#-----| -> Crate(alloc@0.0.0)
|
||||
#-----| -> Crate(proc_macro@0.0.0)
|
||||
#-----| -> Crate(test@0.0.0)
|
||||
#-----| -> Crate(test@0.0.1)
|
||||
11
rust/ql/test/extractor-tests/crate_graph/crates.ql
Normal file
11
rust/ql/test/extractor-tests/crate_graph/crates.ql
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @id crate-graph
|
||||
* @name Crate Graph
|
||||
* @kind graph
|
||||
*/
|
||||
|
||||
import rust
|
||||
|
||||
query predicate nodes(Crate c) { any() }
|
||||
|
||||
query predicate edges(Crate c1, Crate c2) { c1.getADependency() = c2 }
|
||||
3
rust/ql/test/extractor-tests/crate_graph/main.rs
Normal file
3
rust/ql/test/extractor-tests/crate_graph/main.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println! {"Hello world"}
|
||||
}
|
||||
42
rust/ql/test/extractor-tests/crate_graph/module.rs
Normal file
42
rust/ql/test/extractor-tests/crate_graph/module.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::fmt;
|
||||
|
||||
pub enum X {
|
||||
A,
|
||||
B,
|
||||
}
|
||||
|
||||
pub struct X_List {
|
||||
x: X,
|
||||
tail: Option<Box<X_List>>,
|
||||
}
|
||||
|
||||
pub fn length(list: X_List) -> usize {
|
||||
match list {
|
||||
X_List { x: _, tail: None } => 1,
|
||||
X_List {
|
||||
x: _,
|
||||
tail: Some(tail),
|
||||
} => 1 + length(*tail),
|
||||
}
|
||||
}
|
||||
pub trait AsString {
|
||||
fn as_string(&self) -> &str;
|
||||
}
|
||||
|
||||
impl AsString for X {
|
||||
fn as_string(&self) -> &str {
|
||||
match self {
|
||||
X::A => "a",
|
||||
X::B => "b",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for X {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.as_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub const X_A: X = X::A;
|
||||
pub static X_B: X = X::B;
|
||||
40
rust/ql/test/extractor-tests/crate_graph/modules.expected
Normal file
40
rust/ql/test/extractor-tests/crate_graph/modules.expected
Normal file
@@ -0,0 +1,40 @@
|
||||
#-----| fn as_string
|
||||
|
||||
#-----| fn length
|
||||
|
||||
#-----| fn write
|
||||
|
||||
#-----| fn as_string
|
||||
|
||||
#-----| fn fmt
|
||||
|
||||
#-----| struct X_List
|
||||
|
||||
#-----| Static
|
||||
|
||||
#-----| mod module
|
||||
#-----| -> fn length
|
||||
#-----| -> fn write
|
||||
#-----| -> struct X_List
|
||||
#-----| -> Static
|
||||
#-----| -> trait AsString
|
||||
#-----| -> Const
|
||||
#-----| -> impl AsString for ...::X { ... }
|
||||
#-----| -> impl ...::Display for ...::X { ... }
|
||||
#-----| -> enum X
|
||||
|
||||
#-----| mod crate
|
||||
#-----| -> mod module
|
||||
|
||||
#-----| trait AsString
|
||||
#-----| -> fn as_string
|
||||
|
||||
#-----| Const
|
||||
|
||||
#-----| impl AsString for ...::X { ... }
|
||||
#-----| -> fn as_string
|
||||
|
||||
#-----| impl ...::Display for ...::X { ... }
|
||||
#-----| -> fn fmt
|
||||
|
||||
#-----| enum X
|
||||
17
rust/ql/test/extractor-tests/crate_graph/modules.ql
Normal file
17
rust/ql/test/extractor-tests/crate_graph/modules.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @id module-graph
|
||||
* @name Module and Item Graph
|
||||
* @kind graph
|
||||
*/
|
||||
|
||||
import rust
|
||||
|
||||
query predicate nodes(Item i) {
|
||||
i.getParentNode*() = any(Crate m | m.getName() = "test" and m.getVersion() = "0.0.1").getModule()
|
||||
}
|
||||
|
||||
query predicate edges(Item container, Item element) {
|
||||
element = container.(Module).getItemList().getAnItem() or
|
||||
element = container.(Impl).getAssocItemList().getAnAssocItem() or
|
||||
element = container.(Trait).getAssocItemList().getAnAssocItem()
|
||||
}
|
||||
Reference in New Issue
Block a user