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..afa0c424 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 TestStaticAnalysis: + """ + 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, )