From d8b7d11db153a73b4e78812ba7a9c530eafca12e Mon Sep 17 00:00:00 2001 From: "Jamil Lambert, PhD" Date: Wed, 19 Feb 2025 19:36:51 +0000 Subject: [PATCH] Add CI check for odd BufEncoder CAP Add a test file that has an odd capacity BufEncoder. Add a CI check that the test file does not compile. --- .github/workflows/README.md | 1 + .github/workflows/rust.yaml | 11 +++++++++++ Cargo.toml | 2 +- contrib/compile-tests.sh | 12 ++++++++++++ tests/compiletest/Cargo.toml | 8 ++++++++ tests/compiletest/src/main.rs | 7 +++++++ 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 contrib/compile-tests.sh create mode 100644 tests/compiletest/Cargo.toml create mode 100644 tests/compiletest/src/main.rs diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 21f8272..ef4f912 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -24,3 +24,4 @@ Run from rust.yml unless stated otherwise. Unfortunately we are now exceeding th 10. `Arch32bit` 11. `Cross` 12. `Format` +13. `Compile tests` diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index b0b1bc6..311e8db 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -218,3 +218,14 @@ jobs: run: rustup component add rustfmt - name: "Check formatting" run: cargo +nightly fmt --all -- --check + + Compile: + name: Compile tests + runs-on: ubuntu-latest + steps: + - name: "Checkout repo" + uses: actions/checkout@v4 + - name: "Select toolchain" + uses: dtolnay/rust-toolchain@stable + - name: "Run compile tests" + run: ./contrib/compile-tests.sh diff --git a/Cargo.toml b/Cargo.toml index 47ff9df..ed25e5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [workspace] -members = ["fuzz"] +members = ["fuzz", "tests/compiletest"] [features] default = ["std"] diff --git a/contrib/compile-tests.sh b/contrib/compile-tests.sh new file mode 100755 index 0000000..c3e7283 --- /dev/null +++ b/contrib/compile-tests.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Check that an odd BufEncoder capacity fails to compile + +cd tests/compiletest +if cargo run > /dev/null 2>&1; then + echo "test compiled with an odd BufEncoder capacity when it shouldn't" + exit 1 +else + echo "odd BufEncoder capacity failed to compile as expected" + exit 0 +fi diff --git a/tests/compiletest/Cargo.toml b/tests/compiletest/Cargo.toml new file mode 100644 index 0000000..c691770 --- /dev/null +++ b/tests/compiletest/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "compiletest" +version = "0.1.0" +edition = "2021" +rust-version = "1.63.0" + +[dependencies] +hex = { package = "hex-conservative", path = "../../" } diff --git a/tests/compiletest/src/main.rs b/tests/compiletest/src/main.rs new file mode 100644 index 0000000..1650880 --- /dev/null +++ b/tests/compiletest/src/main.rs @@ -0,0 +1,7 @@ +use hex::buf_encoder::BufEncoder; +use hex::Case; + +fn main() { odd_buffer(); } + +// This should fail to compile because the capacity size is odd. +fn odd_buffer() { let _encoder = BufEncoder::<3>::new(Case::Lower); }