Skip to content

Commit 9f6a2e0

Browse files
author
Paolo Tranquilli
committed
Rust: add diagnostics queries to integration tests
1 parent c1937ea commit 9f6a2e0

19 files changed

+62
-22
lines changed

rust/ql/integration-tests/conftest.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import pytest
2-
import shutil
2+
import json
3+
import commands
4+
import pathlib
35

4-
class _Manifests:
5-
def __init__(self, cwd):
6-
self.dir = cwd / "manifests"
76

8-
def select(self, name: str):
9-
(self.dir / name).rename(name)
10-
shutil.rmtree(self.dir)
7+
@pytest.fixture
8+
def cargo(cwd):
9+
assert (cwd / "Cargo.toml").exists()
10+
(cwd / "rust-project.json").unlink(missing_ok=True)
1111

1212

1313
@pytest.fixture
14-
def manifests(cwd):
15-
return _Manifests(cwd)
14+
def rust_project(cwd):
15+
project_file = cwd / "rust-project.json"
16+
assert project_file.exists()
17+
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
18+
project = json.loads(project_file.read_text())
19+
project["sysroot_src"] = str(rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library"))
20+
project_file.write_text(json.dumps(project, indent=4))
21+
(cwd / "Cargo.toml").unlink(missing_ok=True)

rust/ql/integration-tests/hello-project/ExtractionErrors.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/diagnostics/ExtractionErrors.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/diagnostics/ExtractionWarnings.ql

rust/ql/integration-tests/hello-project/manifests/rust-project.json renamed to rust/ql/integration-tests/hello-project/rust-project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"sysroot_src": "filled by the rust_project fixture",
23
"crates": [{
34
"root_module": "src/main.rs",
45
"edition": "2021",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
| Elements extracted | 50 |
2+
| Elements unextracted | 0 |
3+
| Extraction errors | 0 |
4+
| Extraction warnings | 1 |
5+
| Files extracted - total | 5 |
6+
| Files extracted - with errors | 1 |
7+
| Files extracted - without errors | 4 |
8+
| Inconsistencies - AST | 0 |
9+
| Inconsistencies - CFG | 0 |
10+
| Inconsistencies - data flow | 0 |
11+
| Lines of code extracted | 6 |
12+
| Lines of user code extracted | 6 |
13+
| Macro calls - resolved | 2 |
14+
| Macro calls - total | 2 |
15+
| Macro calls - unresolved | 0 |
16+
| Taint sources - active | 0 |
17+
| Taint sources - total | 0 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/summary/SummaryStats.ql
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
def test_cargo(codeql, rust, manifests, check_source_archive):
2-
manifests.select("Cargo.toml")
1+
def test_cargo(codeql, rust, cargo, check_source_archive):
32
codeql.database.create()
43

5-
def test_rust_project(codeql, rust, manifests, check_source_archive):
6-
manifests.select("rust-project.json")
4+
def test_rust_project(codeql, rust, rust_project, check_source_archive):
75
codeql.database.create()

0 commit comments

Comments
 (0)