forked from kward/log4sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log4sh_test_priority.sh
executable file
·78 lines (65 loc) · 2.11 KB
/
log4sh_test_priority.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/sh
# $Id$
# vim:et:ft=sh:sts=2:sw=2
#
# Copyright 2008 Kate Ward. All Rights Reserved.
# Released under the LGPL (GNU Lesser General Public License)
# Author: [email protected] (Kate Ward)
#
# log4sh unit test for output of messages based on priority.
# load test helpers
. ./log4sh_test_helpers
APP_NAME='stdout'
TESTDATA="${TH_TESTDATA_DIR}/priority_matrix.dat"
#------------------------------------------------------------------------------
# suite tests
#
testPriorityMatrix()
{
PRIORITY_NAMES='TRACE DEBUG INFO WARN ERROR FATAL'
PRIORITY_POS='1 2 3 4 5 6'
while read priority outputs; do
# ignore comment lines or blank lines
echo "${priority}" |egrep -v '^(#|$)' >/dev/null || continue
${DEBUG} "setting appender priority to '${priority}' priority"
appender_setLevel ${APP_NAME} ${priority}
appender_activateOptions ${APP_NAME}
# the number of outputs must match the number of priority names and
# positions for this to work
for pos in ${PRIORITY_POS}; do
testPriority=`echo ${PRIORITY_NAMES} |cut -d' ' -f${pos}`
shouldOutput=`echo ${outputs} |cut -d' ' -f${pos}`
${DEBUG} "generating '${testPriority}' message"
result=`log ${testPriority} 'dummy'`
${DEBUG} "result=${result}"
if [ ${shouldOutput} -eq 1 ]; then
assertTrue \
"'${priority}' priority appender did not emit a '${testPriority}' message" \
"[ -n \"${result}\" ]"
else
assertFalse \
"'${priority}' priority appender emitted a '${testPriority}' message" \
"[ -n \"${result}\" ]"
fi
done
done <"${TESTDATA}"
}
testInvalidPriority()
{
# validate that requesting an invalid logging level (i.e. priority) will fail
log INVALID 'some message'
assertTrue \
"logging with an invalid logging level did not properly fail" \
"[ $? -eq ${LOG4SH_ERROR} ]"
}
#------------------------------------------------------------------------------
# suite functions
#
oneTimeSetUp()
{
LOG4SH_CONFIGURATION='none'
th_oneTimeSetUp
}
# load and run shUnit2
[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0
. ${TH_SHUNIT}