Skip to content

Commit

Permalink
Add CI check for odd BufEncoder CAP
Browse files Browse the repository at this point in the history
Add a test file that has an odd capacity BufEncoder.

Add a CI check that the test file does not compile.
  • Loading branch information
jamillambert committed Feb 19, 2025
1 parent a57caeb commit d8b7d11
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
11 changes: 11 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[workspace]
members = ["fuzz"]
members = ["fuzz", "tests/compiletest"]

[features]
default = ["std"]
Expand Down
12 changes: 12 additions & 0 deletions contrib/compile-tests.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/compiletest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "compiletest"
version = "0.1.0"
edition = "2021"
rust-version = "1.63.0"

[dependencies]
hex = { package = "hex-conservative", path = "../../" }
7 changes: 7 additions & 0 deletions tests/compiletest/src/main.rs
Original file line number Diff line number Diff line change
@@ -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); }

0 comments on commit d8b7d11

Please sign in to comment.