diff --git a/tests/expire/tombstone-e2e.t b/tests/expire/tombstone-e2e.t index 870b199a6..d52993a4a 100755 --- a/tests/expire/tombstone-e2e.t +++ b/tests/expire/tombstone-e2e.t @@ -20,6 +20,32 @@ printcount() { count=$(expr $count + 1) } +# POSIX-portable helpers: AIX and Solaris native grep(1) lack -F and +# native sed(1) lacks -i, so we avoid both rather than depend on GNU +# tools being installed. + +# contains FILE STRING -- succeed if STRING occurs literally on some line. +contains() { + while read -r _line; do + case "$_line" in + *"$2"*) return 0 ;; + esac + done <"$1" + return 1 +} + +# countlines FILE -- print the number of newline-terminated lines. +countlines() { + wc -l <"$1" | tr -cd '0-9' +} + +# setconf VALUE -- rewrite the expiretombstone setting in the temp inn.conf. +setconf() { + sed "s/^expiretombstone:.*\$/expiretombstone: $1/" \ + "$TMPDIR_E2E/inn.conf" >"$TMPDIR_E2E/inn.conf.new" \ + && mv "$TMPDIR_E2E/inn.conf.new" "$TMPDIR_E2E/inn.conf" +} + # Find the right directory. sm="../../frontends/sm" dirs='../data data tests/data' @@ -82,14 +108,14 @@ fi # 2. Remove it via sm -r. This should append the token to cancels.tombstone. $sm -r "$token1" -if [ -r "$CANCELS" ] && grep -qF "$token1" "$CANCELS"; then +if [ -r "$CANCELS" ] && contains "$CANCELS" "$token1"; then printcount "ok" else printcount "not ok" "cancels.tombstone missing token1" fi # 3. The file format should be exactly one line per cancellation. -lines=$(wc -l <"$CANCELS" | sed -e 's/[ \t]//g') +lines=$(countlines "$CANCELS") if [ "$lines" = 1 ]; then printcount "ok" else @@ -99,9 +125,9 @@ fi # 4. A second cancellation appends, doesn't overwrite. token2=$($sm -s /dev/null 2>&1 -lines=$(wc -l <"$CANCELS" | sed -e 's/[ \t]//g') +lines=$(countlines "$CANCELS") if [ "$lines" = 2 ]; then printcount "ok" else @@ -164,13 +188,13 @@ fi # a fourth article and confirming a clean append. token4=$($sm -s