diff --git a/rust/ql/src/queries/diagnostics/ExtractedFiles.ql b/rust/ql/src/queries/diagnostics/ExtractedFiles.ql new file mode 100644 index 000000000000..ce5aa699e671 --- /dev/null +++ b/rust/ql/src/queries/diagnostics/ExtractedFiles.ql @@ -0,0 +1,13 @@ +/** + * @name Extracted files + * @description Lists all files in the source code directory that were extracted. + * @kind diagnostic + * @id rust/diagnostics/successfully-extracted-files + * @tags successfully-extracted-files + */ + +import rust + +from File f +where exists(f.getRelativePath()) +select f, "File successfully extracted." diff --git a/rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected b/rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected new file mode 100644 index 000000000000..cc6f775e86d5 --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected @@ -0,0 +1,6 @@ +| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | File successfully extracted. | +| error.rs:0:0:0:0 | error.rs | File successfully extracted. | +| lib.rs:0:0:0:0 | lib.rs | File successfully extracted. | +| main.rs:0:0:0:0 | main.rs | File successfully extracted. | +| my_macro.rs:0:0:0:0 | my_macro.rs | File successfully extracted. | +| my_struct.rs:0:0:0:0 | my_struct.rs | File successfully extracted. | diff --git a/rust/ql/test/query-tests/diagnostics/ExtractedFiles.qlref b/rust/ql/test/query-tests/diagnostics/ExtractedFiles.qlref new file mode 100644 index 000000000000..cd1996e606b6 --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/ExtractedFiles.qlref @@ -0,0 +1 @@ +queries/diagnostics/ExtractedFiles.ql diff --git a/rust/ql/test/query-tests/diagnostics/does_not_compile.rs b/rust/ql/test/query-tests/diagnostics/does_not_compile.rs new file mode 100644 index 000000000000..9aedaffcd93a --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/does_not_compile.rs @@ -0,0 +1,3 @@ +pub fn my_func() { + This is not correct Rust code. +} diff --git a/rust/ql/test/query-tests/diagnostics/error.rs b/rust/ql/test/query-tests/diagnostics/error.rs new file mode 100644 index 000000000000..45239a247c2a --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/error.rs @@ -0,0 +1,3 @@ +pub fn my_func() { + compile_error!("An error!"); +} diff --git a/rust/ql/test/query-tests/diagnostics/main.rs b/rust/ql/test/query-tests/diagnostics/main.rs new file mode 100644 index 000000000000..15fb6f67cddf --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/main.rs @@ -0,0 +1,18 @@ +/** + * total lines in this file: 18 + * of which code: 7 + * of which only comments: 7 + * of which blank: 4 + */ + +mod my_struct; +mod my_macro; + +// another comment + +fn main() { + println!("Hello, world!"); // another comment + + my_struct::my_func(); + my_macro::my_func(); +} diff --git a/rust/ql/test/query-tests/diagnostics/my_macro.rs b/rust/ql/test/query-tests/diagnostics/my_macro.rs new file mode 100644 index 000000000000..d8a0cc2812bd --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/my_macro.rs @@ -0,0 +1,18 @@ +/** + * total lines in this file: 18 + * of which code: 10 + * of which only comments: 6 + * of which blank: 2 + */ + +macro_rules! myMacro { + () => { + println!("Hello, world!"); + }; +} + +pub fn my_func() { + if true { + myMacro!(); + } +} diff --git a/rust/ql/test/query-tests/diagnostics/my_struct.rs b/rust/ql/test/query-tests/diagnostics/my_struct.rs new file mode 100644 index 000000000000..176b0936b162 --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/my_struct.rs @@ -0,0 +1,30 @@ +#![allow(dead_code)] +/** + * total lines in this file: 30 + * of which code: 20 + * of which only comments: 6 + * of which blank: 4 + */ + +#[derive(Debug)] +struct MyStruct { + name: String, + value: i32, +} + +impl MyStruct { + fn my_method(&self) { + println!("Hello, world!"); + } +} + +pub fn my_func() { + let _a = 1; + let b = + MyStruct { + name: String::from("abc"), + value: 123, + }; + + b.my_method(); +}