function tuo = testrunnerText(tu,calls)
% TESTRUNNRETEXT Adds callbacks to a testunit to allow its running
%
% This function adds to a testunit the callbacks that generates the output
% of the testing process, in this case the output is an ascii stream on the
% console.
%
% Params
% ------
% IN:
% tu = The testunit or testset to modify or execute.
% calls = Must modify or execute? (def=false=execute)
% Check params:
if nargin<1 error('A testset or testunit is required!'); end
if nargin<2 calls = false; end
% Check the operation type:
if calls
% Check the type of testunit:
switch class(tu)
case 'testunit'
% Adding only the done callback:
tu = addCallback(tu,@TUDispResults,2,true);
case 'testset'
% Adding reset and done local callbacks:
tu = addCallback(tu,@TSDispHead,1,true);
tu = addCallback(tu,@TSDispResults,2,true);
% I've to "runnerize" recursively the sub-tests:
tests = get(tu,'tests');
for ind=1:size(tests,2)
tests{ind} = testrunnerText(tests{ind},calls);
end
% Saving:
tu = set(tu,'tests',tests);
otherwise
error('Only testunit and testset classes are supported!');
end
else
% Run the test:
disp('**********************************************************');
disp('** **');
disp([' Testing process starts at ',datestr(now)]);
disp('**********************************************************');
tu = test(tu);
disp('**********************************************************');
disp([' Testing process ends at ',datestr(now)]);
disp('** **');
disp('**********************************************************');
end
% Returning:
tuo = tu;
% ------------------------ LOCAL FUNCTIONS ------------------------
% Function that displays the result of a test:
function tuo = TUDispResults(tu,event)
% Display the test name and the status:
if get(tu,'status')
% Displaing the result:
disp(sprintf(' %10s: SUCCESS! "%s"', get(tu,'name'), get(tu,'desc')));
else
% Displaing the result:
disp(' *******');
disp(sprintf('*** %7s: FAILURE! "%s"', get(tu,'name'), get(tu,'desc')));
disp(' *******');
% Check the error:
err = get(tu,'err');
if not(strcmp(err,''))
% Display the error:
disp(sprintf('%10s\tlasterr: %s','',err));
end
end
tuo = tu;
% -----------------------------------------------------------------
% Function that displays the heading of a testset:
function tso = TSDispHead(ts,event)
% Display the test name and the status:
disp('==========================================================');
disp([' ' get(ts,'name')]);
disp('----------------------------------------------------------');
tso = ts;
% -----------------------------------------------------------------
% Function that displays the result of a test:
function tso = TSDispResults(ts,event)
% Display the test name and the status:
if get(ts,'status')
result = 'All tests SUCCESSES';
else
result = 'Some tests FAILS';
end
disp('----------------------------------------------------------');
disp(sprintf('%10s: %s!',get(ts,'name'),result));
disp('==========================================================');
tso = ts;