Skip to content

Commit

Permalink
Fix build-breakers
Browse files Browse the repository at this point in the history
Fix some build-breaking issues introduced in [1].

* Update Dockerfile for new integration tests

* alpine doesn't have bash; make integration tests use sh

* stdout line endings on Windows contain CRLF

References

1. 7c419a7 "ci, sample: add tests for child processes"
  • Loading branch information
cbs228 committed Feb 3, 2024
1 parent 708cfa7 commit d3f6c2a
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 69 deletions.
22 changes: 7 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions sample/long_message.22050.s16le.bash

This file was deleted.

15 changes: 15 additions & 0 deletions sample/long_message.22050.s16le.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/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"
14 changes: 0 additions & 14 deletions sample/npt.22050.s16le.bash

This file was deleted.

16 changes: 16 additions & 0 deletions sample/npt.22050.s16le.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/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"
34 changes: 20 additions & 14 deletions sample/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
#
# Runs integration tests for samedec.
#
Expand All @@ -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() {
Expand All @@ -26,23 +27,28 @@ run_samedec() {

infile="$1"

"${RUNARGS[@]}" \
#shellcheck disable=SC2086
"$SAMEDEC" $ARGS \
--rate 22050 \
--file "${infile}.bin" \
-- \
bash \
"${infile}.bash" | tee /dev/stderr
sh \
"${infile}.sh" | \
tee /dev/stderr
}

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" | tr -d '\r')"
expect="$(cat "${file}.txt" | tr -d '\r')"

printf '[%s]: PASS\n' "$file"
if [ "$output" = "$expect" ]; then
printf '[%s]: PASS\n' "$file"
else
printf '[%s]: FAIL\n' "$file"
exit 1
fi
done
13 changes: 0 additions & 13 deletions sample/two_and_two.22050.s16le.bash

This file was deleted.

15 changes: 15 additions & 0 deletions sample/two_and_two.22050.s16le.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/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"

0 comments on commit d3f6c2a

Please sign in to comment.