1#!/bin/ksh 2 3# 4# This file and its contents are supplied under the terms of the 5# Common Development and Distribution License ("CDDL"), version 1.0. 6# You may only use this file in accordance with the terms of version 7# 1.0 of the CDDL. 8# 9# A full copy of the text of the CDDL should have accompanied this 10# source. A copy of the CDDL is also available via the Internet at 11# http://www.illumos.org/license/CDDL. 12# 13 14# Copyright 2022 OmniOS Community Edition (OmniOSce) Association. 15 16set -o errexit 17set -o pipefail 18 19builtin print 20 21typeset -r ROOT=$(dirname $0) 22typeset -ri MAX_VARIANT=5 23 24typeset -i failures=0 25 26function fatal 27{ 28 echo "Test Failed: $@" >&2 29 exit 1 30} 31 32function fail 33{ 34 ((failures++)) 35 echo "FAIL: $*" >&2 36} 37 38function pass 39{ 40 echo "PASS: $*" 41} 42 43function run 44{ 45 typeset key="$1" 46 typeset keyf="$ROOT/data/$key" 47 shift; 48 49 stderr=${ { stdout=$("$@"); } 2>&1; } 50 exit=$? 51 output=${ 52 cat <<- EOM 53 ::STDOUT:: 54 $stdout 55 ::STDERR:: 56 $stderr 57 ::EXIT:: 58 $exit 59 EOM 60 } 61 if [[ -r "$keyf" ]]; then 62 expect=$(<$keyf) 63 else 64 fatal "Data file $keyf is not readable" 65 fi 66 67 if [[ "$expect" != "$output" ]]; then 68 fail "$key" 69 diff -u <(print "$output") <(print "$expect") || true 70 else 71 pass "$key" 72 fi 73} 74 75for v in {0..$MAX_VARIANT}; do 76 ((errcode = 3 + v * 2)) 77 ((exitcode = 4 + v * 2)) 78 key="${v}.${errcode}.${exitcode}" 79 80 # err(3C) family 81 cmd="$ROOT/err -v $v -e $errcode -x $exitcode" 82 run "E.$key" $cmd 83 84 # warn(3C) family 85 cmd="$ROOT/err -v $v -e $errcode" 86 run "W.$key" $cmd 87done 88 89exit $failures 90 91