Fixed release creation.
[gnupg.git] / tests / pkits / common.sh
1 # common.sh - common defs for all tests         -*- sh -*-
2 # Copyright (C) 2004, 2008 Free Software Foundation, Inc.
3 #
4 # This file is part of GnuPG.
5
6 # GnuPG is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10
11 # GnuPG is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http://www.gnu.org/licenses/>.
18
19 # reset some environment variables because we do not want to test locals
20 export LANG=C
21 export LANGUAGE=C
22 export LC_ALL=C
23
24
25 [ "$VERBOSE" = yes ] && set -x
26 [ -z "$srcdir" ] && srcdir="."
27 [ -z "$top_srcdir" ] && top_srcdir=".."
28 [ -z "$GPGSM" ] && GPGSM="../../sm/gpgsm"
29 [ -z "$silent" ] && silent=no
30
31 if [ "$GNUPGHOME" != "`pwd`" ]; then
32     echo "inittests: please set GNUPGHOME to the tests/pkits directory" >&2
33     exit 1
34 fi
35
36 if [ -n "$GPG_AGENT_INFO" ]; then
37     echo "inittests: please unset GPG_AGENT_INFO" >&2
38     exit 1
39 fi
40
41 if [ -f PKITS_data.tar.bz2 ]; then
42   :
43 else
44     # Exit code 77 is used by the makefile for skipping a tests.
45     exit 77
46 fi
47
48 #--------------------------------
49 #------ utility functions -------
50 #--------------------------------
51
52 echo_n_init=no
53 echo_n () {
54   if test "$echo_n_init" = "no"; then
55     if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
56       if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
57         echo_n_n=
58         echo_n_c='
59 '
60       else
61         echo_n_n='-n'
62         echo_n_c=
63       fi
64     else
65       echo_n_n=
66       echo_n_c='\c'
67     fi
68     echo_n_init=yes
69   fi
70   echo $echo_n_n "${1}$echo_n_c"
71 }
72
73 setup_output () {
74   if [ -z "$first_section_set" ]; then
75       first_section_set=$section
76   fi
77   section_out="$(echo $section)"
78   if [ -z "$section_out" ]; then
79       section_out="-"
80   fi
81 }
82
83 fatal () {
84     echo "$pgmname: fatal:" $* >&2
85     if [ "$silent" != "yes" ]; then
86         echo "$section_out ERROR: $* (fatal)"
87     fi
88     exit 1;
89 }
90
91 error () {
92     echo "$pgmname:" $* >&2
93     if [ "$silent" != "yes" ]; then
94         echo "$section_out ERROR: $*"
95     fi
96     exit 1
97 }
98
99 info () {
100     setup_output
101     echo "$pgmname:" $* >&2
102     if [ "$silent" != "yes" ]; then
103         echo "$section_out ____ $*"
104     fi
105 }
106
107 info_n () {
108     setup_output
109     echo_n "$pgmname:" $* >&2
110 }
111
112 pass () {
113     setup_output
114     echo "PASS: " $* >&2
115     pass_count=`expr ${pass_count} + 1`
116     if [ "$silent" != "yes" ]; then
117         echo_n "$section_out PASS"
118         [ -n "$description" ] && echo_n " ($description)"
119         echo
120     fi
121 }
122
123 fail () {
124     setup_output
125     echo "FAIL: " $* >&2
126     fail_count=`expr ${fail_count} + 1`
127     if [ "$silent" != "yes" ]; then
128         echo_n "$section_out FAIL"
129         [ -n "$description" ] && echo_n " ($description)"
130         echo
131     fi
132 }
133
134 unresolved () {
135     setup_output
136     echo "UNRESOLVED: " $* >&2
137     unresolved_count=`expr ${unresolved_count} + 1`
138     if [ "$silent" != "yes" ]; then
139         echo_n "$section_out UNRESOLVED"
140         [ -n "$description" ] && echo_n " ($description)"
141         echo
142     fi
143 }
144
145 unsupported () {
146     setup_output
147     echo "UNSUPPORTED: " $* >&2
148     unsupported_count=`expr ${unsupported_count} + 1`
149     if [ "$silent" != "yes" ]; then
150         echo_n "$section_out UNSUPPORTED"
151         [ -n "$description" ] && echo_n " ($description)"
152         echo
153     fi
154 }
155
156
157 final_result () {
158     section=$first_section_set
159     [ $pass_count = 0 ]        || info "$pass_count tests passed"
160     [ $fail_count = 0 ]        || info "$fail_count tests failed"
161     [ $unresolved_count = 0 ]  || info "$unresolved_count tests unresolved"
162     [ $unsupported_count = 0 ] || info "$unsupported_count tests unsupported"
163     if [ $fail_count = 0 ]; then
164         info "all tests passed"
165     else
166         exit 1
167     fi
168 }
169
170 set -e
171
172 pgmname=`basename $0`
173
174 pass_count=0
175 fail_count=0
176 unresolved_count=0
177 unsupported_count=0
178 first_section_set=""
179 section_out=""
180 section=""
181 description=""
182
183 #trap cleanup SIGHUP SIGINT SIGQUIT
184 exec 2> ${pgmname}.log
185
186 :
187 # end