2 * dotest - test truth statements found in line tests of dotest_testline file
4 * This file was created by Ernest Bowen <ebowen at une dot edu dot au>
5 * and modified by Landon Curt Noll.
7 * This dotest_code has been placed in the public domain. Please do not
8 * copyright this dotest_code.
10 * ERNEST BOWEN AND LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO
11 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MER-
12 * CHANTABILITY AND FITNESS. IN NO EVENT SHALL LANDON CURT
13 * NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
15 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 * @(#) $Revision: 30.2 $
20 * @(#) $Id: dotest.cal,v 30.2 2007/03/16 11:09:54 chongo Exp $
21 * @(#) $Source: /usr/local/src/bin/calc/cal/RCS/dotest.cal,v $
23 * This file is not covered under version 2.1 of the GNU LGPL.
25 * Under source dotest_code control: 2006/03/08 05:54:09
26 * File existed as early as: 2006
31 * dotest - perform tests from dotest_testline file
34 * dotest_file filename containing single test lines
35 * dotest_code regress.cal test number to use (def: 0)
36 * dotest_maxcond max error conditions allowed (def: <0 ==> 2^31-1)
39 * number of line test failures
41 * NOTE: All variables used by the dotest() function start with "dotest_".
42 * The dotest_file and dotest_read should not use any variable
43 * that starts with "dotest_".
45 define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1)
47 local dotest_f_file; /* open file containing test lines */
48 local dotest_testline; /* test line */
49 local dotest_testeval; /* eval value from dotest_testline test line */
50 local dotest_tmperrcnt; /* temp error count after line test */
51 local dotest_errcnt; /* total number of errors */
52 local dotest_failcnt; /* number of line tests failed */
53 local dotest_testnum; /* number of test lines evaluated */
54 local dotest_linenum; /* test line number */
55 local dotest_old_errmax; /* value of errmax() prior to calling */
56 local dotest_old_errcount; /* value of errcount() prior to calling */
59 * preserve calling stats
61 dotest_old_errmax = errmax();
62 dotest_old_errcount = errcount(0);
65 * initialize test accounting
67 dotest_errcnt = errcount();
73 * setup error accounting for dotest
75 if (dotest_maxcond >= 0 && dotest_maxcond < 2147483647) {
76 errmax(dotest_maxcond + dotest_old_errcount + 1),;
82 * open the test line file
84 printf("%d-: opening line file: %d", dotest_code, dotest_file);
85 dotest_f_file = fpathopen(dotest_file, "r");
86 if (!isfile(dotest_f_file)) {
87 printf("**** Unable to file or open file \"%s\"\n",
91 printf('%d: testing "%s"\n', dotest_code, dotest_file);
94 * perform dotest_testline test on each line of the file
98 /* get the next test line */
99 dotest_testline = fgets(dotest_f_file);
101 if (iserror(dotest_testline)) {
102 quit "**** Error while reading file";
103 } else if (isnull(dotest_testline)) {
104 /* EOF - end of test file */
108 /* skip empty lines */
109 if (dotest_testline == "\n") {
113 /* evaluate the test line */
114 dotest_testeval = eval(dotest_testline);
116 /* ignore white space or comment lines */
117 if (isnull(dotest_testeval)) {
121 /* look for test line parse errors */
122 if (iserror(dotest_testeval)) {
123 printf("**** evaluation error: ");
126 /* look for test line dotest_failcnt */
127 } else if (dotest_testeval != 1) {
128 printf("**** did not return 1: ");
132 /* show the test line we just performed */
133 printf("%d-%d: %s", dotest_code, dotest_linenum, dotest_testline);
135 /* error accounting */
136 dotest_tmperrcnt = errcount() - dotest_errcnt;
137 if (dotest_tmperrcnt > 0) {
139 /* report any other errors */
140 if (dotest_tmperrcnt > 1) {
141 printf("%d-%d: NOTE: %d error conditions(s): %s\n",
142 dotest_code, dotest_linenum, dotest_tmperrcnt);
145 /* report the calc error string */
146 printf("%d-%d: NOTE: last error string: %s\n",
147 dotest_code, dotest_linenum, strerror());
149 /* new error count level */
150 dotest_errcnt = errcount();
151 if (dotest_maxcond >= 0 &&
152 dotest_old_errcount-dotest_errcnt > dotest_maxcond) {
153 printf("%d-%d: total error conditions: %d > %d\n",
154 dotest_code, dotest_linenum,
155 dotest_maxcond, dotest_old_errcount-dotest_errcnt);
161 * test the close of the line file
163 printf("%d-: detected %d error condition(s), many of which may be OK\n",
164 dotest_code, dotest_old_errcount-dotest_errcnt);
165 printf("%d-: closing line file: %d\n", dotest_code, dotest_file);
166 fclose(dotest_f_file);
169 * test line file accounting
171 if (dotest_failcnt > 0) {
172 printf("**** %d-: %d test failure(s) in %d line(s)\n",
173 dotest_code, dotest_failcnt, dotest_linenum);
175 printf("%d-: no failure(s) in %d line(s)\n",
176 dotest_code, dotest_linenum);
180 * preppare to return to the caller environment
182 * We increase the caller's error count by the number
183 * of line tests that failed, not the number of internal
184 * errors that were noted.
186 errmax(dotest_old_errmax),;
187 errcount(dotest_old_errcount + dotest_failcnt),;
190 * All Done!!! -- Jessica Noll, Age 2
192 return dotest_failcnt;