0001 function check = mtest(fname,fpath)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 check = 1;
0024
0025
0026 fid = fopen([fpath '/' fname '.m'],'r');
0027
0028
0029 file = textscan(fid,'%s','delimiter','\n');
0030 file = file{1};
0031
0032
0033 fclose(fid);
0034
0035
0036 b1 = find(strncmp(file,'%@test:',7))+1;
0037 b2 = find(strncmp(file,'%@eof:',6))-1;
0038 nn = length(b2);
0039
0040 if length(b1)-length(b2)
0041 error('test:: There is a problem with the test blocks definition!')
0042 end
0043
0044
0045 for i=1:nn
0046
0047 tid = fopen([fname '_test_' int2str(i) '.m'],'w');
0048 fprintf(tid,['function [T,t,LOG] = ' fname '_test_' int2str(i) '()\n']);
0049 fprintf(tid,['try\n']);
0050 for j=b1(i):b2(i)
0051 str = file{j};
0052 fprintf(tid,[str(4:end) '\n']);
0053 end
0054 fprintf(tid,['LOG = NaN;\n']);
0055 fprintf(tid,['catch exception\n']);
0056 fprintf(tid,['LOG = getReport(exception,''extended'');\n']);
0057 fprintf(tid,['T = NaN;\n']);
0058 fprintf(tid,['t = NaN;\n']);
0059 fprintf(tid,['end\n']);
0060 fclose(tid);
0061
0062 [TestFlag,TestDetails,LOG] = feval([fname '_test_' int2str(i)]);
0063 if isnan(TestFlag)
0064 fprintf(['\n'])
0065 fprintf(['Call to ' fname ' test routine n°' int2str(i) ' failed (' datestr(now) ')!\n'])
0066 fprintf(['\n'])
0067 disp(LOG)
0068 check = 0;
0069 continue
0070 end
0071 if ~TestFlag
0072 fprintf(['Test n°' int2str(i) ' for routine ' fname ' failed (' datestr(now) ')!\n']);
0073 for j=1:length(TestDetails)
0074 if ~TestDetails(j)
0075 fprintf(['Output argument n°' int2str(j) ' didn''t give the expected result.\n']);
0076 end
0077 end
0078 check = 0;
0079 else
0080 delete([fname '_test_' int2str(i) '.m'])
0081 end
0082 end