forked from tsdev/spinw
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun_tests.m
67 lines (60 loc) · 2.46 KB
/
run_tests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function result = run_tests(out_dir)
disp(version);
if ~exist('spinw', 'class')
if exist('swfiles', 'dir') && exist('external', 'dir') && exist('dat_files', 'dir')
addpath(genpath('swfiles'));
addpath(genpath('external'));
addpath(genpath('dat_files'));
else
error(['SpinW is not installed and the swfiles, external and/or ', ...
'dat_files drectories couldn''t be found on the current ', ...
'path, so the tests cannot be run.'])
end
end
if nargin == 0
out_dir = fullfile(pwd);
end
if ~exist(out_dir, 'dir')
mkdir(out_dir);
end
import matlab.unittest.TestSuite
import matlab.unittest.TestRunner
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.codecoverage.CoberturaFormat
import matlab.unittest.selectors.HasTag
import matlab.unittest.plugins.XMLPlugin
% Suppress printing to make test output less verbose
pref = swpref;
pref.fid = 0;
pref.usemex = 0; % Tests which use mex will set it themselves
pref.nthread = -1;
pref.nspinlarge = 120;
suite = TestSuite.fromPackage('sw_tests', 'IncludingSubpackages', true);
if ~sw_hassymtoolbox()
% only run symbolic tests when the toolbox is available
suite = suite.selectIf(~HasTag('Symbolic'));
end
runner = TestRunner.withTextOutput;
% compile mex files
sw_mex('compile', true, 'test', false, 'swtest', false);
% Add coverage output
cov_dirs = {'swfiles', 'external'};
for i = 1:length(cov_dirs)
reportFormat = CoberturaFormat(fullfile(out_dir, ['coverage_', cov_dirs{i}, '.xml']));
coverage_plugin = CodeCoveragePlugin.forFolder(cov_dirs{i}, ...
'Producing', reportFormat, ...
'IncludingSubfolders', true);
runner.addPlugin(coverage_plugin);
if verLessThan('matlab', '9.12') % Can add cov for multiple folders only from R2022a
break;
end
end
% Add JUnit output - unique name so they are not overwritten on CI
junit_fname = ['junit_report_', computer, version('-release'), '.xml'];
junit_plugin = XMLPlugin.producingJUnitFormat(junit_fname);
runner.addPlugin(junit_plugin)
result = runner.run(suite)
if(any(arrayfun(@(x) x.Failed, result)))
error('Test failed');
end
end