Merge pull request #18147 from github/redsun82/rust-windows-semantics

Rust: add diagnostics queries to integration tests
This commit is contained in:
Paolo Tranquilli
2024-11-29 11:45:48 +01:00
committed by GitHub
19 changed files with 64 additions and 24 deletions

View File

@@ -1,15 +1,21 @@
import pytest import pytest
import shutil import json
import commands
class _Manifests: import pathlib
def __init__(self, cwd):
self.dir = cwd / "manifests"
def select(self, name: str):
(self.dir / name).rename(name)
shutil.rmtree(self.dir)
@pytest.fixture @pytest.fixture
def manifests(cwd): def cargo(cwd):
return _Manifests(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)

View File

@@ -0,0 +1 @@
queries/diagnostics/ExtractionErrors.ql

View File

@@ -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 |

View File

@@ -0,0 +1 @@
queries/diagnostics/ExtractionWarnings.ql

View File

@@ -1,4 +1,5 @@
{ {
"sysroot_src": "filled by the rust_project fixture",
"crates": [{ "crates": [{
"root_module": "src/main.rs", "root_module": "src/main.rs",
"edition": "2021", "edition": "2021",

View 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 |

View File

@@ -0,0 +1 @@
queries/summary/SummaryStats.ql

View File

@@ -1,7 +1,5 @@
def test_cargo(codeql, rust, manifests, check_source_archive): def test_cargo(codeql, rust, cargo, check_source_archive):
manifests.select("Cargo.toml")
codeql.database.create() codeql.database.create()
def test_rust_project(codeql, rust, manifests, check_source_archive): def test_rust_project(codeql, rust, rust_project, check_source_archive):
manifests.select("rust-project.json")
codeql.database.create() codeql.database.create()

View File

@@ -0,0 +1 @@
queries/diagnostics/ExtractionErrors.ql

View File

@@ -0,0 +1 @@
queries/diagnostics/ExtractionWarnings.ql

View File

@@ -1,4 +1,5 @@
{ {
"sysroot_src": "filled by the rust_project fixture",
"crates": [ "crates": [
{ {
"root_module": "exe/src/main.rs", "root_module": "exe/src/main.rs",

View 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 |

View File

@@ -0,0 +1 @@
queries/summary/SummaryStats.ql

View File

@@ -1,12 +1,5 @@
import pytest def test_cargo(codeql, rust, cargo, check_source_archive):
# 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")
codeql.database.create() codeql.database.create()
def test_rust_project(codeql, rust, manifests, check_source_archive): def test_rust_project(codeql, rust, rust_project, check_source_archive):
manifests.select("rust-project.json")
codeql.database.create() codeql.database.create()