Skip to content

Commit

Permalink
Add test-features recipe to justfile
Browse files Browse the repository at this point in the history
Created a `.sh` script using the `cargo-hack` tool in order to easily test all feature combinations. This is done in `--release` mode to reduce the size of the compiled artifacts.

The script is located in a new `contrib` directory (same approach followed by `rust-bitcoin` crates). This will be useful for CI as well.
  • Loading branch information
JoseSK999 committed Nov 13, 2024
1 parent 696c2a7 commit 5a2d338
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
46 changes: 46 additions & 0 deletions contrib/test_features.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

# Exit immediately if any command fails
set -e

# Install or update cargo-hack (will skip if up-to-date)
cargo install cargo-hack --locked

crates="\
floresta-chain \
floresta-cli \
floresta-common \
floresta-compact-filters \
floresta-electrum \
floresta-watch-only \
floresta-wire \
floresta \
florestad"

for crate in $crates; do
# Determine the path to the crate
if [ "$crate" = "florestad" ]; then
path="$crate"
else
path="crates/$crate"
fi

# The default feature, if not used to conditionally compile code, can be skipped as the combinations already
# include that case (see https://github.com/taiki-e/cargo-hack/issues/155#issuecomment-2474330839)
if [ "$crate" = "floresta-compact-filters" ] || [ "$crate" = "floresta-electrum" ]; then
# These two crates don't have a default feature
skip_default=""
else
skip_default="--skip default"
fi

# Navigate to the crate's directory
cd "$path" || exit 1
echo "Testing all feature combinations for $crate..."
export RUSTFLAGS="-Awarnings"

# Test all feature combinations
# shellcheck disable=SC2086
cargo hack test --release --feature-powerset $skip_default --quiet
cd - > /dev/null || exit 1
done
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ fmt:
# Checks the formatting
format:
cargo +nightly fmt --all --check

# Test all feature combinations for each crate using cargo hack
test-features:
./contrib/test_features.sh

0 comments on commit 5a2d338

Please sign in to comment.