Skip to content

Commit fa44eab

Browse files
committed
set up travis CI for unit tests
1 parent 3804278 commit fa44eab

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Travis CI (https://travis-ci.org/)
2+
3+
language: c
4+
dist: bionic
5+
cache:
6+
apt: true # only works with Pro version
7+
8+
env:
9+
global:
10+
- OCTFLAGS="--no-gui --no-window-system --silent"
11+
12+
before_install:
13+
- travis_retry sudo apt-get -y -qq update
14+
- travis_retry sudo apt-get -y install octave
15+
- travis_retry sudo apt-get -y install liboctave-dev
16+
- travis_retry sudo apt-get -y install nodejs
17+
- travis_retry sudo apt-get -y install npm
18+
19+
install:
20+
# Install JSONio
21+
#- travis_retry git clone git://github.com/gllmflndn/JSONio.git --depth 1
22+
#- cd JSONio; mkoctfile --mex jsonread.c jsmn.c -DJSMN_PARENT_LINKS; cd ..
23+
#- octave $OCTFLAGS --eval "addpath (fullfile (pwd, 'JSONio')); savepath ();"
24+
# Install BIDS-MATLAB
25+
- octave $OCTFLAGS --eval "addpath (pwd); savepath ();"
26+
# Install BIDS-Validator
27+
#- sudo npm install -g bids-validator
28+
29+
before_script:
30+
# Change current directory
31+
- cd tests
32+
33+
script:
34+
- octave $OCTFLAGS --eval "results = bids_runtests; assert(all(~[results.Failed]))"

tests/bids_runtests.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)