DIRECTORY Commander, IO, ProcessProps, RefText, RegressUtils;
RegressUtilsImpl: CEDAR PROGRAM
IMPORTS Commander, IO, ProcessProps, RefText
EXPORTS RegressUtils
= BEGIN
STREAM: TYPE = IO.STREAM;
testRunning: REF TEXTNIL;
errorStop: BOOLFALSE;
ProcList: TYPE = LIST OF ProcEntry;
procList: ProcList ← NIL;
procListTail: ProcList ← NIL;
ProcEntry: TYPE = RECORD [name: REF TEXT, proc: PROC];
testsRun: INT ← 0;
testsFailed: INT ← 0;
Val: PUBLIC PROC [val: NAT] RETURNS [NAT] = {
RETURN [val];
};
SetErrorStop: PUBLIC PROC [bool: BOOL] = {
errorStop ← bool;
};
Register: PUBLIC PROC [name: REF TEXT, proc: PROC] = {
new: ProcList ← LIST[[name, proc]];
IF name = NIL THEN ERROR;
IF proc = NIL THEN ERROR;
IF procListTail = NIL THEN procList ← new ELSE procListTail.rest ← new;
procListTail ← new;
};
NoteProc: PUBLIC PROC [name: REF TEXT] = {
testRunning ← name;
};
Test: PUBLIC PROC [failed: BOOL, why: REF TEXT] = {
testsRun ← testsRun + 1;
IF failed THEN {
st: STREAM = NARROW[ProcessProps.GetProp[$StdOut]];
IO.PutF1[st, "** %g ** ", [text[testRunning]] ];
IF why # NIL THEN IO.PutText[st, why];
IO.PutChar[st, '\n];
testsFailed ← testsFailed + 1;
IF errorStop THEN ERROR;
};
};
RunMatchingTests: PUBLIC PROC [pattern: REF TEXT] = {
st: STREAM = NARROW[ProcessProps.GetProp[$StdOut]];
modules: INT ← 0;
testsRun ← 0;
testsFailed ← 0;
FOR each: ProcList ← procList, each.rest WHILE each # NIL DO
name: REF TEXT = each.first.name;
proc: PROC = each.first.proc;
IF RefText.Match[pattern, name, FALSE] THEN {
modules ← modules + 1;
IO.PutF1[st, "-- %g\n", [text[name]] ];
testRunning ← name;
proc[];
};
ENDLOOP;
IO.PutF[st, "-- modules: %g, tests run: %g, tests failed: %g\n",
[integer[modules]], [integer[testsRun]], [integer[testsFailed]] ];
testRunning ← NIL;
};
RegressCmd: Commander.CommandProc = {
RunMatchingTests["*"];
};
Commander.Register["Regress", RegressCmd, "runs registered regression tests"];
END.