~willismonroe/ubuntu/precise/xdg-utils/typo-fix-996304

« back to all changes in this revision

Viewing changes to tests/include/testfuncs.sh

  • Committer: Bazaar Package Importer
  • Author(s): Per Olofsson
  • Date: 2006-08-29 17:35:02 UTC
  • Revision ID: james.westby@ubuntu.com-20060829173502-ffe063dqe8ajg2rm
Tags: upstream-1.0~beta3
ImportĀ upstreamĀ versionĀ 1.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
verify_test_context() {
 
2
        if [ -z "$TEST_NAME" -a ! "$USING_TET" ]; then
 
3
                echo "A test context must be established with 'test_start <name>'!"
 
4
                exit 255
 
5
        fi
 
6
}
 
7
 
 
8
## record the test a name.
 
9
test_start () {
 
10
 
 
11
        TEST_NAME="$*"
 
12
        verify_test_context
 
13
        TEST_STATUS=PASS
 
14
                
 
15
        if [ $USING_TET ]; then
 
16
                tet_infoline $TEST_NAME
 
17
                FAIL=N
 
18
        else
 
19
                echo -n "[`date`] $TEST_NAME: "
 
20
        fi
 
21
 
 
22
}
 
23
 
 
24
test_infoline() {
 
25
        verify_test_context
 
26
        FAIL_MESSAGE="$FAIL_MESSAGE\n$*"
 
27
        if [ "$USING_TET" ] ; then
 
28
                tet_infoline $*
 
29
        fi
 
30
}
 
31
 
 
32
test_fail() {
 
33
        FAIL=Y
 
34
        TEST_STATUS=FAIL
 
35
        test_infoline $*
 
36
}
 
37
 
 
38
## provide a nice way to document the test purpose
 
39
test_purpose() {
 
40
        verify_test_context
 
41
        # TODO: generate a manpage or something.
 
42
}
 
43
test_note() {
 
44
        verify_test_context
 
45
        # TODO: generate even more docs.
 
46
}
 
47
 
 
48
## Used for setup/dependency verification.
 
49
test_init() {
 
50
        verify_test_context
 
51
}
 
52
 
 
53
test_status() {
 
54
        TEST_STATUS="$1"
 
55
        test_infoline "$2"
 
56
}
 
57
 
 
58
## Called after test_init()
 
59
test_procedure() {
 
60
        verify_test_context
 
61
        ## Make sure nothing screwed up in initilization
 
62
        if [ "$TEST_STATUS" != "PASS" ]; then
 
63
                # Something failed before we could get to the test.
 
64
                FAIL=N
 
65
                test_result NORESULT "Initilization failed!"
 
66
        fi
 
67
}
 
68
 
 
69
## Must be within test_procedure
 
70
test_failoverride() {
 
71
        STAT=${1-WARN}
 
72
        if [ "$TEST_STATUS" == FAIL ] ; then
 
73
                FAIL=N
 
74
                test_status "$STAT"
 
75
        fi
 
76
}
 
77
        
 
78
## Report the test's result.
 
79
test_result() {
 
80
        verify_test_context
 
81
 
 
82
        # Set status appropriately
 
83
        if [ ! -z "$1" ]; then
 
84
                TEST_STATUS=$1
 
85
                # account for TET
 
86
                if [ "$TEST_STATUS" = "FAIL" ] ; then 
 
87
                        FAIL=Y
 
88
                fi
 
89
        fi
 
90
        # if we have a message, save it
 
91
        if [ ! -z "$2" ]; then
 
92
                test_infoline $2
 
93
        fi
 
94
        if [ "$USING_TET" ]; then
 
95
                tet_result $TEST_STATUS
 
96
        fi
 
97
        # not using tet, so print nice explanation
 
98
 
 
99
                [ -z "$USING_TET" ] && echo -n "$TEST_STATUS"
 
100
 
 
101
                ## Result codes MUST agree with tet_codes
 
102
                ## for LSB/tet integration.
 
103
                case "$TEST_STATUS" in
 
104
                PASS )  RESULT=0
 
105
                        ;;
 
106
                FAIL )  RESULT=1
 
107
                        [ -z "$USING_TET" ] && echo -ne " $FAIL_MESSAGE"
 
108
                        ;;
 
109
                UNTESTED ) RESULT=5
 
110
                        [ -z "$USING_TET" ] && echo -ne " $FAIL_MESSAGE" 
 
111
                        ;;
 
112
                NORESULT ) RESULT=7
 
113
                        [ -z "$USING_TET" ] && echo -ne " $FAIL_MESSAGE"
 
114
                        ;;
 
115
                WARN ) RESULT=10
 
116
                        [ -z "$USING_TET" ] && echo -ne " $FAIL_MESSAGE"
 
117
                        ;;
 
118
                *)      RESULT=1
 
119
                        [ -z "$USING_TET" ] && echo -ne " - UNKNOWN STATUS\n$FAIL_MESSAGE"
 
120
                        ;;
 
121
                esac
 
122
        #fi
 
123
        [ -z "$USING_TET" ] && echo ""
 
124
        exit "$RESULT"
 
125
}
 
126
 
 
127
use_file() {
 
128
        src="$1"
 
129
        file=${src##/*/}
 
130
        varname="$2"
 
131
 
 
132
        if [ $# -lt 2 ] ; then
 
133
                echo "TEST SYNTAX ERROR: use_file must have two arguments" >&2
 
134
                exit 255 
 
135
        fi
 
136
 
 
137
        assert_file "$src"
 
138
 
 
139
        outfile="xdgtestdata-$XDG_TEST_ID-$file"
 
140
        eval "$varname=$outfile"
 
141
        
 
142
        cp "$src" "$XDG_TEST_TMPDIR/$outfile"
 
143
}
 
144
 
 
145
get_unique_name() {
 
146
        varname="$1"
 
147
        file="$2"
 
148
        if [ -z "$varname" ] ; then
 
149
                echo "TEST SYNAX ERROR: get_unique_name requries a variable name"
 
150
                exit 255
 
151
        fi
 
152
 
 
153
        outfile="xdgtestdata-$XDG_TEST_ID-$file"
 
154
        eval "$varname=$outfile"
 
155
}
 
156
 
 
157
edit_file() {
 
158
        file="$1"
 
159
        origstr="$2"
 
160
        varname="$3"
 
161
        newstr="$4"
 
162
 
 
163
        if [ $# -lt 3 ] ; then
 
164
                echo "TEST SYNTAX ERROR: edit_file must have at least 3 arguments."
 
165
                exit 255
 
166
        fi
 
167
        
 
168
        assert_file "$file"
 
169
 
 
170
        if [ -z "$newstr" ] ; then
 
171
                newstr="xdgtestdata-$XDG_TEST_ID-$origstr"
 
172
        fi
 
173
 
 
174
        eval "$varname=\"$newstr\""
 
175
 
 
176
        sed -i -e "s|$origstr|$newstr|g" "$file"
 
177
}
 
178
 
 
179