mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Converted all ASCII tabs to ASCII spaces using a 8 character tab stop, for all files, except for all Makefiles (plus rpm.mk). The `git diff -w` reports no changes.
208 lines
6.8 KiB
Plaintext
208 lines
6.8 KiB
Plaintext
/*
|
|
* dotest - test truth statements found in line tests of dotest_testline file
|
|
*
|
|
* This file was created by Ernest Bowen <ebowen at une dot edu dot au>
|
|
* and modified by Landon Curt Noll.
|
|
*
|
|
* This file is not covered under version 2.1 of the GNU LGPL.
|
|
* This file is covered under "The unlicense":
|
|
*
|
|
* https://unlicense.org
|
|
*
|
|
* In particular:
|
|
*
|
|
* This is free and unencumbered software released into the public domain.
|
|
*
|
|
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
* distribute this software, either in source code form or as a compiled
|
|
* binary, for any purpose, commercial or non-commercial, and by any
|
|
* means.
|
|
*
|
|
* In jurisdictions that recognize copyright laws, the author or authors
|
|
* of this software dedicate any and all copyright interest in the
|
|
* software to the public domain. We make this dedication for the benefit
|
|
* of the public at large and to the detriment of our heirs and
|
|
* successors. We intend this dedication to be an overt act of
|
|
* relinquishment in perpetuity of all present and future rights to this
|
|
* software under copyright law.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* For more information, please refer to <http://unlicense.org/>
|
|
*
|
|
* Under source dotest_code control: 2006/03/08 05:54:09
|
|
* File existed as early as: 2006
|
|
*/
|
|
|
|
|
|
/*
|
|
* dotest - perform tests from dotest_testline file
|
|
*
|
|
* given:
|
|
* dotest_file filename containing single test lines
|
|
* dotest_code regress.cal test number to use (def: 0)
|
|
* dotest_maxcond max error conditions allowed (def: <0 ==> 2^31-1)
|
|
*
|
|
* returns:
|
|
* number of line test failures
|
|
*
|
|
* NOTE: All variables used by the dotest() function start with "dotest_".
|
|
* The dotest_file and dotest_read should not use any variable
|
|
* that starts with "dotest_".
|
|
*/
|
|
define dotest(dotest_file, dotest_code = 0, dotest_maxcond = -1)
|
|
{
|
|
local dotest_f_file; /* open file containing test lines */
|
|
local dotest_testline; /* test line */
|
|
local dotest_testeval; /* eval value from dotest_testline test line */
|
|
local dotest_tmperrcnt; /* temp error count after line test */
|
|
local dotest_errcnt; /* total number of errors */
|
|
local dotest_failcnt; /* number of line tests failed */
|
|
local dotest_testnum; /* number of test lines evaluated */
|
|
local dotest_linenum; /* test line number */
|
|
local dotest_old_errmax; /* value of errmax() prior to calling */
|
|
local dotest_old_errcount; /* value of errcount() prior to calling */
|
|
|
|
/*
|
|
* preserve calling stats
|
|
*/
|
|
dotest_old_errmax = errmax();
|
|
dotest_old_errcount = errcount(0);
|
|
|
|
/*
|
|
* initialize test accounting
|
|
*/
|
|
dotest_errcnt = errcount();
|
|
dotest_failcnt = 0;
|
|
dotest_testnum = 0;
|
|
dotest_linenum = 0;
|
|
|
|
/*
|
|
* setup error accounting for dotest
|
|
*/
|
|
if (dotest_maxcond >= 0 && dotest_maxcond < 2147483647) {
|
|
errmax(dotest_maxcond + dotest_old_errcount + 1),;
|
|
} else {
|
|
errmax(2147483647),;
|
|
}
|
|
|
|
/*
|
|
* open the test line file
|
|
*/
|
|
printf("%d-: opening line file: %d", dotest_code, dotest_file);
|
|
dotest_f_file = fpathopen(dotest_file, "r");
|
|
if (!isfile(dotest_f_file)) {
|
|
printf("**** Unable to file or open file \"%s\"\n",
|
|
dotest_file);
|
|
quit;
|
|
}
|
|
printf('%d: testing "%s"\n', dotest_code, dotest_file);
|
|
|
|
/*
|
|
* perform dotest_testline test on each line of the file
|
|
*/
|
|
for (;;) {
|
|
|
|
/* get the next test line */
|
|
dotest_testline = fgets(dotest_f_file);
|
|
++dotest_linenum;
|
|
if (iserror(dotest_testline)) {
|
|
quit "**** Error while reading file";
|
|
} else if (isnull(dotest_testline)) {
|
|
/* EOF - end of test file */
|
|
break;
|
|
}
|
|
|
|
/* skip empty lines */
|
|
if (dotest_testline == "\n") {
|
|
continue;
|
|
}
|
|
|
|
/* evaluate the test line */
|
|
dotest_testeval = eval(dotest_testline);
|
|
|
|
/* ignore white space or comment lines */
|
|
if (isnull(dotest_testeval)) {
|
|
continue;
|
|
}
|
|
|
|
/* look for test line parse errors */
|
|
if (iserror(dotest_testeval)) {
|
|
printf("**** evaluation error: ");
|
|
++dotest_failcnt;
|
|
|
|
/* look for test line dotest_failcnt */
|
|
} else if (dotest_testeval != 1) {
|
|
printf("**** did not return 1: ");
|
|
++dotest_failcnt;
|
|
}
|
|
|
|
/* show the test line we just performed */
|
|
printf("%d-%d: %s", dotest_code, dotest_linenum, dotest_testline);
|
|
|
|
/* error accounting */
|
|
dotest_tmperrcnt = errcount() - dotest_errcnt;
|
|
if (dotest_tmperrcnt > 0) {
|
|
|
|
/* report any other errors */
|
|
if (dotest_tmperrcnt > 1) {
|
|
printf("%d-%d: NOTE: %d error conditions(s): %s\n",
|
|
dotest_code, dotest_linenum, dotest_tmperrcnt);
|
|
}
|
|
|
|
/* report the calc error string */
|
|
printf("%d-%d: NOTE: last error string: %s\n",
|
|
dotest_code, dotest_linenum, strerror());
|
|
|
|
/* new error count level */
|
|
dotest_errcnt = errcount();
|
|
if (dotest_maxcond >= 0 &&
|
|
dotest_old_errcount-dotest_errcnt > dotest_maxcond) {
|
|
printf("%d-%d: total error conditions: %d > %d\n",
|
|
dotest_code, dotest_linenum,
|
|
dotest_maxcond, dotest_old_errcount-dotest_errcnt);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* test the close of the line file
|
|
*/
|
|
printf("%d-: detected %d error condition(s), many of which may be OK\n",
|
|
dotest_code, dotest_old_errcount-dotest_errcnt);
|
|
printf("%d-: closing line file: %d\n", dotest_code, dotest_file);
|
|
fclose(dotest_f_file);
|
|
|
|
/*
|
|
* test line file accounting
|
|
*/
|
|
if (dotest_failcnt > 0) {
|
|
printf("**** %d-: %d test failure(s) in %d line(s)\n",
|
|
dotest_code, dotest_failcnt, dotest_linenum);
|
|
} else {
|
|
printf("%d-: no failure(s) in %d line(s)\n",
|
|
dotest_code, dotest_linenum);
|
|
}
|
|
|
|
/*
|
|
* prepare to return to the caller environment
|
|
*
|
|
* We increase the caller's error count by the number
|
|
* of line tests that failed, not the number of internal
|
|
* errors that were noted.
|
|
*/
|
|
errmax(dotest_old_errmax),;
|
|
errcount(dotest_old_errcount + dotest_failcnt),;
|
|
|
|
/*
|
|
* All Done!!! -- Jessica Noll, Age 2
|
|
*/
|
|
return dotest_failcnt;
|
|
}
|