57 lines
962 B
Bash
Executable File

#!/bin/bash
set -eu
set -o pipefail
: ${BIN:=..}
: ${EMU:=qemu-riscv64}
cmd=$BIN/echo
name=echo
fail=0
err() {
echo "FAIL $name: $*"
fail=1
}
# the shell strips the trailing newline when capturing output,
# which makes writing tests for echo a bit difficult
out=$($EMU $cmd)
len=$($EMU $cmd | wc -c)
stat=$?
if [ "$out" != "" ]; then
err "expected a newline"
fi
if [ "$len" -ne 1 ]; then
err "expected len 1, got len $len"
fi
if [ "$stat" -ne 0 ]; then
err "exited with status code $stat, expected 0"
fi
out=$($EMU $cmd a b c)
stat=$?
if [ "$out" != "a b c" ]; then
err "expected 'a b c', got '$out'"
fi
if [ "$stat" -ne 0 ]; then
err "exited with status code $stat, expected 0"
fi
out=$($EMU $cmd 'a b')
stat=$?
if [ "$out" != "a b" ]; then
err "expected 'a b', got '$out'"
fi
if [ "$stat" -ne 0 ]; then
err "exited with status code $stat, expected 0"
fi
if [ "$fail" -eq 0 ]; then
echo PASS $name
fi