Skip to content

Commit

Permalink
ENH: Add -cover_exclude option for excluding patterns
Browse files Browse the repository at this point in the history
This adds an option to the API to specify patterns which should not
be included in the coverage report.

Closes MOxUnit#4.
  • Loading branch information
scottclowe committed Feb 22, 2016
1 parent 172eeca commit 4ab5b2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion MOcov/@MOcovMFileCollection/MOcovMFileCollection.m
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -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=[];
Expand Down
2 changes: 1 addition & 1 deletion MOcov/@MOcovMFileCollection/prepare.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion MOcov/mocov.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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=[];
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 4ab5b2a

Please sign in to comment.