From 172eeca7b8f2863c9bc23abf69fa87b0cd1bc760 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Mon, 22 Feb 2016 13:30:18 +0000 Subject: [PATCH 1/4] ENH: mocov_find_files.m Add exclude patterns option Will exclude matching directories and files from the list. --- MOcov/mocov_find_files.m | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/MOcov/mocov_find_files.m b/MOcov/mocov_find_files.m index e8b9d03..36122bd 100644 --- a/MOcov/mocov_find_files.m +++ b/MOcov/mocov_find_files.m @@ -1,4 +1,4 @@ -function res=mocov_find_files(root_dir, file_pat, monitor) +function res=mocov_find_files(root_dir, file_pat, monitor, exclude_pat) % Finds files recursively in a directory % % res=mocov_find_files([root_dir[, file_pat]]) @@ -12,6 +12,7 @@ % is used, corresponding to all files. % monitor Optional progress monitory that supports a % 'notify' method. +% exclude_pat Optional cell array of patterns to exclude. % % Output: % res Kx1 cell with names of files in root_dir matching @@ -35,10 +36,28 @@ monitor=[]; end + if nargin<4 + exclude_pat={}; + end + + if ischar(exclude_pat) + exclude_pat={exclude_pat}; + end + file_re=['^' ... % start of the string regexptranslate('wildcard',file_pat) ... '$']; % end of the string + exclude_re=''; + for k=1:numel(exclude_pat) + if ~isempty(exclude_re) + exclude_re=[exclude_re '|']; + end + exclude_re=[exclude_re ... + '^' ... % start of the string + regexptranslate('wildcard',exclude_pat{k}) ... + '$']; % end of the string + end if ~isempty(monitor) msg=sprintf('Finding files matching %s from %s',file_pat,root_dir); @@ -47,7 +66,7 @@ res=find_files_recursively(root_dir,file_re,monitor); -function res=find_files_recursively(root_dir,file_re,monitor) +function res=find_files_recursively(root_dir,file_re,monitor,exclude_re) if isempty(root_dir) dir_arg={}; else @@ -67,7 +86,9 @@ if ~ignore_fn path_fn=fullfile(root_dir, fn); - if isdir(path_fn) + if ~isempty(regexp(fn,exclude_re,'once')); + continue; + elseif isdir(path_fn) res=find_files_recursively(path_fn,file_re,monitor); elseif ~isempty(regexp(fn,file_re,'once')); res={path_fn}; From 4ab5b2adf3ae62ec8351f22594278f7cdb8559f9 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Mon, 22 Feb 2016 13:39:01 +0000 Subject: [PATCH 2/4] ENH: Add -cover_exclude option for excluding patterns This adds an option to the API to specify patterns which should not be included in the coverage report. Closes #4. --- MOcov/@MOcovMFileCollection/MOcovMFileCollection.m | 8 +++++++- MOcov/@MOcovMFileCollection/prepare.m | 2 +- MOcov/mocov.m | 12 +++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/MOcov/@MOcovMFileCollection/MOcovMFileCollection.m b/MOcov/@MOcovMFileCollection/MOcovMFileCollection.m index dec91ed..93a2708 100644 --- a/MOcov/@MOcovMFileCollection/MOcovMFileCollection.m +++ b/MOcov/@MOcovMFileCollection/MOcovMFileCollection.m @@ -1,4 +1,4 @@ -function obj=MOcovMFileCollection(root_dir, method, monitor) +function obj=MOcovMFileCollection(root_dir, method, monitor, exclude_pat) % instantiate MOcovMFileCollection % % obj=MOcovMFileCollection(root_dir, method, monitor) @@ -13,9 +13,14 @@ % - 'profile' use Matlab profiler % default: 'file' % monitor optional MOcovProgressMonitor instance +% exclude_pat Optional cell array of patterns to exclude. % % See also: mocov + if nargin<4 || isempty(exclude_pat) + exclude_pat={}; + end + if nargin<3 || isempty(monitor) monitor=MOcovProgressMonitor(); end @@ -27,6 +32,7 @@ props=struct(); props.root_dir=root_dir; props.monitor=monitor; + props.exclude_pat=exclude_pat; props.mfiles=[]; props.orig_path=[]; props.temp_dir=[]; diff --git a/MOcov/@MOcovMFileCollection/prepare.m b/MOcov/@MOcovMFileCollection/prepare.m index b3a470e..615c634 100644 --- a/MOcov/@MOcovMFileCollection/prepare.m +++ b/MOcov/@MOcovMFileCollection/prepare.m @@ -14,7 +14,7 @@ monitor=obj.monitor; - fns=mocov_find_files(obj.root_dir,'*.m',monitor); + fns=mocov_find_files(obj.root_dir,'*.m',monitor,obj.exclude_pat); n=numel(fns); mfiles=cell(n,1); diff --git a/MOcov/mocov.m b/MOcov/mocov.m index c8baf14..6155df4 100644 --- a/MOcov/mocov.m +++ b/MOcov/mocov.m @@ -16,6 +16,10 @@ % Mutually exclusive with '-e' option. % '-cover', covd Find coverage for files in dir covd and all % of its subdirectories +% '-cover_exclude', pat (optional) Exclude files and directories +% which match this pattern, even if they are +% in covd. Can be used multiple times to +% specify multiple patterns to match. % '-cover_json_file', cj (optional) Store coverage information in % ` file cj in JSON format [use with coveralls] % '-cover_xml_file', xc (optional) Store coverage information in @@ -81,7 +85,8 @@ monitor=MOcovProgressMonitor(opt.verbose); mfile_collection=MOcovMFileCollection(opt.cover,... opt.method,... - monitor); + monitor,... + opt.excludes); mfile_collection=prepare(mfile_collection); cleaner_collection=onCleanup(@()cleanup(mfile_collection)); @@ -151,6 +156,7 @@ function write_coverage_results(writers, mfile_collection, opt) defaults=struct(); defaults.coverage_dir=pwd(); + defaults.excludes={}; defaults.html_dir=[]; defaults.cobertura_xml=[]; defaults.coveralls_json=[]; @@ -185,6 +191,10 @@ function write_coverage_results(writers, mfile_collection, opt) k=k+1; opt.cover=varargin{k}; + case '-cover_exclude' + k=k+1; + opt.excludes(end+1)=varargin(k); + case '-verbose' opt.verbose=opt.verbose+1; From 2c721d741604f106b4c1e163280982ffb02fe55b Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Fri, 26 Feb 2016 13:02:38 +0000 Subject: [PATCH 3/4] BUG: Fix mocov_find_files.m to pass exclude_re recursively --- MOcov/mocov_find_files.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MOcov/mocov_find_files.m b/MOcov/mocov_find_files.m index 36122bd..09cf1a0 100644 --- a/MOcov/mocov_find_files.m +++ b/MOcov/mocov_find_files.m @@ -89,7 +89,7 @@ if ~isempty(regexp(fn,exclude_re,'once')); continue; elseif isdir(path_fn) - res=find_files_recursively(path_fn,file_re,monitor); + res=find_files_recursively(path_fn,file_re,monitor,exclude_re); elseif ~isempty(regexp(fn,file_re,'once')); res={path_fn}; if ~isempty(monitor) @@ -100,4 +100,4 @@ res_cell{k}=res; end - res=cat(1,res_cell{:}); \ No newline at end of file + res=cat(1,res_cell{:}); From 074542d124a0159a21af956247144da81497778d Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Fri, 26 Feb 2016 13:22:27 +0000 Subject: [PATCH 4/4] DOC: mocov_find_files.m Improve exclude_pat documentation --- MOcov/mocov_find_files.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MOcov/mocov_find_files.m b/MOcov/mocov_find_files.m index 09cf1a0..f6c2e24 100644 --- a/MOcov/mocov_find_files.m +++ b/MOcov/mocov_find_files.m @@ -12,7 +12,9 @@ % is used, corresponding to all files. % monitor Optional progress monitory that supports a % 'notify' method. -% exclude_pat Optional cell array of patterns to exclude. +% exclude_pat Optional cell array of patterns to exclude. Both +% files and directories which match one of these +% patterns will be omitted from the output. % % Output: % res Kx1 cell with names of files in root_dir matching