Skip to content

Commit 1feeb6e

Browse files
k1o0k1o0
authored andcommitted
Added tests script
1 parent 31cecfa commit 1feeb6e

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

runAllTests.m

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function runAllTests(id, repo)
2+
%% Script for running all Rigbox tests
3+
% To be called for code checks and the like
4+
% TODO May add flags for levels of testing
5+
% TODO Method setup in dat_test may become global fixture
6+
% TODO Delete sinusoidLayer_test from this folder
7+
if nargin == 1; repo = 'rigbox'; end
8+
try
9+
%% Initialize enviroment
10+
dbPath = 'C:\Users\Experiment\db.json';
11+
fprintf('Running tests\n')
12+
fprintf('Repo = %s\n', repo)
13+
origDir = pwd;
14+
cleanup = onCleanup(@() cd(origDir));
15+
cd(fullfile(fileparts(which('addRigboxPaths')),'tests'))
16+
% Ideally we check code coverage and tests for all commits
17+
import matlab.unittest.TestRunner
18+
import matlab.unittest.plugins.CodeCoveragePlugin
19+
import matlab.unittest.plugins.codecoverage.CoberturaFormat
20+
21+
%% Gather Rigbox main tests
22+
main_tests = testsuite;
23+
24+
%% Gather signals tests
25+
root = getOr(dat.paths,'rigbox');
26+
signals_tests = testsuite(fullfile(root, 'signals', 'tests'));
27+
28+
%% Gather alyx-matlab tests
29+
alyx_tests = testsuite(fullfile(root, 'alyx-matlab', 'tests'));
30+
31+
%% Filter & run
32+
% the suite is automatically sorted based on shared fixtures. However, if
33+
% you add, remove, or reorder elements after initial suite creation, call
34+
% the sortByFixtures method to sort the suite.
35+
all_tests = [main_tests signals_tests alyx_tests];
36+
% If the repo under test is alyx, filter out irrelevent tests
37+
if strcmp(repo, 'alyx')
38+
all_tests = all_tests(startsWith({all_tests.Name}, 'Alyx', 'IgnoreCase', true));
39+
end
40+
41+
runner = TestRunner.withTextOutput;
42+
reportFile = fullfile(fileparts(dbPath), 'CoverageResults.xml');
43+
reportFormat = CoberturaFormat(reportFile);
44+
plugin = CodeCoveragePlugin.forFolder(root, 'Producing', reportFormat, ...
45+
'IncludingSubfolders', true);
46+
runner.addPlugin(plugin)
47+
48+
results = runner.run(all_tests);
49+
assert(now - file.modDate(reportFile) < 0.001, ...
50+
'Coverage file may not have been updated')
51+
52+
%% Diagnostics
53+
% failed = {all_tests([results.Failed]).Name}';
54+
% [info,filePaths] = checkcode(...);
55+
% Load benchmarks and compare for performance tests?
56+
status = iff(all([results.Passed]), 'success', 'failure');
57+
failStr = sprintf('%i/%i tests failed', sum([results.Failed]), length(results));
58+
context = iff(all([results.Passed]), 'All passed', failStr);
59+
report = struct(...
60+
'commit', id, ...
61+
'results', results, ...
62+
'status', status, ...
63+
'description', context);
64+
if file.exists(dbPath)
65+
data = jsondecode(fileread(dbPath));
66+
report = [report; data];
67+
end
68+
fid = fopen(dbPath, 'w+');
69+
fprintf(fid, '%s', jsonencode(report));
70+
exit(fclose(fid))
71+
catch ex
72+
fprintf('Error in ''%s'' line %i: %s: %s\n', ...
73+
ex.stack(1).name, ex.stack(1).line, ex.identifier, ex.message)
74+
exit(1)
75+
end

0 commit comments

Comments
 (0)