diff --git a/rust/ql/integration-tests/conftest.py b/rust/ql/integration-tests/conftest.py index 08b17f106f8..fbe443a4927 100644 --- a/rust/ql/integration-tests/conftest.py +++ b/rust/ql/integration-tests/conftest.py @@ -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) diff --git a/rust/ql/integration-tests/hello-project/manifests/Cargo.toml b/rust/ql/integration-tests/hello-project/Cargo.toml similarity index 100% rename from rust/ql/integration-tests/hello-project/manifests/Cargo.toml rename to rust/ql/integration-tests/hello-project/Cargo.toml diff --git a/rust/ql/integration-tests/hello-project/ExtractionErrors.expected b/rust/ql/integration-tests/hello-project/ExtractionErrors.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/rust/ql/integration-tests/hello-project/ExtractionErrors.qlref b/rust/ql/integration-tests/hello-project/ExtractionErrors.qlref new file mode 100644 index 00000000000..ba4f854d6a1 --- /dev/null +++ b/rust/ql/integration-tests/hello-project/ExtractionErrors.qlref @@ -0,0 +1 @@ +queries/diagnostics/ExtractionErrors.ql diff --git a/rust/ql/integration-tests/hello-project/ExtractionWarnings.expected b/rust/ql/integration-tests/hello-project/ExtractionWarnings.expected new file mode 100644 index 00000000000..ef3e107fa76 --- /dev/null +++ b/rust/ql/integration-tests/hello-project/ExtractionWarnings.expected @@ -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 | diff --git a/rust/ql/integration-tests/hello-project/ExtractionWarnings.qlref b/rust/ql/integration-tests/hello-project/ExtractionWarnings.qlref new file mode 100644 index 00000000000..ff6e566d20a --- /dev/null +++ b/rust/ql/integration-tests/hello-project/ExtractionWarnings.qlref @@ -0,0 +1 @@ +queries/diagnostics/ExtractionWarnings.ql diff --git a/rust/ql/integration-tests/hello-project/manifests/rust-project.json b/rust/ql/integration-tests/hello-project/rust-project.json similarity index 63% rename from rust/ql/integration-tests/hello-project/manifests/rust-project.json rename to rust/ql/integration-tests/hello-project/rust-project.json index 03d9a5ce2c0..b111bca9c73 100644 --- a/rust/ql/integration-tests/hello-project/manifests/rust-project.json +++ b/rust/ql/integration-tests/hello-project/rust-project.json @@ -1,4 +1,5 @@ { + "sysroot_src": "filled by the rust_project fixture", "crates": [{ "root_module": "src/main.rs", "edition": "2021", diff --git a/rust/ql/integration-tests/hello-project/summary.expected b/rust/ql/integration-tests/hello-project/summary.expected new file mode 100644 index 00000000000..09e03490eb1 --- /dev/null +++ b/rust/ql/integration-tests/hello-project/summary.expected @@ -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 | diff --git a/rust/ql/integration-tests/hello-project/summary.qlref b/rust/ql/integration-tests/hello-project/summary.qlref new file mode 100644 index 00000000000..b94ba40446a --- /dev/null +++ b/rust/ql/integration-tests/hello-project/summary.qlref @@ -0,0 +1 @@ +queries/summary/SummaryStats.ql diff --git a/rust/ql/integration-tests/hello-project/test_project.py b/rust/ql/integration-tests/hello-project/test_project.py index d03c4f67e26..6a7e21ebedb 100644 --- a/rust/ql/integration-tests/hello-project/test_project.py +++ b/rust/ql/integration-tests/hello-project/test_project.py @@ -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() diff --git a/rust/ql/integration-tests/hello-workspace/manifests/Cargo.toml b/rust/ql/integration-tests/hello-workspace/Cargo.toml similarity index 100% rename from rust/ql/integration-tests/hello-workspace/manifests/Cargo.toml rename to rust/ql/integration-tests/hello-workspace/Cargo.toml diff --git a/rust/ql/integration-tests/hello-workspace/ExtractionErrors.expected b/rust/ql/integration-tests/hello-workspace/ExtractionErrors.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/rust/ql/integration-tests/hello-workspace/ExtractionErrors.qlref b/rust/ql/integration-tests/hello-workspace/ExtractionErrors.qlref new file mode 100644 index 00000000000..ba4f854d6a1 --- /dev/null +++ b/rust/ql/integration-tests/hello-workspace/ExtractionErrors.qlref @@ -0,0 +1 @@ +queries/diagnostics/ExtractionErrors.ql diff --git a/rust/ql/integration-tests/hello-workspace/ExtractionWarnings.expected b/rust/ql/integration-tests/hello-workspace/ExtractionWarnings.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/rust/ql/integration-tests/hello-workspace/ExtractionWarnings.qlref b/rust/ql/integration-tests/hello-workspace/ExtractionWarnings.qlref new file mode 100644 index 00000000000..ff6e566d20a --- /dev/null +++ b/rust/ql/integration-tests/hello-workspace/ExtractionWarnings.qlref @@ -0,0 +1 @@ +queries/diagnostics/ExtractionWarnings.ql diff --git a/rust/ql/integration-tests/hello-workspace/manifests/rust-project.json b/rust/ql/integration-tests/hello-workspace/rust-project.json similarity index 81% rename from rust/ql/integration-tests/hello-workspace/manifests/rust-project.json rename to rust/ql/integration-tests/hello-workspace/rust-project.json index 38e16980196..c8461b098bd 100644 --- a/rust/ql/integration-tests/hello-workspace/manifests/rust-project.json +++ b/rust/ql/integration-tests/hello-workspace/rust-project.json @@ -1,4 +1,5 @@ { + "sysroot_src": "filled by the rust_project fixture", "crates": [ { "root_module": "exe/src/main.rs", diff --git a/rust/ql/integration-tests/hello-workspace/summary.expected b/rust/ql/integration-tests/hello-workspace/summary.expected new file mode 100644 index 00000000000..4e800e60bd0 --- /dev/null +++ b/rust/ql/integration-tests/hello-workspace/summary.expected @@ -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 | diff --git a/rust/ql/integration-tests/hello-workspace/summary.qlref b/rust/ql/integration-tests/hello-workspace/summary.qlref new file mode 100644 index 00000000000..b94ba40446a --- /dev/null +++ b/rust/ql/integration-tests/hello-workspace/summary.qlref @@ -0,0 +1 @@ +queries/summary/SummaryStats.ql diff --git a/rust/ql/integration-tests/hello-workspace/test_workspace.py b/rust/ql/integration-tests/hello-workspace/test_workspace.py index f3503e7cefa..6a7e21ebedb 100644 --- a/rust/ql/integration-tests/hello-workspace/test_workspace.py +++ b/rust/ql/integration-tests/hello-workspace/test_workspace.py @@ -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()