diff --git a/.github/workflows/rust_release.yml b/.github/workflows/rust_release.yml index ae231d6..f217d4b 100644 --- a/.github/workflows/rust_release.yml +++ b/.github/workflows/rust_release.yml @@ -230,17 +230,9 @@ jobs: - name: Run integration tests shell: bash run: | - set -e; - "$samedec_exe" --version - for file in $(basename -s .bin sample/*.s16le.bin); do - printf '[%s]\n' "$file"; - "$samedec_exe" -r 22050 <"sample/$file.bin" | tee result; - cmp result "sample/$file.txt" || { - echo "FAIL!"; - exit 1; - }; - echo "PASS"; - done + pushd sample && + ./test.sh && + popd - name: Copy artifact shell: bash @@ -316,17 +308,9 @@ jobs: - name: Run integration tests run: | - set -e; - "$samedec_exe" --version - for file in $(basename -s .bin sample/*.s16le.bin); do - printf '[%s]\n' "$file"; - "$samedec_exe" -r 22050 <"sample/$file.bin" | tee result; - cmp result "sample/$file.txt" || { - echo "FAIL!"; - exit 1; - }; - echo "PASS"; - done + pushd sample && + ./test.sh && + popd - name: Copy artifact run: | diff --git a/Dockerfile b/Dockerfile index ac27047..83a95ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ### set --build-arg CARGO_NET_OFFLINE=true # Rust version, like "1" or "1.67.0" -ARG BUILD_RUST_TAG=1.67 +ARG BUILD_RUST_TAG=1.70 # Build operating system # Use slim-buster for glibc or alpine for musl @@ -100,21 +100,13 @@ RUN [ -n "$CARGO_BUILD_TARGET" ] || unset CARGO_BUILD_TARGET && \ cargo test --frozen --release --workspace && \ cargo install --frozen --path=crates/samedec -# Perform tests -RUN samedec --version +# Perform integration tests +COPY sample sample -COPY sample/*.22050.s16le.* . - -RUN set -e; \ - for file in $(basename -s .bin *.s16le.bin); do \ - printf '[%s]\n' "$file"; \ - samedec -r 22050 <"$file.bin" | tee result; \ - cmp result "$file.txt" || {\ - echo "FAIL!"; \ - exit 1; \ - }; \ - echo "PASS"; \ - done +RUN samedec --version && \ + cd sample && \ + SAMEDEC=/usr/local/bin/samedec ./test.sh && \ + cd .. ### ### NON-IMAGE diff --git a/sample/long_message.22050.s16le.bash b/sample/long_message.22050.s16le.bash deleted file mode 100644 index a158c27..0000000 --- a/sample/long_message.22050.s16le.bash +++ /dev/null @@ -1,13 +0,0 @@ -set -e - -# close standard input to ignore it -exec 0>/dev/null - -[[ $SAMEDEC_RATE = "22050" ]] -[[ $SAMEDEC_EVENT = "Practice/Demo Warning" ]] -[[ $SAMEDEC_ORG = "EAS" ]] -[[ $SAMEDEC_SIGNIFICANCE = "W" ]] -[[ $SAMEDEC_LOCATIONS = "372088 091724 919623 645687 745748 175234 039940 955869 091611 304171 931612 334828 179485 569615 809223 830187 611340 014693 472885 084645 977764 466883 406863 390018 701741 058097 752790 311648 820127 255900 581947" ]] -[[ $SAMEDEC_ISSUETIME = "$SAMEDEC_PURGETIME" ]] - -echo "+OK" diff --git a/sample/long_message.22050.s16le.sh b/sample/long_message.22050.s16le.sh new file mode 100644 index 0000000..6abde37 --- /dev/null +++ b/sample/long_message.22050.s16le.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +set -e + +# close standard input to ignore it +exec 0>/dev/null + +[ "$SAMEDEC_RATE" = "22050" ] +[ "$SAMEDEC_EVENT" = "Practice/Demo Warning" ] +[ "$SAMEDEC_ORG" = "EAS" ] +[ "$SAMEDEC_SIGNIFICANCE" = "W" ] +[ "$SAMEDEC_LOCATIONS" = "372088 091724 919623 645687 745748 175234 039940 955869 091611 304171 931612 334828 179485 569615 809223 830187 611340 014693 472885 084645 977764 466883 406863 390018 701741 058097 752790 311648 820127 255900 581947" ] +[ "$SAMEDEC_ISSUETIME" = "$SAMEDEC_PURGETIME" ] + +echo "+OK" diff --git a/sample/npt.22050.s16le.bash b/sample/npt.22050.s16le.bash deleted file mode 100644 index e5c59ad..0000000 --- a/sample/npt.22050.s16le.bash +++ /dev/null @@ -1,14 +0,0 @@ -set -e - -# close standard input to ignore it -exec 0>/dev/null - -[[ $SAMEDEC_EVENT = "National Periodic Test" ]] -[[ $SAMEDEC_ORG = "PEP" ]] -[[ $SAMEDEC_SIGNIFICANCE = "T" ]] -[[ $SAMEDEC_LOCATIONS = "000000" ]] - -lifetime=$(( $SAMEDEC_PURGETIME - $SAMEDEC_ISSUETIME)) -[[ $lifetime -eq $(( 30*60 )) ]] - -echo "+OK" diff --git a/sample/npt.22050.s16le.sh b/sample/npt.22050.s16le.sh new file mode 100644 index 0000000..76aad32 --- /dev/null +++ b/sample/npt.22050.s16le.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +set -e + +# close standard input to ignore it +exec 0>/dev/null + +[ "$SAMEDEC_EVENT" = "National Periodic Test" ] +[ "$SAMEDEC_ORG" = "PEP" ] +[ "$SAMEDEC_SIGNIFICANCE" = "T" ] +[ "$SAMEDEC_LOCATIONS" = "000000" ] + +lifetime=$(( SAMEDEC_PURGETIME - SAMEDEC_ISSUETIME)) +[ "$lifetime" -eq $(( 30*60 )) ] + +echo "+OK" diff --git a/sample/test.sh b/sample/test.sh index f9f0e83..370732f 100755 --- a/sample/test.sh +++ b/sample/test.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # # Runs integration tests for samedec. # @@ -12,12 +12,13 @@ # The integration tests ensure that samedec's child process # spawning and environment variable assignment works. -set -euo pipefail +set -eu -if [ -n "${SAMEDEC:-}" ]; then - RUNARGS=("${SAMEDEC}") +if [ -z "${SAMEDEC:-}" ]; then + SAMEDEC="cargo" + ARGS="run -q -p samedec --" else - RUNARGS=('cargo' 'run' '-q' '-p' 'samedec' '--') + ARGS="" fi run_samedec() { @@ -26,23 +27,29 @@ run_samedec() { infile="$1" - "${RUNARGS[@]}" \ + #shellcheck disable=SC2086 + "$SAMEDEC" $ARGS \ --rate 22050 \ --file "${infile}.bin" \ -- \ - bash \ - "${infile}.bash" | tee /dev/stderr + sh \ + "${infile}.sh" } -for file in $(basename -s .bin *.s16le.bin); do +for file in $(basename -s .bin -- *.s16le.bin); do [ -e "${file}.bin" ] || exit 1 printf '[%s]\n' "$file" - cmp <(run_samedec "$file") "$file.txt" || { - printf '[%s]: FAIL\n' "$file" - exit 1 - }; + output="$(run_samedec "$file")" + expect="$(cat "${file}.txt")" - printf '[%s]: PASS\n' "$file" + echo "$output" + + if [ "$output" = "$expect" ]; then + printf '[%s]: PASS\n' "$file" + else + printf '[%s]: FAIL\n' "$file" + exit 1 + fi done diff --git a/sample/two_and_two.22050.s16le.bash b/sample/two_and_two.22050.s16le.bash deleted file mode 100644 index ebb6380..0000000 --- a/sample/two_and_two.22050.s16le.bash +++ /dev/null @@ -1,13 +0,0 @@ -set -e - -# close standard input to ignore it -exec 0>/dev/null - -[[ $SAMEDEC_EVENT = "Severe Thunderstorm Warning" ]] -[[ $SAMEDEC_ORIGINATOR = "Weather Service" ]] -[[ $SAMEDEC_SIGNIFICANCE = "W" ]] - -lifetime=$(( $SAMEDEC_PURGETIME - $SAMEDEC_ISSUETIME)) -[[ $lifetime -eq $(( 1*60*60 + 30*60 )) ]] - -echo "+OK" diff --git a/sample/two_and_two.22050.s16le.sh b/sample/two_and_two.22050.s16le.sh new file mode 100644 index 0000000..fca62dc --- /dev/null +++ b/sample/two_and_two.22050.s16le.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +set -e + +# close standard input to ignore it +exec 0>/dev/null + +[ "$SAMEDEC_EVENT" = "Severe Thunderstorm Warning" ] +[ "$SAMEDEC_ORIGINATOR" = "Weather Service" ] +[ "$SAMEDEC_SIGNIFICANCE" = "W" ] + +lifetime=$(( SAMEDEC_PURGETIME - SAMEDEC_ISSUETIME)) +[ "$lifetime" -eq $(( 1*60*60 + 30*60 )) ] + +echo "+OK"