Skip to content

Commit

Permalink
Add CI check for compile tests
Browse files Browse the repository at this point in the history
Create a script `contrib/compile-tests.sh` the checks that all crates in
`tests/compiletests/` do compile if in `pass/` and fail to compile if in
`fail/`

Add a CI step to run the script
  • Loading branch information
jamillambert committed Feb 25, 2025
1 parent 3dee66b commit c7eb39e
Show file tree
Hide file tree
Showing 3 changed files with 54 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
42 changes: 42 additions & 0 deletions contrib/compile-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# Checks intended compile failures.

set -euo pipefail

REPO_DIR=$(git rev-parse --show-toplevel)

compile_check() {
local dir_path=$1
local expected_status=$2
result=0
# All crates in the specified subdirectory must compile or fail based on expected_status
for dir in "$dir_path"/*; do
if [ -d "$dir" ]; then
pushd "$dir" > /dev/null
echo "Compiling $dir"
output=$(cargo build 2>&1)
if [ "$?" -ne "$expected_status" ]; then
if [ "$expected_status" -eq 0 ]; then
echo "$output"
echo "error: compile-tests/$dir/ failed to compile"
else
echo "error: compile-tests/$dir/ compiled when it should not have"
fi
result=1
fi
popd > /dev/null
fi
done
return "$result"
}

# Check that all files in compiletests pass or fail as expected
cd "$REPO_DIR"/tests/compile-tests
if compile_check "pass" 0 && compile_check "fail" 101; then
echo "Compile tests passed"
exit 0
else
echo "Compile tests failed"
exit 1
fi

0 comments on commit c7eb39e

Please sign in to comment.