tutorials_test

PURPOSE ^

TUTORIAL_TEST: Run all tutorials

SYNOPSIS ^

function [errors warnings] = tutorials_test(directory,tcount)

DESCRIPTION ^

 TUTORIAL_TEST: Run all tutorials
 [errors, warnings] = tutorial_test(directory) will run all *.m files in 
 the specified directory (../../htdocs/tutorial/ if omitted). The status
 of each file will be printed to the screen as well as in a
 tutorial_status.txt file in the current directory (using the diary
 functionality). Delete tutorial_status.txt between succesive calls to
 avoid appending. 
 OUTPUTS: 
  errors -- a cell array containing the files that caused errors
            (including the directory and the first error message)
 warnings -- a cell array containing the files that caused warnings 
            (including directories)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [errors warnings] = tutorials_test(directory,tcount)
0002 % TUTORIAL_TEST: Run all tutorials
0003 % [errors, warnings] = tutorial_test(directory) will run all *.m files in
0004 % the specified directory (../../htdocs/tutorial/ if omitted). The status
0005 % of each file will be printed to the screen as well as in a
0006 % tutorial_status.txt file in the current directory (using the diary
0007 % functionality). Delete tutorial_status.txt between succesive calls to
0008 % avoid appending.
0009 % OUTPUTS:
0010 %  errors -- a cell array containing the files that caused errors
0011 %            (including the directory and the first error message)
0012 % warnings -- a cell array containing the files that caused warnings
0013 %            (including directories)
0014 
0015 % (C) 2011 Bartlomiej Grychtol. License: GPL version 2 or version 3
0016 % $Id: tutorials_test.m 4535 2014-04-28 00:56:46Z bgrychtol $
0017 
0018 if nargin<1 || isempty(directory)
0019     directory = '../../htdocs/tutorial/';
0020     %directory = cd;
0021 end
0022 diary tutorial_status.txt
0023 
0024 global my_dir; my_dir = cd;
0025 cd(directory);
0026 global tut_dir; tut_dir = cd;
0027 global D; D = genpath('.');
0028 global d;
0029 
0030 warning off all
0031 eidors_msg('log_level',0);
0032 pause off
0033 
0034 % a little consistency would have been nice!
0035 global tut_dlm;
0036 if strcmp(computer,'PCWIN') || strcmp(computer,'PCWIN64')
0037     tut_dlm = ';';
0038 else
0039     tut_dlm = ':';
0040 end
0041 
0042 global tut_count; tut_count = 0;
0043 global last_tut;
0044 if nargin >1,
0045     last_tut = tcount;
0046 else last_tut = 0;
0047 end
0048 [d,D]= strtok(D,tut_dlm);
0049 while ~isempty(d)
0050     if ~isempty(strfind(d,'.svn')); 
0051         [d,D]= strtok(D,tut_dlm); 
0052         continue; 
0053     end;
0054     try
0055        cd(d);
0056     catch
0057        keyboard
0058     end
0059     global F;F = dir('*.m');
0060     F = struct2cell(F); F = sortrows(F(1,:));% assume sorted by name
0061     global errors; errors={};
0062     global e_count; e_count = 1;
0063     global w_count; w_count = 1;
0064     global warnings; warnings={};
0065 
0066 
0067     while length(F) > 0
0068         evalin('base','clear');
0069         calc_colours('defaults');
0070         clf; % make sure pictures from previous tutorial don't affect
0071         tutname = F{1};
0072         %tutname(end-3) = [];
0073         tutname(end-3) = '*'; % assume tutorials differ by 2 chars
0074         tutname(end-2) = [];
0075         T = dir(tutname);
0076         if any(strcmp( T(1).name, skiplist)); 
0077            F(1:length(T)) = []; 
0078            continue; 
0079         end
0080         while length(T) > 0
0081             calc_colours('defaults');
0082             if length(T(1).name)>length(tutname)+2 % allow some leeway
0083                 T(1) = [];
0084                 continue
0085             end
0086             name = T(1).name(1:end-2);
0087             skip = 0;
0088             if isfunction(name)
0089                 skip = 1;
0090             else
0091                 tut_count = tut_count +1;
0092             end
0093             if skip || tut_count < last_tut 
0094                 T(1) = [];
0095                 F(1) = [];
0096                 continue
0097             end
0098             fprintf([num2str(tut_count,'%04d') '  ' strrep(d,'\','\\') '\\' name]);
0099             lastwarn('');
0100             save tmp
0101             try
0102               evalin('base',sprintf('evalc(''%s'');',name));
0103 %                 evalc(['evalin(''base'',''' name ''')'])
0104                 if ~isempty(lastwarn)
0105                     fprintf(' WARNING(S) = (%s)\n',lastwarn);
0106                     warnings{w_count,1} = T(1).name;
0107                     warnings{w_count,1} = d;
0108                     w_count = w_count+1;
0109                 else
0110                     fprintf(' OK\n');
0111                 end
0112                 load tmp
0113                 delete('tmp.mat');
0114                 global warnings w_count;
0115             catch
0116                 load tmp
0117                 delete('tmp.mat');
0118                 errors{e_count,1} = T(1).name;
0119                 L = lasterror();
0120                 errors{e_count,2} = d;
0121                 errors{e_count,3} = L.message;
0122                 e_count = e_count + 1;
0123                 fprintf(' ERROR = (%s)\n',L.message);
0124             end
0125 
0126             T(1) = [];
0127             F(1) = [];
0128 
0129         end
0130         clear; clf; %close all; %close all crashes vnc :(
0131         global F tut_count e_count errors warnings w_count d D my_dir tut_dir tut_dlm last_tut
0132     end
0133     cd(tut_dir);
0134     [d,D]= strtok(D,tut_dlm);
0135 end
0136 % if numel(errors)>0
0137 %     errors
0138 % end
0139 warning on all
0140 eidors_msg('log_level',2);
0141 pause on
0142 clear global F tut_count e_count errors warnings w_count
0143 cd(my_dir)
0144 diary off
0145 
0146 function sl = skiplist
0147   sl = {'netgen_accuracy01.m', ...
0148         'common_models01.m', ...
0149         'Script_For_Tutorial.m'};
0150 %     , ...
0151 %         'cg_ards_recruitment_01.m'};
0152 
0153 function flag = isfunction(fname)
0154 fid = fopen([fname '.m']);
0155 l = fgetl(fid);
0156 fclose(fid);
0157 t = strtok(l);
0158 flag = strcmp(t,'function');
0159

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005