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 24, 2025
1 parent 3dee66b commit 1451ac8
Show file tree
Hide file tree
Showing 3 changed files with 63 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
51 changes: 51 additions & 0 deletions contrib/compile-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

should_pass() {
all_passed=true
# All crates in the subdirectory pass/ must compile
for dir in pass/*; do
if [ -d "$dir" ]; then
pushd "$dir" > /dev/null
if ! cargo run > /dev/null 2>&1; then
echo "compiletests/$dir/ failed to compile"
all_passed=false
fi
popd > /dev/null
fi
done
if [ "$all_passed" = true ]; then
return 0
else
return 1
fi
}

should_fail() {
all_failed=true
# All crates in the subdirectory fail/ must fail to compile
for dir in fail/*; do
if [ -d "$dir" ]; then
pushd "$dir" > /dev/null
if cargo run > /dev/null 2>&1; then
echo "compiletests/$dir/ compiled when it should not have"
all_failed=false
fi
popd > /dev/null
fi
done
if [ "$all_failed" = true ]; then
return 0
else
return 1
fi
}

# Check that all files in compiletests pass or fail as expected
cd tests/compiletests
if should_pass && should_fail; then
echo "Compile tests passed"
exit 0
else
echo "Compile tests failed"
exit 1
fi

0 comments on commit 1451ac8

Please sign in to comment.