From f3223ddd3ee01eb9317bf1cb7fca657f4c3ffb9b Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Wed, 18 Sep 2024 09:52:27 +0200 Subject: [PATCH] Create rust unit test command --- scripts/did.sh | 38 +++++++++++++++++++------------------- scripts/pic-install | 2 +- scripts/test-rs | 9 +++++++++ 3 files changed, 29 insertions(+), 20 deletions(-) create mode 100755 scripts/test-rs diff --git a/scripts/did.sh b/scripts/did.sh index 7197fa0..458f77f 100755 --- a/scripts/did.sh +++ b/scripts/did.sh @@ -1,37 +1,37 @@ #!/usr/bin/env bash did_file_location_from_cargo() { - # Warning: Does no _- conversion. - cargo metadata --format-version 1 | jq -r --arg v "$1" '.packages[] | select(.name==$v) | .manifest_path | sub("Cargo.toml";"\($v).did")' + # Warning: Does no _- conversion. + cargo metadata --format-version 1 | jq -r --arg v "$1" '.packages[] | select(.name==$v) | .manifest_path | sub("Cargo.toml";"\($v).did")' } cargo_manifest_path() { - # Warning: Does no _- conversion. - cargo metadata --format-version 1 | jq -r --arg v "$1" '.packages[] | select(.name==$v) | .manifest_path")' + # Warning: Does no _- conversion. + cargo metadata --format-version 1 | jq -r --arg v "$1" '.packages[] | select(.name==$v) | .manifest_path")' } did_file_location_from_dfx_json() { - # Warning: Does no _- conversion. - jq -r --arg v "$1" '.canisters[$v].candid' dfx.json + # Warning: Does no _- conversion. + jq -r --arg v "$1" '.canisters[$v].candid' dfx.json } function generate_did() { - local canister=$1 - echo "Deriving candid file from Rust for $canister" - #local manifest_path="$(cargo_manifest_path "$canister")" - #local candid_file="${manifest_path%Cargo.toml}$canister.did" - local candid_file="$(did_file_location_from_dfx_json "$canister")" + local canister=$1 + echo "Deriving candid file from Rust for $canister" + #local manifest_path="$(cargo_manifest_path "$canister")" + #local candid_file="${manifest_path%Cargo.toml}$canister.did" + local candid_file="$(did_file_location_from_dfx_json "$canister")" - test -e "target/wasm32-unknown-unknown/release/$canister.wasm" || - cargo build -p "$canister" \ - --target wasm32-unknown-unknown \ - --release --package "$canister" + test -e "target/wasm32-unknown-unknown/release/$canister.wasm" || + cargo build -p "$canister" \ + --target wasm32-unknown-unknown \ + --release --package "$canister" - # cargo install candid-extractor - candid-extractor "target/wasm32-unknown-unknown/release/$canister.wasm" >"$candid_file" - echo "Written: $candid_file" + # cargo install candid-extractor + candid-extractor "target/wasm32-unknown-unknown/release/$canister.wasm" >"$candid_file" + echo "Written: $candid_file" } CANISTERS=(example_app_backend example_paid_service) for canister in ${CANISTERS[@]}; do - generate_did "$canister" + generate_did "$canister" done diff --git a/scripts/pic-install b/scripts/pic-install index b796a0c..0edf992 100755 --- a/scripts/pic-install +++ b/scripts/pic-install @@ -13,7 +13,7 @@ else exit 1 fi -if "$POCKET_IC_SERVER_PATH" --version &>/dev/null | grep -wq "$POCKET_IC_SERVER_VERSION" ; then +if "$POCKET_IC_SERVER_PATH" --version &>/dev/null | grep -wq "$POCKET_IC_SERVER_VERSION"; then echo "PocketIC server already exists at: $POCKET_IC_SERVER_PATH" echo "Skipping download." else diff --git a/scripts/test-rs b/scripts/test-rs new file mode 100755 index 0000000..2bd8931 --- /dev/null +++ b/scripts/test-rs @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +print_help() { + echo "Runs rust unit tests." +} + +[[ "${1:-}" != "--help" ]] || print_help + +cargo test --lib --bins "${@}"