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 test file that has an even capacity BufEncoder.

Add a CI check that the even capacity compiles and the odd capacity
does not.
  • Loading branch information
jamillambert committed Feb 21, 2025
1 parent a57caeb commit 5a70ac4
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
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
36 changes: 36 additions & 0 deletions contrib/compile-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

even_capacity() {
cd even-capacity
if cargo run > /dev/null 2>&1; then
cd ..
return 0
else
cd ..
return 1
fi
}

odd_capacity() {
cd odd-capacity
if cargo run > /dev/null 2>&1; then
cd ..
return 0
else
cd ..
return 1
fi
}

# Check that an even capacity BufEncoder compiles and an odd BufEncoder capacity fails to compile
cd tests/compiletests
if ! even_capacity; then
echo "even-capacity BufEncoder failed to compile"
exit 1
elif odd_capacity; then
echo "odd-capacity BufEncoder compiled when it should not have"
exit 1
else
echo "BufEncoder capacity compile tests passed"
exit 0
fi
10 changes: 10 additions & 0 deletions tests/compiletests/even-capacity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "even-capacity"
version = "0.1.0"
edition = "2021"
rust-version = "1.63.0"

[workspace]

[dependencies]
hex = { package = "hex-conservative", path = "../../../" }
5 changes: 5 additions & 0 deletions tests/compiletests/even-capacity/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use hex::buf_encoder::BufEncoder;
use hex::Case;

// This should compile, ensuring that the compile error in odd-capacity is from the odd capacity.
fn main() { let _encoder = BufEncoder::<4>::new(Case::Lower); }
10 changes: 10 additions & 0 deletions tests/compiletests/odd-capacity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "odd-capacity"
version = "0.1.0"
edition = "2021"
rust-version = "1.63.0"

[workspace]

[dependencies]
hex = { package = "hex-conservative", path = "../../../" }
6 changes: 6 additions & 0 deletions tests/compiletests/odd-capacity/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use hex::buf_encoder::BufEncoder;
use hex::Case;

// This should fail to compile because the capacity size is odd.
// The only difference to `even-capacity` is the capacity size.
fn main() { let _encoder = BufEncoder::<3>::new(Case::Lower); }

0 comments on commit 5a70ac4

Please sign in to comment.