Files
makronix/mobile/userland/echo/test.sh
T
lotherkandClaude Sonnet 5.5 73c9de51a6 licence: the CNCL line in every file Makronix wrote (tools, docs, www, mobile, top level)
consmirror.c: the BSD notice is replaced (Makronix's own file).  Files with
changes of other sessions pending are left for their commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:50:26 +00:00

63 lines
2.0 KiB
Bash

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# Test of the echo port. src/tests/bin/echo does not exist, so every case
# comes from echo(1): the operands are written separated by a single blank
# and followed by a newline; -n drops the newline; nothing else is an option
# (-e is a string like any other and a backslash is not an escape), and -n
# counts only in the first position.
#
# Usage: test.sh ECHO DATADIR
# ECHO the command that runs the port (a path, or "qemu-aarch64 -L
# <sysroot> <path>"; tools/userland-test.sh passes it)
# DATADIR unused: there is no NetBSD test data for echo ("/nonexistent")
# Prints one line per case and exits non-zero if one failed.
[ $# -eq 2 ] || { echo "usage: $0 ECHO DATADIR" >&2; exit 2; }
e=$1 d=$2
fails=0
t=${TMPDIR:-/tmp}/echo-test.$$
mkdir -p "$t" || exit 1
trap 'rm -rf "$t"' EXIT
ok() { echo "PASS $1"; }
no() { echo "FAIL $1"; fails=$((fails + 1)); }
# out NAME EXPECTED-FILE: the run that just happened exited 0 and wrote
# exactly that file (echo(1) writes its operands and nothing else)
out() {
st=$?
if [ "$st" -ne 0 ]; then no "$1"; return; fi
if cmp -s "$2" "$t/out"; then ok "$1"; else no "$1"; fi
}
# echo(1): operands, separated by single blanks, followed by a newline
printf 'a b c\n' > "$t/exp"
$e a b c > "$t/out" 2> "$t/err"
out operands "$t/exp"
# echo(1): no operands -- just the newline
printf '\n' > "$t/exp"
$e > "$t/out" 2> "$t/err"
out no-operands "$t/exp"
# echo(1) -n: "Do not print the trailing newline character"
printf 'a b' > "$t/exp"
$e -n a b > "$t/out" 2> "$t/err"
out n-flag "$t/exp"
# echo(1): -n is the only option -- -e is written like any other string and
# a backslash is not an escape
printf '%s\n' '-e a\tb' > "$t/exp"
$e -e 'a\tb' > "$t/out" 2> "$t/err"
out no-other-options "$t/exp"
# ... and it counts only in the first position: after an operand, -n is a
# string too
printf 'a -n\n' > "$t/exp"
$e a -n > "$t/out" 2> "$t/err"
out n-only-in-first-position "$t/exp"
echo "echo: $fails failed"
[ "$fails" -eq 0 ]