зеркало из https://github.com/github/codeql.git
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:
Родитель
afb9ffa50e
Коммит
aae33db137
|
@ -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)
|
|
@ -0,0 +1 @@
|
|||
| src/main.rs:4:1:6:1 | main |
|
|
@ -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;
|
|
@ -0,0 +1,6 @@
|
|||
mod file_module;
|
||||
mod directory_module;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
|
@ -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()
|
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "exe"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
lib = { path = "../lib" }
|
|
@ -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 |
|
|
@ -0,0 +1,5 @@
|
|||
import rust
|
||||
|
||||
from Function f
|
||||
where exists(f.getLocation().getFile().getRelativePath())
|
||||
select f
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "lib"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
|
@ -0,0 +1,3 @@
|
|||
pub fn hello() {
|
||||
println!("Hello, world!");
|
||||
}
|
|
@ -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
|
|
@ -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()
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
dependencies: {}
|
||||
compiled: false
|
||||
lockVersion: 1.0.0
|
|
@ -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
|
Загрузка…
Ссылка в новой задаче