2
2
3
3
# Confirm that PBM_TESTPREFIX is set.
4
4
# PBM_TESTPREFIX is the directory with the Netpbm programs you want to
5
- # test. This can be null, but this is not recommended.
5
+ # test. If set to null, executables will be sought from the default
6
+ # execution path ($PATH). Usually you should explicitly set this.
6
7
#
7
- # You can set it here by decommenting and modifying the next line:
8
- # export PBM_TESTPREFIX="/usr/local/bin/"
9
-
8
+ # You can set it here by de-commenting and modifying the next line:
9
+ # export PBM_TESTPREFIX="/usr/local/bin/"
10
10
11
11
if [ -z $PBM_TESTPREFIX ]
12
12
then
@@ -20,7 +20,7 @@ elif [ ! -d $PBM_TESTPREFIX ]
20
20
exit 1
21
21
else
22
22
# append "/" to end of string if necessary
23
- export PBM_TESTPREFIX=` echo $PBM_TESTPREFIX | sed ' /\/$/!s@$@/@' `
23
+ export PBM_TESTPREFIX=$( echo $PBM_TESTPREFIX | sed ' /\/$/!s@$@/@' )
24
24
fi
25
25
26
26
# Set PBM_BINPREFIX.
30
30
#
31
31
# If testing a fresh install, this should be the same as PBM_TESTPREFIX.
32
32
# If you are developing a single Netpbm program, you may want to
33
- # set this to a directory with stable executables.
33
+ # set this to a directory with stable executables. (Final "/" is
34
+ # mandatory.)
34
35
# If set to null, executables in the default execution path will
35
36
# be used.
36
37
@@ -47,67 +48,132 @@ if [ ! -z $PBM_BINPREFIX ]
47
48
export PATH=${PBM_BINPREFIX} :$PATH
48
49
fi
49
50
50
- # Set tmpdir, which is used in some of the test scripts.
51
- # This must be an existing directory.
51
+ # Set srcdir, which is the directory which contains Execute-Tests
52
+ # (this script), Test-Order *.test and *.ok files.
53
+
54
+ srcdir=$( dirname $0 )
55
+
56
+ # Set tmpdir, which is used in some of the test scripts. By default
57
+ # this is created by mktemp. The user can override and specify tmpdir,
58
+ # but in this case it must be an existing directory and must not be
59
+ # either $srcdir or current work.
52
60
53
61
if [ -z $tmpdir ]
54
62
then
55
- if [ -z $TMPDIR ]
56
- then
57
- export tmpdir=/tmp/
58
- else
59
- export tmpdir=$TMPDIR
63
+ tmpdir_created=$( mktemp -p " " -d TestPBM-XXXXXXX) || exit 1;
64
+ export tmpdir=${tmpdir_created}
65
+ else
66
+ tmpdir_created=" " ;
67
+ if [ ! -d ${tmpdir} ]
68
+ then echo " Specified temporary directory $tmpdir does not exist."
69
+ exit 1;
70
+ elif [ ${tmpdir} -ef ${srcdir} ]
71
+ then echo " Temporary directory must not be $srcdir ."
72
+ exit 1;
73
+ elif [ ${tmpdir} -ef $PWD ]
74
+ then echo " Temporary directory must not be current directory."
75
+ exit 1;
60
76
fi
61
77
fi
62
78
79
+
63
80
# If necessary set the RGBDEF environment variable.
64
81
# export RGBDEF=/etc/rgb.txt
65
82
# export RGBDEF=/usr/local/netpbm/lib/rgb.txt
66
83
# export RGBDEF=/usr/share/emacs/*/etc/rgb.txt
67
84
68
85
# Declare arrays used to count and report test results.
69
86
# For now only "SUCCESS" and "FAILURE" are used.
70
- declare -a array=(0 0 0 0 0)
71
- declare -a status=(" SUCCESS" " FAILURE" " UNEXPECTED SUCCESS" \
72
- " EXPECTED FAILURE" " NOT SUPPORTED" )
87
+ declare -a array=(0 0 0 0 0 0)
88
+ declare -a status=(" SUCCESS" " FAILURE" " UNEXPECTED SUCCESS"
89
+ " EXPECTED FAILURE" " NOT SUPPORTED" " TOTAL SUPPORTED" )
90
+
91
+ # Copy test files to the current work directory
92
+
93
+ cp -n -t . ${srcdir} /testgrid.pbm ${srcdir} /testimg.ppm
73
94
74
95
# Execute the tests, as described in the "Test-Order" file.
75
96
#
76
- # To execute just one test, or a few tests, replace the grep part
77
- # within backquotes with names of tests you want to run like this:
78
- #
79
- # for t in pbmmake.test pgmmake.test ppmmake.test
97
+ # Each test outputs a ".out" file, which is compared against a
98
+ # corresponding ".ok" file. For example the output from "pbmmake.test"
99
+ # is "pbmmake.out" and when this matches "pbmmake.ok" we declare the
100
+ # test a success.
101
+ # In the error case the ".out" file is retained in the current work
102
+ # directory.
103
+ #
104
+ # All tests are self-contained.
105
+ #
106
+ # By defeault the tests are executed in the order described in the
107
+ # file Test-Order. Normally the Test-Order in the source directory
108
+ # will be used, but the user can override this with a file named
109
+ # Test-Order placed in the work directory. (This feature comes useful
110
+ # when you want to pare down the list.)
111
+
112
+ if [ ! -f ./Test-Order ]
113
+ then cp ${srcdir} /Test-Order ./Test-Order
114
+ fi
80
115
81
- for t in ` grep -v " ^#" Test-Order | grep " ." `
116
+ for t in ` grep -v " ^#" ./ Test-Order | fgrep " .test " `
82
117
do
83
118
echo == $t ==
84
- . /$t > ${t% .test} .out ; let result=$?
119
+ ${srcdir} /$t > ${t% .test} .out ; let result=$?
85
120
case $result in
86
- 0) cmp --quiet ${t% .test} .out ${t% .test} .ok ;
121
+ 0) cmp --quiet ${t% .test} .out ${srcdir} / ${ t% .test} .ok ;
87
122
if [ $? -eq 0 ]
88
123
then let result=0; rm ${t% .test} .out ;
89
124
else let result=1;
90
- fi ;;
91
- 1 | 2 | 3 ) ;;
92
- * ) let result=1 ;;
125
+ fi
126
+ let supported=1 ;;
127
+ * ) let result=1 ; let supported=1; ;
93
128
esac
94
129
95
- # Print out a summary report.
130
+
131
+ # Report whether a single test succeeded or failed.
132
+ # Increment counters.
96
133
97
134
echo $t : ${status[${result}]} ; echo
98
135
let array[${result} ]=${array[${result}]} +1
136
+ let array[5]=${array[5]} +$supported
137
+
99
138
done
100
139
140
+
141
+ # Erase temporary directory and its contents, if it was created.
142
+
143
+ if [ -n $tmpdir_created ]
144
+ then rm -rf $tmpdir_created
145
+ fi
146
+
147
+
148
+ # Erase test image files in the current (work) directory.
149
+ # (Do not erase them if we are working from the source directory.)
150
+
151
+ if [ ! $PWD -ef ${srcdir} ]
152
+ then rm ./testimg.ppm ./testgrid.pbm
153
+ fi
154
+
155
+
156
+ # Calculate success / failure totals and print a summary report.
157
+ # Report date and time of completion.
158
+
101
159
echo " Test summary:"
102
160
echo ==================
103
161
104
- for s in 0 1 2 3 4
105
- do
106
- if [[ ${array[${s}]} -gt 0 || s -eq 1 ]]
107
- then
108
- echo ${status[${s}]} ${array[${s}]}
109
- fi
110
- done
162
+ for s in 0 1 2 3 4 5
163
+ do
164
+ if [[ ${array[${s}]} -gt 0 || s -eq 1 ]]
165
+ then echo ${status[${s}]} ${array[${s}]}
166
+ fi
167
+ done
111
168
112
169
echo ==================
113
170
echo " All tests done."
171
+ date --rfc-3339=seconds
172
+
173
+
174
+ # Exit with status 0 if all supported tests succeeded, 1 otherwise.
175
+
176
+ if [[ ${array[0]} -eq ${array[5]} ]]
177
+ then exit 0
178
+ else exit 1
179
+ fi
0 commit comments