Skip to content

Commit

Permalink
Invoke cargo with exactly one target during tests (#490)
Browse files Browse the repository at this point in the history
This permits to avoid problems with dependencies and features
resolution.
  • Loading branch information
ia0 committed May 26, 2024
1 parent a5a74f8 commit a9a59a8
Show file tree
Hide file tree
Showing 34 changed files with 117 additions and 84 deletions.
4 changes: 3 additions & 1 deletion crates/api-desc/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ check_applet_api api- --features=

test_helper

cargo test --features=full-api
cargo test --lib --features=full-api
# TODO: Move this bin target to xtask.
cargo check --bin=wasefire-applet-api-desc
2 changes: 1 addition & 1 deletion crates/api-macro/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ check_applet_api api- --features=

test_helper

cargo test
cargo test --lib
8 changes: 4 additions & 4 deletions crates/api/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ check_applet_api api- --features=wasm, --target=wasm32-unknown-unknown

test_helper

cargo check --features=full-api,host
cargo check --target=thumbv7em-none-eabi --features=full-api,host
cargo check --target=wasm32-unknown-unknown --features=full-api,wasm
cargo check --target=thumbv7em-none-eabi --features=full-api,wasm,native
cargo check --lib --features=full-api,host
cargo check --lib --target=thumbv7em-none-eabi --features=full-api,host
cargo check --lib --target=wasm32-unknown-unknown --features=full-api,wasm
cargo check --lib --target=thumbv7em-none-eabi --features=full-api,wasm,native
cargo check --example=repr --features=full-api,host
8 changes: 4 additions & 4 deletions crates/board/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ check_board_api api- --features=std,

test_helper

cargo test --features=full-api,std
cargo check --target=thumbv7em-none-eabi --features=full-api
cargo check --target=thumbv7em-none-eabi \
cargo test --lib --features=full-api,std
cargo check --lib --target=thumbv7em-none-eabi --features=full-api
cargo check --lib --target=thumbv7em-none-eabi \
--features=full-api,internal-software-crypto
cargo check --target=riscv32imc-unknown-none-elf --features=full-api
cargo check --lib --target=riscv32imc-unknown-none-elf --features=full-api
2 changes: 1 addition & 1 deletion crates/cli-tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --lib
2 changes: 1 addition & 1 deletion crates/cli/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --bin=wasefire
6 changes: 3 additions & 3 deletions crates/error/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ set -e

test_helper

cargo test
cargo check --target=thumbv7em-none-eabi --features=defmt
cargo check --target=wasm32-unknown-unknown
cargo test --lib
cargo check --lib --target=thumbv7em-none-eabi --features=defmt
cargo check --lib --target=wasm32-unknown-unknown
11 changes: 6 additions & 5 deletions crates/interpreter/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ ensure_submodule third_party/WebAssembly/spec

test_helper

cargo check
cargo check --target=thumbv7em-none-eabi
cargo check --target=riscv32imc-unknown-none-elf \
cargo test --lib --features=toctou
cargo check --lib --target=thumbv7em-none-eabi
cargo check --lib --target=riscv32imc-unknown-none-elf \
--features=portable-atomic/critical-section
RUSTFLAGS=--cfg=portable_atomic_unsafe_assume_single_core \
cargo check --target=riscv32imc-unknown-none-elf
cargo test --features=debug,toctou,float-types,vector-types
cargo check --lib --target=riscv32imc-unknown-none-elf
cargo test --test=spec --features=debug,toctou,float-types,vector-types
cargo check --example=hello
8 changes: 4 additions & 4 deletions crates/logger/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -e

test_helper

cargo test
cargo check --target=thumbv7em-none-eabi
cargo check --target=thumbv7em-none-eabi --features=defmt
cargo check --features=log
cargo test --lib
cargo check --lib --target=thumbv7em-none-eabi
cargo check --lib --target=thumbv7em-none-eabi --features=defmt
cargo check --lib --features=log
8 changes: 4 additions & 4 deletions crates/prelude/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ done

test_helper

cargo check --target=wasm32-unknown-unknown --features=full-api
cargo check --target=wasm32-unknown-unknown --features=full-api,rust-crypto
cargo check --features=full-api,native
cargo test --features=full-api,test
cargo check --lib --target=wasm32-unknown-unknown --features=full-api
cargo check --lib --target=wasm32-unknown-unknown --features=full-api,rust-crypto
cargo check --lib --features=full-api,native
cargo test --lib --features=full-api,test
8 changes: 4 additions & 4 deletions crates/protocol-usb/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set -e

test_helper

cargo test --features=host
cargo check --target=thumbv7em-none-eabi --features=device
cargo check --features=host,std,log
DEFMT_LOG=trace cargo check --target=thumbv7em-none-eabi --features=device,defmt
cargo test --lib --features=host
cargo check --lib --target=thumbv7em-none-eabi --features=device
cargo check --lib --features=host,std,log
DEFMT_LOG=trace cargo check --lib --target=thumbv7em-none-eabi --features=device,defmt
3 changes: 2 additions & 1 deletion crates/protocol/fuzz/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ set -e

test_helper

cargo check
cargo check --bin=request
cargo check --bin=response
4 changes: 2 additions & 2 deletions crates/protocol/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set -e

test_helper

cargo test
cargo check --target=thumbv7em-none-eabi
cargo test --lib
cargo check --lib --target=thumbv7em-none-eabi
2 changes: 1 addition & 1 deletion crates/runner-host/crates/web-common/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --lib
4 changes: 2 additions & 2 deletions crates/runner-host/crates/web-server/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set -e

test_helper

cargo test
cargo check --features=wasefire-logger/log
cargo test --lib
cargo check --lib --features=wasefire-logger/log
10 changes: 5 additions & 5 deletions crates/runner-host/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ ensure_applet

test_helper

cargo test --features=wasm,debug
cargo check --features=wasm,debug,web
cargo check --features=wasm,release
cargo check --target=i686-unknown-linux-gnu --features=native,release
cargo check --no-default-features --features=wasm,debug
cargo test --bin=runner-host --features=wasm,debug
cargo check --bin=runner-host --features=wasm,debug,web
cargo check --bin=runner-host --features=wasm,release
cargo check --bin=runner-host --target=i686-unknown-linux-gnu --features=native,release
cargo check --bin=runner-host --no-default-features --features=wasm,debug
4 changes: 2 additions & 2 deletions crates/runner-nordic/crates/bootloader/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set -e

test_helper

cargo check --target=thumbv7em-none-eabi
cargo check --target=thumbv7em-none-eabi --release
cargo check --bin=bootloader --target=thumbv7em-none-eabi
cargo check --bin=bootloader --target=thumbv7em-none-eabi --release
4 changes: 2 additions & 2 deletions crates/runner-nordic/crates/header/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set -e

test_helper

cargo check
cargo check --target=thumbv7em-none-eabi
cargo check --lib
cargo check --lib --target=thumbv7em-none-eabi
10 changes: 5 additions & 5 deletions crates/runner-nordic/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ ensure_applet

test_helper

cargo check --target=thumbv7em-none-eabi --features=wasm,debug
cargo check --target=thumbv7em-none-eabi --features=wasm,debug,software-crypto
DEFMT_LOG=trace cargo check --target=thumbv7em-none-eabi --features=wasm,debug
cargo check --target=thumbv7em-none-eabi --features=wasm,release
cargo check --target=thumbv7em-none-eabi --features=native,release
cargo check --bin=runner-nordic --target=thumbv7em-none-eabi --features=wasm,debug
cargo check --bin=runner-nordic --target=thumbv7em-none-eabi --features=wasm,debug,software-crypto
DEFMT_LOG=trace cargo check --bin=runner-nordic --target=thumbv7em-none-eabi --features=wasm,debug
cargo check --bin=runner-nordic --target=thumbv7em-none-eabi --features=wasm,release
cargo check --bin=runner-nordic --target=thumbv7em-none-eabi --features=native,release
17 changes: 8 additions & 9 deletions crates/scheduler/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ check_board_api board-api- --features=wasm,std,

test_helper

cargo test --features=full-api,wasm,std
cargo check --features=full-api,wasm,std,log
cargo check --target=i686-unknown-linux-gnu --features=full-api,native,std
cargo check --target=i686-unknown-linux-gnu \
--features=full-api,native,std,log
cargo check --target=thumbv7em-none-eabi --features=full-api,wasm
cargo check --target=thumbv7em-none-eabi --features=full-api,wasm,defmt
cargo check --target=thumbv7em-none-eabi --features=full-api,native
cargo check --target=thumbv7em-none-eabi --features=full-api,native,defmt
cargo test --lib --features=full-api,wasm,std
cargo check --lib --features=full-api,wasm,std,log
cargo check --lib --target=i686-unknown-linux-gnu --features=full-api,native,std
cargo check --lib --target=i686-unknown-linux-gnu --features=full-api,native,std,log
cargo check --lib --target=thumbv7em-none-eabi --features=full-api,wasm
cargo check --lib --target=thumbv7em-none-eabi --features=full-api,wasm,defmt
cargo check --lib --target=thumbv7em-none-eabi --features=full-api,native
cargo check --lib --target=thumbv7em-none-eabi --features=full-api,native,defmt
5 changes: 3 additions & 2 deletions crates/store/fuzz/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ set -e

test_helper

cargo check
cargo test --lib --examples
cargo test --lib
cargo check --bin=store
cargo check --example=store
2 changes: 1 addition & 1 deletion crates/store/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ test_helper

cargo test --lib --features=std
cargo test --test=store --features=std
cargo check --target=thumbv7em-none-eabi
cargo check --lib --target=thumbv7em-none-eabi
2 changes: 1 addition & 1 deletion crates/stub/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --lib
4 changes: 2 additions & 2 deletions crates/sync/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set -e

test_helper

cargo test
cargo check --target=thumbv7em-none-eabi
cargo test --lib
cargo check --lib --target=thumbv7em-none-eabi
2 changes: 1 addition & 1 deletion crates/xtask/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --bin=xtask
2 changes: 1 addition & 1 deletion examples/rust/exercises/client/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --bin=client
4 changes: 2 additions & 2 deletions examples/rust/exercises/interface/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set -e

test_helper

cargo test
cargo check --target=wasm32-unknown-unknown
cargo test --lib
cargo check --lib --target=wasm32-unknown-unknown
4 changes: 2 additions & 2 deletions examples/rust/hsm/common/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ set -e

test_helper

cargo test --features=std
cargo check --target=wasm32-unknown-unknown --features=api
cargo test --lib --features=std
cargo check --lib --target=wasm32-unknown-unknown --features=api
2 changes: 1 addition & 1 deletion examples/rust/hsm/host/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --bin=host
2 changes: 1 addition & 1 deletion examples/rust/protocol/host/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo check
cargo check --bin=host
2 changes: 1 addition & 1 deletion examples/rust/update/host/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set -e

test_helper

cargo test
cargo test --bin=host
3 changes: 3 additions & 0 deletions scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ package_features() { sed -n '/^\[features]$/,/^$/{s/ = .*$//p}' Cargo.toml; }
package_doc_features() { _package_doc_raw features; }
package_doc_targets() { _package_doc_raw targets; }
package_doc_default_target() { _package_doc_raw default-target | tr -d '"'; }
package_bin_name() { _package_bin_string name; }
package_bin_path() { _package_bin_string path; }

# Internal helpers
_package_raw() { sed -n '/^\[package]$/,/^$/{s/^'"$1"' = //p}' Cargo.toml; }
_package_string() { _package_raw "$1" | sed 's/^"\(.*\)"$/\1/'; }
_package_doc_raw() {
sed -n '/^\[package\.metadata\.docs\.rs]$/,/^$/{s/^'"$1"' = //p}' Cargo.toml
}
_package_bin_string() { sed -n '/^\[\[bin\]\]$/,/^$/{s/^'"$1"' = "\(.*\)"$/\1/p}' Cargo.toml; }
2 changes: 1 addition & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ for crate in "${TOPOLOGICAL_ORDER[@]}"; do
exit
fi
i "Publish $crate from $latest to $current"
eval "$(sed -n 's/^cargo \(check\|test\)/cargo publish/p;T;q' test.sh)"
eval "$(sed -En 's/^cargo (check|test) --(lib|bin=[^ ]*)/cargo publish/p;T;q' test.sh)"
)
done
40 changes: 33 additions & 7 deletions scripts/test-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ check_software_crypto() {
}

test_helper() {
_test_desc | grep -v 'cargo \(check\|test\)' \
_test_desc | grep -Ev 'cargo (check|test) --(lib|(bin|test|example)=[^ ]*)( |$)' \
&& e 'Invalid description (invalid commands are listed above).'
# TODO: Check tests/* and examples/* to make sure they have a specific line. Or actually, create
# one clippy per test/example based on the first cargo check unless that test/example already has
# custom line
# TODO: Also check that there's a cargo test if there's a #[test].
_test_ensure_lib
_test_ensure_bins
_test_ensure_dir tests test test
_test_ensure_dir examples check example
_test_desc | _test_check | grep 'cargo check' | sh -ex
_test_desc | grep 'cargo test' | sh -ex
x cargo fmt -- --check
Expand All @@ -76,12 +76,38 @@ test_helper() {
}

_test_desc() {
sed '0,/^test_helper$/d;:a;/\\$/{N;s/\\\n//;ta};s/ \+/ /g' "$SELF" | grep -v '^\($\|#\)'
sed '0,/^test_helper$/d;:a;/\\$/{N;s/\\\n//;ta};s/ \+/ /g' "$SELF" | grep -Ev '^($|#)'
}

_test_check() { sed 's/cargo test/cargo check --profile=test/'; }
_test_clippy() { sed 's/cargo check/cargo clippy/;s/$/ -- --deny=warnings/'; }

_test_ensure_lib() {
if [ -e src/lib.rs ]; then
if git grep -q '#\[test\]' src
then _test_ensure_desc 'cargo test --lib'
else _test_ensure_desc 'cargo (check|test) --lib'
fi
fi
}
_test_ensure_bins() {
local i
for i in $(package_bin_name); do
_test_ensure_desc "cargo (check|test) --bin=$i"
done
if [ -e src/main.rs ] && ! package_bin_path | grep -q src/main.rs; then
_test_ensure_desc "cargo (check|test) --bin=$(package_name)"
fi
}
_test_ensure_dir() {
local i
[ -d $1 ] || return 0
for i in $(find $1 -name '*.rs' -printf '%P\n'); do
_test_ensure_desc "cargo $2 --$3=${i%.rs}"
done
}
_test_ensure_desc() { _test_desc | grep -Eq "$1" || e "No \`$1\` found."; }

_test_check_api() {
local api="$1"
local prefix="$2"
Expand All @@ -95,7 +121,7 @@ _test_check_api() {
$(_test_full_deps $full $prefix)
fi
for api in $api; do
x cargo clippy "$@" "$features$prefix$api" -- --deny=warnings
x cargo clippy --lib "$@" "$features$prefix$api" -- --deny=warnings
done
}

Expand Down

0 comments on commit a9a59a8

Please sign in to comment.