From 4d77236002e09eaf54e6a1236b543d1f971a7786 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sat, 4 Jul 2026 18:24:24 +0100 Subject: [PATCH 1/2] test: Add Rust static analysis (cargo clippy) Signed-off-by: Arthit Suriyawongkul --- .github/workflows/coverage-generate.yaml | 3 ++ .github/workflows/test.yaml | 3 ++ tests/test_rust.py | 54 ++++++++++++++++++------ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/.github/workflows/coverage-generate.yaml b/.github/workflows/coverage-generate.yaml index 68570c1e..76d8bc98 100644 --- a/.github/workflows/coverage-generate.yaml +++ b/.github/workflows/coverage-generate.yaml @@ -37,6 +37,9 @@ jobs: sudo apt install -y build-essential doxygen graphviz npm install -g jsonld-cli npm --prefix scripts ci + - name: Install Rust static analysis tools + run: | + rustup component add clippy - name: Install package run: | pip install -e .[dev] diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c52f6a89..23ebbff6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -50,6 +50,9 @@ jobs: run: | brew update brew install doxygen gcc go graphviz + - name: Install Rust static analysis tools + run: | + rustup component add clippy - name: Build package run: | python -m build diff --git a/tests/test_rust.py b/tests/test_rust.py index 2d76d51c..f71cd16b 100644 --- a/tests/test_rust.py +++ b/tests/test_rust.py @@ -407,33 +407,59 @@ def f(path, name, tag, **kwargs): yield f -@pytest.mark.parametrize( +RUST_MODEL_TESTS = ( "args", [ ["--input", TEST_MODEL], ["--input", TEST_MODEL, "--context-url", TEST_CONTEXT, SPDX3_CONTEXT_URL], ], ) + + +def _build_rust_module(tmp_path, model_server, args): + subprocess.run( + [ + "shacl2code", + "generate", + "--context", + model_server + "/test-context.json", + ] + + args + + [ + "rust", + "--output", + tmp_path / "shacl_model", + ], + check=True, + ) + + +@pytest.mark.parametrize(*RUST_MODEL_TESTS) class TestOutput: def test_output_compile(self, tmp_path, model_server, args): + _build_rust_module(tmp_path, model_server, args) + subprocess.run( - [ - "shacl2code", - "generate", - "--context", - model_server + "/test-context.json", - ] - + args - + [ - "rust", - "--output", - tmp_path / "shacl_model", - ], + ["cargo", "build"], + cwd=tmp_path / "shacl_model", check=True, ) + +@pytest.mark.parametrize(*RUST_MODEL_TESTS) +class TestCheckType: + """ + Static analysis checks for the generated Rust code + """ + + def test_clippy(self, tmp_path, model_server, args): + """ + cargo clippy static analysis + """ + _build_rust_module(tmp_path, model_server, args) + subprocess.run( - ["cargo", "build"], + ["cargo", "clippy", "--all-targets", "--", "-D", "warnings"], cwd=tmp_path / "shacl_model", check=True, ) From e4a6ecbe5223e93e2cd43bf8d9d61121868baba4 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Sat, 4 Jul 2026 20:31:09 +0100 Subject: [PATCH 2/2] Rename TestCheckType -> TestStaticAnalysis: Signed-off-by: Arthit Suriyawongkul --- tests/test_rust.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_rust.py b/tests/test_rust.py index f71cd16b..afa0c424 100644 --- a/tests/test_rust.py +++ b/tests/test_rust.py @@ -447,7 +447,7 @@ def test_output_compile(self, tmp_path, model_server, args): @pytest.mark.parametrize(*RUST_MODEL_TESTS) -class TestCheckType: +class TestStaticAnalysis: """ Static analysis checks for the generated Rust code """