mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: add basic integration tests
This adds testing of well-formed rust projects and workspaces, using both `Cargo.toml` and `rust-project.json` manifests.
This commit is contained in:
15
rust/integration-tests/conftest.py
Normal file
15
rust/integration-tests/conftest.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
import shutil
|
||||
|
||||
class _Manifests:
|
||||
def __init__(self, cwd):
|
||||
self.dir = cwd / "manifests"
|
||||
|
||||
def select(self, name: str):
|
||||
(self.dir / name).rename(name)
|
||||
shutil.rmtree(self.dir)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def manifests(cwd):
|
||||
return _Manifests(cwd)
|
||||
1
rust/integration-tests/hello-project/functions.expected
Normal file
1
rust/integration-tests/hello-project/functions.expected
Normal file
@@ -0,0 +1 @@
|
||||
| src/main.rs:4:1:6:1 | main |
|
||||
5
rust/integration-tests/hello-project/functions.ql
Normal file
5
rust/integration-tests/hello-project/functions.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where exists(f.getLocation().getFile().getRelativePath())
|
||||
select f
|
||||
@@ -0,0 +1,7 @@
|
||||
[workspace]
|
||||
[package]
|
||||
name = "hello-cargo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"crates": [{
|
||||
"root_module": "src/main.rs",
|
||||
"edition": "2021",
|
||||
"deps": []
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
src/directory_module/mod.rs
|
||||
src/directory_module/nested_module.rs
|
||||
src/file_module.rs
|
||||
src/main.rs
|
||||
@@ -0,0 +1 @@
|
||||
mod nested_module;
|
||||
6
rust/integration-tests/hello-project/src/main.rs
Normal file
6
rust/integration-tests/hello-project/src/main.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
mod file_module;
|
||||
mod directory_module;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
7
rust/integration-tests/hello-project/test_project.py
Normal file
7
rust/integration-tests/hello-project/test_project.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def test_cargo(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("Cargo.toml")
|
||||
codeql.database.create()
|
||||
|
||||
def test_rust_project(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("rust-project.json")
|
||||
codeql.database.create()
|
||||
7
rust/integration-tests/hello-workspace/exe/Cargo.toml
Normal file
7
rust/integration-tests/hello-workspace/exe/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "exe"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
lib = { path = "../lib" }
|
||||
7
rust/integration-tests/hello-workspace/exe/src/main.rs
Normal file
7
rust/integration-tests/hello-workspace/exe/src/main.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use lib::a_module::hello;
|
||||
|
||||
mod a_module;
|
||||
|
||||
fn main() {
|
||||
hello();
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
| exe/src/main.rs:5:1:7:1 | main |
|
||||
| lib/src/a_module/mod.rs:1:1:3:1 | hello |
|
||||
5
rust/integration-tests/hello-workspace/functions.ql
Normal file
5
rust/integration-tests/hello-workspace/functions.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import rust
|
||||
|
||||
from Function f
|
||||
where exists(f.getLocation().getFile().getRelativePath())
|
||||
select f
|
||||
6
rust/integration-tests/hello-workspace/lib/Cargo.toml
Normal file
6
rust/integration-tests/hello-workspace/lib/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "lib"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,3 @@
|
||||
pub fn hello() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
1
rust/integration-tests/hello-workspace/lib/src/lib.rs
Normal file
1
rust/integration-tests/hello-workspace/lib/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod a_module;
|
||||
@@ -0,0 +1,3 @@
|
||||
[workspace]
|
||||
members = [ "exe", "lib" ]
|
||||
resolver = "2"
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"crates": [
|
||||
{
|
||||
"root_module": "exe/src/main.rs",
|
||||
"edition": "2021",
|
||||
"deps": [{"crate": 1, "name": "lib"}]
|
||||
},
|
||||
{
|
||||
"root_module": "lib/src/lib.rs",
|
||||
"edition": "2021",
|
||||
"deps": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
exe/src/a_module.rs
|
||||
exe/src/main.rs
|
||||
lib/src/a_module/mod.rs
|
||||
lib/src/lib.rs
|
||||
7
rust/integration-tests/hello-workspace/test_workspace.py
Normal file
7
rust/integration-tests/hello-workspace/test_workspace.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def test_cargo(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("Cargo.toml")
|
||||
codeql.database.create()
|
||||
|
||||
def test_rust_project(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("rust-project.json")
|
||||
codeql.database.create()
|
||||
4
rust/integration-tests/qlpack.lock.yml
Normal file
4
rust/integration-tests/qlpack.lock.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
dependencies: {}
|
||||
compiled: false
|
||||
lockVersion: 1.0.0
|
||||
8
rust/integration-tests/qlpack.yml
Normal file
8
rust/integration-tests/qlpack.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
name: codeql/rust-integration-tests
|
||||
groups: [rust, test]
|
||||
dependencies:
|
||||
codeql/rust-queries: ${workspace}
|
||||
codeql/rust-all: ${workspace}
|
||||
extractor: rust
|
||||
tests: .
|
||||
warnOnImplicitThis: true
|
||||
@@ -1,4 +0,0 @@
|
||||
# dummy test to get CI going
|
||||
|
||||
def test(codeql, rust):
|
||||
pass
|
||||
Reference in New Issue
Block a user