mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge pull request #18147 from github/redsun82/rust-windows-semantics
Rust: add diagnostics queries to integration tests
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
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)
|
||||
import json
|
||||
import commands
|
||||
import pathlib
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def manifests(cwd):
|
||||
return _Manifests(cwd)
|
||||
def cargo(cwd):
|
||||
assert (cwd / "Cargo.toml").exists()
|
||||
(cwd / "rust-project.json").unlink(missing_ok=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def rust_project(cwd):
|
||||
project_file = cwd / "rust-project.json"
|
||||
assert project_file.exists()
|
||||
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
|
||||
project = json.loads(project_file.read_text())
|
||||
project["sysroot_src"] = str(rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library"))
|
||||
project_file.write_text(json.dumps(project, indent=4))
|
||||
(cwd / "Cargo.toml").unlink(missing_ok=True)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
queries/diagnostics/ExtractionErrors.ql
|
||||
@@ -0,0 +1 @@
|
||||
| src/directory_module/not_loaded.rs:1:1:1:1 | semantic analyzer unavailable (not included as a module) | Extraction warning in src/directory_module/not_loaded.rs with message semantic analyzer unavailable (not included as a module) | 1 |
|
||||
@@ -0,0 +1 @@
|
||||
queries/diagnostics/ExtractionWarnings.ql
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"sysroot_src": "filled by the rust_project fixture",
|
||||
"crates": [{
|
||||
"root_module": "src/main.rs",
|
||||
"edition": "2021",
|
||||
17
rust/ql/integration-tests/hello-project/summary.expected
Normal file
17
rust/ql/integration-tests/hello-project/summary.expected
Normal file
@@ -0,0 +1,17 @@
|
||||
| Elements extracted | 50 |
|
||||
| Elements unextracted | 0 |
|
||||
| Extraction errors | 0 |
|
||||
| Extraction warnings | 1 |
|
||||
| Files extracted - total | 5 |
|
||||
| Files extracted - with errors | 1 |
|
||||
| Files extracted - without errors | 4 |
|
||||
| Inconsistencies - AST | 0 |
|
||||
| Inconsistencies - CFG | 0 |
|
||||
| Inconsistencies - data flow | 0 |
|
||||
| Lines of code extracted | 6 |
|
||||
| Lines of user code extracted | 6 |
|
||||
| Macro calls - resolved | 2 |
|
||||
| Macro calls - total | 2 |
|
||||
| Macro calls - unresolved | 0 |
|
||||
| Taint sources - active | 0 |
|
||||
| Taint sources - total | 0 |
|
||||
1
rust/ql/integration-tests/hello-project/summary.qlref
Normal file
1
rust/ql/integration-tests/hello-project/summary.qlref
Normal file
@@ -0,0 +1 @@
|
||||
queries/summary/SummaryStats.ql
|
||||
@@ -1,7 +1,5 @@
|
||||
def test_cargo(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("Cargo.toml")
|
||||
def test_cargo(codeql, rust, cargo, check_source_archive):
|
||||
codeql.database.create()
|
||||
|
||||
def test_rust_project(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("rust-project.json")
|
||||
def test_rust_project(codeql, rust, rust_project, check_source_archive):
|
||||
codeql.database.create()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
queries/diagnostics/ExtractionErrors.ql
|
||||
@@ -0,0 +1 @@
|
||||
queries/diagnostics/ExtractionWarnings.ql
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"sysroot_src": "filled by the rust_project fixture",
|
||||
"crates": [
|
||||
{
|
||||
"root_module": "exe/src/main.rs",
|
||||
17
rust/ql/integration-tests/hello-workspace/summary.expected
Normal file
17
rust/ql/integration-tests/hello-workspace/summary.expected
Normal file
@@ -0,0 +1,17 @@
|
||||
| Elements extracted | 72 |
|
||||
| Elements unextracted | 0 |
|
||||
| Extraction errors | 0 |
|
||||
| Extraction warnings | 0 |
|
||||
| Files extracted - total | 4 |
|
||||
| Files extracted - with errors | 0 |
|
||||
| Files extracted - without errors | 4 |
|
||||
| Inconsistencies - AST | 0 |
|
||||
| Inconsistencies - CFG | 0 |
|
||||
| Inconsistencies - data flow | 0 |
|
||||
| Lines of code extracted | 9 |
|
||||
| Lines of user code extracted | 9 |
|
||||
| Macro calls - resolved | 2 |
|
||||
| Macro calls - total | 2 |
|
||||
| Macro calls - unresolved | 0 |
|
||||
| Taint sources - active | 0 |
|
||||
| Taint sources - total | 0 |
|
||||
1
rust/ql/integration-tests/hello-workspace/summary.qlref
Normal file
1
rust/ql/integration-tests/hello-workspace/summary.qlref
Normal file
@@ -0,0 +1 @@
|
||||
queries/summary/SummaryStats.ql
|
||||
@@ -1,12 +1,5 @@
|
||||
import pytest
|
||||
|
||||
# currently the DB-check fails on actions because of loading files multiple times and assiging multiple locations
|
||||
# see https://github.com/github/codeql-team/issues/3365
|
||||
@pytest.mark.ql_test("DB-CHECK", xfail="maybe")
|
||||
def test_cargo(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("Cargo.toml")
|
||||
def test_cargo(codeql, rust, cargo, check_source_archive):
|
||||
codeql.database.create()
|
||||
|
||||
def test_rust_project(codeql, rust, manifests, check_source_archive):
|
||||
manifests.select("rust-project.json")
|
||||
def test_rust_project(codeql, rust, rust_project, check_source_archive):
|
||||
codeql.database.create()
|
||||
|
||||
Reference in New Issue
Block a user