Add tests, front() method overload #106
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow checks each crate builds and runs, and for lints. | |
| name: Check | |
| # Runs this workflow | |
| on: | |
| # On all pull requests, regardless of target branch | |
| pull_request: | |
| # On PRs in the merge queue | |
| merge_group: | |
| # After merges to main | |
| push: | |
| branches: | |
| - main | |
| # When a developer asks for a manual workflow run | |
| workflow_dispatch: | |
| jobs: | |
| build-rust: | |
| name: 1. Build Rust crates | |
| runs-on: ubuntu-latest | |
| # Actions are pinned to a commit to prevent supply-chain attacks | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| # Use the same components in every step for caching | |
| components: cargo,clippy,rustfmt | |
| - name: Build each Rust crate | |
| run: cargo build --all-targets --all-features | |
| test-rust: | |
| name: 2. Test Rust crates | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-rust | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| components: cargo,clippy,rustfmt | |
| - name: Test each Rust crate | |
| run: | | |
| cargo test --all-targets --all-features | |
| cargo test --doc --all-features | |
| run: | |
| name: 3. Run Rust overload-test binaries | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-rust | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| components: cargo,clippy,rustfmt | |
| - name: Run Rust overload-test binaries | |
| # Find all test crate binaries, extract the basename (no directories or extensions), | |
| # then run them one at a time with cargo. | |
| # There is no default-run binary set in Cargo.toml. | |
| run: | | |
| find splat-overload-test/src/bin -name "*.rs" | \ | |
| sed 's|.*/\([^/]*\).rs|\1|g' | \ | |
| xargs --max-args=1 cargo run --all-features --bin | |
| clippy-rust: | |
| name: 4. Clippy lints on Rust crates | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| components: cargo,clippy,rustfmt | |
| - name: Run clippy on Rust crates | |
| run: cargo clippy --all-targets --all-features -- --deny warnings | |
| doc-rust: | |
| name: 5. Doc lints on Rust crates | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| components: cargo,clippy,rustfmt | |
| - name: Run doc checks on Rust crates | |
| run: cargo doc --all-features | |
| fmt-rust: | |
| name: 6. Code format on Rust crates | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| components: cargo,clippy,rustfmt | |
| - name: Run rustfmt checks on crates | |
| run: cargo fmt --all -- --check | |
| publish-dry-run: | |
| name: 7. Dry run publishing | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-rust | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| components: cargo,clippy,rustfmt | |
| - name: Dry run publishing | |
| run: cargo publish --dry-run | |
| diagnostics-rust: | |
| name: 8. Diagnostics tests on Rust crates | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-rust | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| # Use the same components in every step for caching | |
| components: cargo,clippy,rustfmt | |
| - name: Check diagnostic output | |
| # To bless (update the expected diagnostics), change '/tmp' to 'splat-overload-diagnostics/src/bin', | |
| # and disable color output. | |
| # Or just do `cargo build --package splat-overload-diagnostics --bin NAME > splat-overload-diagnostics/src/bin/NAME.stderr 2>&1` | |
| # and delete the cargo Updating/Download*/Compiling logs. | |
| # FIXME: turn this into a script so we can run it locally. | |
| run: | | |
| cargo fmt --package splat-overload-diagnostics -- --check | |
| export CARGO_TERM_COLOR=never | |
| set -o pipefail | |
| TEST_NAMES=$(find splat-overload-diagnostics/src/bin -name "*.rs" | \ | |
| sed 's|.*/\([^/]*\).rs|\1|g' ) | |
| echo "testing failure diagnostics: $TEST_NAMES" | |
| for test_name in $TEST_NAMES; do | |
| echo "testing failure diagnostics: $test_name" | |
| # We expect cargo to fail, so don't exit the shell when it does | |
| set +e | |
| # Ignore build progress, if it's cached then the built crates change | |
| cargo build --all-features --package splat-overload-diagnostics --bin "$test_name" 2>&1 | \ | |
| grep --invert-match -e 'Updating .* index' -e 'Downloading .*' -e 'Downloaded .*' -e 'Compiling [^ ]* .*' \ | |
| > "/tmp/$test_name.stderr" | |
| CARGO_EXIT_CODE=$? | |
| set -e | |
| if [[ $CARGO_EXIT_CODE -ne 101 ]]; then | |
| echo "error: $test_name compilation unexpectedly returned exit code $CARGO_EXIT_CODE rather than 101" | |
| exit 1 | |
| fi | |
| echo "comparing diagnostics for: $test_name" | |
| diff --unified=5 "splat-overload-diagnostics/src/bin/$test_name.stderr" /tmp/"$test_name.stderr" | |
| done | |
| cpp-overload-test-ok: | |
| name: 9. Check C++ overloads | |
| # Ubuntu 26.04 is needed for C++23 standard library features. | |
| runs-on: ubuntu-26.04 | |
| needs: | |
| - build-rust | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| # Use the same components in every step for caching | |
| components: cargo,clippy,rustfmt | |
| # FIXME: turn this into a script so contributors can run it locally. | |
| - name: Check C++ overload ok cases | |
| run: | | |
| echo "Checking the crate library builds on a newer platform:" | |
| cargo build --all-targets --all-features | |
| cargo clippy --all-targets --all-features -- --deny warnings | |
| cargo test --all-targets --all-features | |
| cargo test --doc --all-features | |
| echo "Checking the C++ overload test crate builds:" | |
| cargo build --all-features --package cpp-overload-test --lib | |
| cargo clippy --all-features --package cpp-overload-test -- --deny warnings | |
| cargo test --all-features --package cpp-overload-test --lib | |
| cargo test --doc --all-features --package cpp-overload-test | |
| cargo fmt --package cpp-overload-test -- --check | |
| cpp-overload-test-fail: | |
| name: 10. Must-fail C++ overloads | |
| runs-on: ubuntu-26.04 | |
| # Don't run unless the test crate has built successfully, crates arealways built for examples. | |
| needs: | |
| - cpp-overload-test-ok | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 | |
| with: | |
| toolchain: nightly | |
| # Use the same components in every step for caching | |
| components: cargo,clippy,rustfmt | |
| - name: Check C++ overload fail cases | |
| # To bless (update the expected output), change '/tmp' to 'cpp-overload-test/examples', | |
| # and disable color output. | |
| # Or just do `cargo build --package cpp-overload-test --example NAME > cpp-overload-test/examples/NAME.stderr 2>&1` | |
| # and delete the cargo Updating/Download*/Compiling logs. | |
| # FIXME: turn this into a script so contributors can run it locally. | |
| run: | | |
| echo "Checking must-fail example builds:" | |
| export CARGO_TERM_COLOR=never | |
| set -o pipefail | |
| TEST_NAMES=$(find cpp-overload-test/examples -name "*.rs" | \ | |
| sed 's|.*/\([^/]*\).rs|\1|g' ) | |
| echo "testing incompatible overloads: $TEST_NAMES" | |
| for test_name in $TEST_NAMES; do | |
| echo "testing incompatible overloads: $test_name" | |
| # We expect cargo to fail, so don't exit the shell when it does | |
| set +e | |
| # Ignore build progress, if it's cached then the built crates change | |
| cargo build --all-features --package cpp-overload-test --example "$test_name" 2>&1 | \ | |
| grep --invert-match -e 'Updating .* index' -e 'Downloading .*' -e 'Downloaded .*' -e 'Compiling [^ ]* .*' \ | |
| > "/tmp/$test_name.stderr" | |
| CARGO_EXIT_CODE=$? | |
| set -e | |
| if [[ $CARGO_EXIT_CODE -ne 101 ]]; then | |
| echo "error: $test_name compilation unexpectedly returned exit code $CARGO_EXIT_CODE rather than 101" | |
| exit 1 | |
| fi | |
| echo "comparing incompatible overload diagnostics for: $test_name" | |
| diff --unified=5 "cpp-overload-test/examples/$test_name.stderr" /tmp/"$test_name.stderr" | |
| done | |
| all: | |
| name: All checks | |
| # Always run this job, even if earlier steps were skipped (or failed): | |
| # <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks> | |
| if: ${{ always() }} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-rust | |
| - test-rust | |
| - run | |
| - clippy-rust | |
| - doc-rust | |
| - fmt-rust | |
| - publish-dry-run | |
| - diagnostics-rust | |
| - cpp-overload-test-ok | |
| - cpp-overload-test-fail | |
| steps: | |
| - name: Fail if any other job failed | |
| # Every job status needs to be checked here, because `always()` stops failures from propagating automatically | |
| run: | | |
| echo "Checking other jobs..." | |
| [[ "${{ needs.build-rust.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.test-rust.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.run.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.clippy-rust.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.doc-rust.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.fmt-rust.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.publish-dry-run.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.diagnostics-rust.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.cpp-overload-test-ok.result }}" == "success" ]] || exit 1 | |
| [[ "${{ needs.cpp-overload-test-fail.result }}" == "success" ]] || exit 1 |