#!/usr/bin/env bash # Automated tests for the addrset functions in ncat_hostmatch.c. This # program runs various addresses against different host specifications # and checks that the output is what is expected. ADDRSET=./addrset # Takes as arguments a whitespace-separated list of host specifications # and a space-separated list of expected matching addresses. Tests hosts # are passed in stdin. function test_addrset() { specs=$1 expected=$2 result=$($ADDRSET $specs) ret=$? # Change newlines to spaces. result=$(echo $result) if [ "$ret" != "0" ]; then echo "FAIL $ADDRSET returned $ret." elif [ "$result" != "$expected" ]; then echo "FAIL \"$result\" !=" echo " \"$expected\"." else echo "PASS $specs" fi } # Takes as an argument a host specification with invalid syntax. The # test passes if addrset returns with a non-zero exit code. function expect_fail() { specs=$1 $ADDRSET $specs < /dev/null 2> /dev/null ret=$? if [ "$ret" == "0" ]; then echo "FAIL $ADDRSET $specs was expected to fail, but didn't." else echo "PASS $specs" fi } # seq replacement for systems without seq. function seq() { low=$1 high=$2 while [ $low -le $high ]; do echo $low low=$((low + 1)) done } # No specifications. test_addrset "" "" <