diff --git a/CI/tests/cargo_test.yml b/CI/tests/cargo_test.yml new file mode 100644 index 0000000..db3f682 --- /dev/null +++ b/CI/tests/cargo_test.yml @@ -0,0 +1,31 @@ +cargo_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Cache Cargo registry and target + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Run cargo test + run: | + set -euo pipefail + + if [[ ! -f "Cargo.toml" ]]; then + echo "::error::No Cargo.toml found" + exit 1 + fi + + echo "ℹ️ Running cargo test..." + cargo test --all-features --verbose \ + && echo "✅ cargo tests passed" \ + || { echo "❌ cargo tests failed"; exit 1; } diff --git a/README.md b/README.md index f8a4941..5742528 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ that projects compose into their own workflows. | SpotBugs | static_analysis | [CI/static_analysis/spotbugs.yml](https://github.com/prog-time/workflows/blob/main/CI/static_analysis/spotbugs.yml) | | mermaid-cli | build | [CI/build/mermaid.yml](https://github.com/prog-time/workflows/blob/main/CI/build/mermaid.yml) | | BATS | tests | [CI/tests/bats.yml](https://github.com/prog-time/workflows/blob/main/CI/tests/bats.yml) | +| cargo test | tests | [CI/tests/cargo_test.yml](https://github.com/prog-time/workflows/blob/main/CI/tests/cargo_test.yml) | | go test | tests | [CI/tests/go_test.yml](https://github.com/prog-time/workflows/blob/main/CI/tests/go_test.yml) | | Jest | tests | [CI/tests/jest.yml](https://github.com/prog-time/workflows/blob/main/CI/tests/jest.yml) | | Laravel | tests | [CI/tests/laravel_tests.yml](https://github.com/prog-time/workflows/blob/main/CI/tests/laravel_tests.yml) | @@ -104,6 +105,7 @@ Workflows/ │ │ │ └── spotbugs.yml │ │ └── tests/ │ │ ├── bats.yml +│ │ ├── cargo_test.yml │ │ ├── go_test.yml │ │ ├── jest.yml │ │ ├── laravel_tests.yml @@ -135,6 +137,7 @@ Workflows/ │ │ ├── semgrep.sh │ │ └── trivy.sh │ └── tests/ +│ ├── cargo_test.sh │ └── jest.sh │ ├── CI/ # assembled output (ready to use) @@ -163,6 +166,7 @@ Workflows/ │ │ ├── semgrep.bats │ │ └── trivy.bats │ ├── tests/ +│ │ ├── cargo_test.bats │ │ └── jest.bats │ └── helpers/ │ └── common.bash # shared test utilities (mocks, temp dirs) @@ -277,6 +281,7 @@ shellcheck: | Snippet | What it runs | |---------|--------------| | `CI/tests/bats.yml` | BATS tests (`tests/` directory) | +| `CI/tests/cargo_test.yml` | Rust test suite (`cargo test --all-features --verbose`) | | `CI/tests/go_test.yml` | Go test suite (`go test ./...`) | | `CI/tests/jest.yml` | JavaScript/TypeScript test suite (Jest) | | `CI/tests/laravel_tests.yml` | Laravel test suite (PHP 8.2, SQLite, parallel) | diff --git a/scripts/CI/tests/cargo_test.yml b/scripts/CI/tests/cargo_test.yml new file mode 100644 index 0000000..65df244 --- /dev/null +++ b/scripts/CI/tests/cargo_test.yml @@ -0,0 +1,20 @@ +cargo_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Cache Cargo registry and target + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Run cargo test + run: bash scripts/shell/tests/cargo_test.sh diff --git a/scripts/shell/tests/cargo_test.sh b/scripts/shell/tests/cargo_test.sh new file mode 100644 index 0000000..1ead97a --- /dev/null +++ b/scripts/shell/tests/cargo_test.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ ! -f "Cargo.toml" ]]; then + echo "::error::No Cargo.toml found" + exit 1 +fi + +echo "ℹ️ Running cargo test..." +cargo test --all-features --verbose \ + && echo "✅ cargo tests passed" \ + || { echo "❌ cargo tests failed"; exit 1; } diff --git a/tests/tests/cargo_test.bats b/tests/tests/cargo_test.bats new file mode 100644 index 0000000..3935813 --- /dev/null +++ b/tests/tests/cargo_test.bats @@ -0,0 +1,47 @@ +#!/usr/bin/env bats + +load "../helpers/common" + +SCRIPT="$BATS_TEST_DIRNAME/../../scripts/shell/tests/cargo_test.sh" + +setup() { + setup_test_dir + mkdir -p "$TEST_DIR/bin" + export PATH="$TEST_DIR/bin:$PATH" +} + +teardown() { + teardown_test_dir +} + +make_cargo_stub() { + local exit_code="$1" + cat > "$TEST_DIR/bin/cargo" <