Browse Source

[trac555] Added shell-based unit test for console appender

Stephen Morris 14 years ago
parent
commit
475624c79f

+ 2 - 0
configure.ac

@@ -891,6 +891,7 @@ AC_OUTPUT([doc/version.ent
            src/lib/dns/tests/testdata/gen-wiredata.py
            src/lib/cc/session_config.h.pre
            src/lib/cc/tests/session_unittests_config.h
+           src/lib/log/tests/console_test.sh
            src/lib/log/tests/run_time_init_test.sh
            src/lib/util/python/mkpywrapper.py
            src/lib/server_common/tests/data_path.h
@@ -919,6 +920,7 @@ AC_OUTPUT([doc/version.ent
            chmod +x src/lib/dns/gen-rdatacode.py
            chmod +x src/lib/dns/tests/testdata/gen-wiredata.py
            chmod +x src/lib/log/tests/run_time_init_test.sh
+           chmod +x src/lib/log/tests/console_test.sh
            chmod +x src/lib/util/python/mkpywrapper.py
            chmod +x tests/system/conf.sh
           ])

+ 2 - 1
src/lib/log/tests/Makefile.am

@@ -46,6 +46,7 @@ logger_support_test_LDADD += $(top_builddir)/src/lib/util/libutil.la
 noinst_PROGRAMS = $(TESTS)
 
 # Additional test using the shell
-PYTESTS = run_time_init_test.sh
+PYTESTS = run_time_init_test.sh console_test.sh
 check-local:
 	$(SHELL) $(abs_builddir)/run_time_init_test.sh
+	$(SHELL) $(abs_builddir)/console_test.sh

+ 63 - 0
src/lib/log/tests/console_test.sh.in

@@ -0,0 +1,63 @@
+#!/bin/sh
+# Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+testname="Console output test"
+echo $testname
+
+failcount=0
+tempfile=@abs_builddir@/console_test_tempfile_$$
+
+# Look at tempfile and check that the count equals the expected count
+passfail() {
+    count=`wc -l $tempfile | cut -f1 -d' '`
+    if [ $count -eq $1 ]; then
+        echo " -- pass"
+    else
+        echo " ** FAIL"
+        failcount=`expr $failcount + $1`
+    fi
+}
+
+echo "1. Checking that console output to stdout goes to stdout:"
+rm -f $tempfile
+./logger_support_test -s error -c stdout 1> $tempfile
+passfail 2
+
+echo "2. Checking that console output to stdout does not go to stderr:"
+rm -f $tempfile
+./logger_support_test -s error -c stdout 2> $tempfile
+passfail 0
+
+echo "3. Checking that console output to stderr goes to stderr:"
+rm -f $tempfile
+./logger_support_test -s error -c stderr 2> $tempfile
+passfail 2
+
+echo "4. Checking that console output to stderr does not go to stdout:"
+rm -f $tempfile
+./logger_support_test -s error -c stderr 1> $tempfile
+passfail 0
+
+rm -f $tempfile
+
+if [ $failcount -eq 0 ]; then
+    echo "PASS: $testname"
+elif [ $failcount -eq 1 ]; then
+    echo "FAIL: $testname - 1 test failed"
+else
+    echo "FAIL: $testname - $failcount tests failed"
+fi
+
+exit $failcount

+ 13 - 10
src/lib/log/tests/run_time_init_test.sh.in

@@ -13,17 +13,20 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
+testname="Run-time initialization test"
+echo $testname
+
 failcount=0
 localmes=@abs_builddir@/localdef_mes_$$
 tempfile=@abs_builddir@/run_time_init_test_tempfile_$$
 
 passfail() {
     if [ $1 -eq 0 ]; then
-        echo "pass"
+        echo " -- pass"
     else
-        echo "FAIL"
+        echo " ** FAIL"
+        failcount=`expr $failcount + $1`
     fi
-    failcount=`expr $failcount + $1`
 }
 
 # Create the local message file for testing
@@ -35,7 +38,7 @@ cat > $localmes << .
 % RDLOCMES    replacement read local message file, parameter is '%1'
 .
 
-echo -n "1. runInitTest default parameters: "
+echo "1. runInitTest default parameters: "
 cat > $tempfile << .
 FATAL [alpha.example] MSG_WRITERR, error writing to test1: 42
 ERROR [alpha.example] MSG_RDLOCMES, reading local message file dummy/file
@@ -45,7 +48,7 @@ INFO  [alpha.dlm] MSG_OPENIN, unable to open message file example.msg for input:
 ./logger_support_test | cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
-echo -n "2. Severity filter: "
+echo "2. Severity filter: "
 cat > $tempfile << .
 FATAL [alpha.example] MSG_WRITERR, error writing to test1: 42
 ERROR [alpha.example] MSG_RDLOCMES, reading local message file dummy/file
@@ -53,7 +56,7 @@ ERROR [alpha.example] MSG_RDLOCMES, reading local message file dummy/file
 ./logger_support_test -s error | cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
-echo -n "3. Debug level: "
+echo "3. Debug level: "
 cat > $tempfile << .
 FATAL [alpha.example] MSG_WRITERR, error writing to test1: 42
 ERROR [alpha.example] MSG_RDLOCMES, reading local message file dummy/file
@@ -66,7 +69,7 @@ DEBUG [alpha.example] MSG_RDLOCMES, reading local message file dummy/25
 ./logger_support_test -s debug -d 25 | cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
-echo -n "4. Local message replacement: "
+echo "4. Local message replacement: "
 cat > $tempfile << .
 WARN  [alpha.log] MSG_IDNOTFND, could not replace message text for 'MSG_NOTHERE': no such message
 FATAL [alpha.example] MSG_WRITERR, error writing to test1: 42
@@ -80,11 +83,11 @@ rm -f $localmes
 rm -f $tempfile
 
 if [ $failcount -eq 0 ]; then
-    echo "PASS: run_time_init_test"
+    echo "PASS: $testname"
 elif [ $failcount -eq 1 ]; then
-    echo "FAIL: run_time_init_test - 1 test failed"
+    echo "FAIL: $testname - 1 test failed"
 else
-    echo "FAIL: run_time_init_test - $failcount tests failed"
+    echo "FAIL: $testname - $failcount tests failed"
 fi
 
 exit $failcount