|
| 1 | +function results = bids_runtests(pth) |
| 2 | +% Run tests |
| 3 | +% List all the 'test_*.m' files located in the same directory as this |
| 4 | +% function, run them and keep track of how many passed, failed or are |
| 5 | +% incomplete. |
| 6 | +%__________________________________________________________________________ |
| 7 | + |
| 8 | +% Copyright (C) 2019, Guillaume Flandin, Wellcome Centre for Human Neuroimaging |
| 9 | +% Copyright (C) 2020--, CPP_BIDS developers |
| 10 | + |
| 11 | +%-Get the path of where this file is located |
| 12 | +if ~nargin, pth = fileparts(mfilename('fullpath')); end |
| 13 | + |
| 14 | +%-List all the 'test_*.m' files located in the same directory as this |
| 15 | +% function |
| 16 | +d = dir(pth); |
| 17 | +d([d.isdir]) = []; |
| 18 | +d(arrayfun(@(x) isempty(regexp(x.name,'^test_.*\.m$','once')),d)) = []; |
| 19 | + |
| 20 | +results = struct('Passed',{},'Failed',{},'Incomplete',{},'Duration',{}); |
| 21 | +for i=1:numel(d) |
| 22 | + |
| 23 | + results(i).Failed = false; |
| 24 | + results(i).Passed = false; |
| 25 | + results(i).Incomplete = false; |
| 26 | + |
| 27 | + tstart = tic; |
| 28 | + |
| 29 | + %-Run each test file and catch error message in case of failure |
| 30 | + try |
| 31 | + |
| 32 | + fprintf('%s',d(i).name(1:end-2)); |
| 33 | + feval(d(i).name(1:end-2)); |
| 34 | + results(i).Passed = true; |
| 35 | + catch err |
| 36 | + results(i).Failed = true; |
| 37 | + fprintf('\n%s',err.message); |
| 38 | + end |
| 39 | + |
| 40 | + results(i).Duration = toc(tstart); |
| 41 | + |
| 42 | + fprintf('\n'); |
| 43 | + |
| 44 | +end |
| 45 | + |
| 46 | +if ~nargout |
| 47 | + fprintf(['Totals (%d tests):\n\t%d Passed, %d Failed, %d Incomplete.\n' ... |
| 48 | + '\t%f seconds testing time.\n\n'],numel(results),nnz([results.Passed]),... |
| 49 | + nnz([results.Failed]),nnz([results.Incomplete]),sum([results.Duration])); |
| 50 | +end |
0 commit comments