File: mtest.m

package info (click to toggle)
dynare 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,640 kB
  • sloc: fortran: 82,231; cpp: 72,734; ansic: 28,874; pascal: 13,241; sh: 4,300; objc: 3,281; yacc: 2,833; makefile: 1,288; lex: 1,162; python: 162; lisp: 54; xml: 8
file content (82 lines) | stat: -rw-r--r-- 2,626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function check = mtest(fname,fpath)
% Extract test sections from matlab's routine executes the test and report errors.

% Copyright (C) 2011 Dynare Team
% stephane DOT adjemian AT univ DASH lemans DOT fr
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

% Default answer (no problem).
check = 1;

% Open the matlab file.
fid = fopen([fpath '/' fname '.m'],'r');

% Read the matlab file.
file = textscan(fid,'%s','delimiter','\n');
file = file{1};

% Close the matlab file.
fclose(fid);

% Locate the test blocks.
b1 = find(strncmp(file,'%@test:',7))+1;
b2 = find(strncmp(file,'%@eof:',6))-1;
nn = length(b2);

if length(b1)-length(b2)
    error('test:: There is a problem with the test blocks definition!')
end

% Perform the tests.
for i=1:nn
    % Write the temporary test routine.
    tid = fopen([fname '_test_' int2str(i) '.m'],'w');
    fprintf(tid,['function [T,t,LOG] = ' fname '_test_' int2str(i) '()\n']);
    fprintf(tid,['try\n']);
    for j=b1(i):b2(i)
        str = file{j};
        fprintf(tid,[str(4:end) '\n']);
    end
    fprintf(tid,['LOG = NaN;\n']);
    fprintf(tid,['catch exception\n']);
    fprintf(tid,['LOG = getReport(exception,''extended'');\n']);
    fprintf(tid,['T = NaN;\n']);
    fprintf(tid,['t = NaN;\n']);
    fprintf(tid,['end\n']);
    fclose(tid);
    % Call the temporary test routine.
    [TestFlag,TestDetails,LOG] = feval([fname '_test_' int2str(i)]);
    if isnan(TestFlag)
        fprintf(['\n'])
        fprintf(['Call to ' fname ' test routine n°' int2str(i) ' failed (' datestr(now) ')!\n'])
        fprintf(['\n'])
        disp(LOG)
        check = 0;
        continue
    end
    if ~TestFlag
        fprintf(['Test n°' int2str(i) ' for routine ' fname ' failed (' datestr(now) ')!\n']);
        for j=1:length(TestDetails)
            if ~TestDetails(j)
                fprintf(['Output argument n°' int2str(j) ' didn''t give the expected result.\n']);
            end
        end
        check = 0;
    else
        delete([fname '_test_' int2str(i) '.m'])
    end
end