File nmap-ncat-fail-test-addrset.patch of Package nmap

From: Andreas Stieger <andreas.stieger@gmx.de>
Date: 2012-12-06 18:46:29 +0000
Subject: [PATCH] ncat - make check succeeds despite test failures
References: http://seclists.org/nmap-dev/2012/q4/373
Upstream: merged

For ncat, "make check" succeeds despite test failures. Patch corrects 
ncat/test/test-addrset.sh by exiting the script with a non-zero return value.

$ svn log -r30341:30350 https://svn.nmap.org/nmap/ncat/test/test-addrset.sh
------------------------------------------------------------------------
r30341 | david | 2012-12-05 06:48:15 +0000 (Wed, 05 Dec 2012) | 4 lines

Make test-addrset.sh exit with nonzero status if any tests fail.

Patch by Andreas Stieger.
http://seclists.org/nmap-dev/2012/q4/385
------------------------------------------------------------------------
r30350 | dmiller | 2012-12-06 18:46:29 +0000 (Thu, 06 Dec 2012) | 1 line

Change test-addrset.sh to be POSIX sh compliant
------------------------------------------------------------------------

---
 ncat/test/test-addrset.sh |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

Index: nmap-6.25/ncat/test/test-addrset.sh
===================================================================
--- nmap-6.25.orig/ncat/test/test-addrset.sh	2009-06-14 18:12:56.000000000 +0100
+++ nmap-6.25/ncat/test/test-addrset.sh	2012-12-08 13:29:30.000000000 +0000
@@ -1,46 +1,56 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 # 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
+TESTS=0
+TEST_PASS=0
+TEST_FAIL=0
 
 # 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() {
+test_addrset() {
 	specs=$1
 	expected=$2
 	result=$($ADDRSET $specs)
 	ret=$?
 	# Change newlines to spaces.
 	result=$(echo $result)
+	TESTS=$((TESTS + 1));
 	if [ "$ret" != "0" ]; then
 		echo "FAIL $ADDRSET returned $ret."
+		TEST_FAIL=$((TEST_FAIL + 1))
 	elif [ "$result" != "$expected" ]; then
 		echo "FAIL \"$result\" !="
 		echo "     \"$expected\"."
+		TEST_FAIL=$((TEST_FAIL + 1))
 	else
 		echo "PASS $specs"
+		TEST_PASS=$((TEST_PASS + 1))
 	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() {
+expect_fail() {
 	specs=$1
 	$ADDRSET $specs < /dev/null 2> /dev/null
 	ret=$?
-	if [ "$ret" == "0" ]; then
+	TESTS=$((TESTS + 1))
+	if [ "$ret" = "0" ]; then
 		echo "FAIL $ADDRSET $specs was expected to fail, but didn't."
+		TEST_FAIL=$((TEST_FAIL + 1))
 	else
 		echo "PASS $specs"
+		TEST_PASS=$((TEST_PASS + 1))
 	fi
 }
 
 # seq replacement for systems without seq.
-function seq() {
+seq() {
 	low=$1
 	high=$2
 	while [ $low -le $high ]; do
@@ -296,3 +306,9 @@ expect_fail "FF::FF/129"
 # 1.2.0.3
 # 1.2.3.4
 # EOF
+
+if [ "$TEST_FAIL" -gt 0 ]; then
+	echo "$TEST_PASS / $TESTS passed, $TEST_FAIL failed"
+	exit 1
+fi
+echo "$TEST_PASS / $TESTS passed"
openSUSE Build Service is sponsored by