Skip to content

Commit f37aa9f

Browse files
committed
Make tests run-able if project is used as a project reference.
1 parent 4fe8087 commit f37aa9f

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

runAllTests.m

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
% Script to run all tests from the "xUintTests" directory.
2-
3-
clear
4-
clc
1+
function testRes = runAllTests()
2+
%RUNALLTESTS Run all tests from the "xUintTests" directory.
3+
% TESTRES = RUNALLTESTS() runs all tests from the "xUnitTests" directory
4+
% and returns the results TESTRES.
5+
%
6+
7+
% Get the root folder of the project - this should also work when the
8+
% project is referenced in another project.
9+
path2RootFolder = mfilename('fullpath');
10+
path2RootFolder = path2RootFolder(1:end-numel(mfilename()));
511

612
% Add current folder to path - this is needed for pre R2019a releases that
713
% don't support Matlab Projects
8-
addpath(pwd)
14+
addpath(path2RootFolder)
915

1016
% Create and run the test suite
1117
testSuite = matlab.unittest.TestSuite.fromFolder(...
12-
'xUnitTests', ...
18+
[path2RootFolder 'xUnitTests'], ...
1319
'IncludingSubfolders',true);
20+
21+
str = ' Running "Path2D" tests ... ';
22+
printTopRule('=', numel(str))
23+
fprintf('<strong>%s</strong>\n', str);
24+
printTopRule('=', numel(str))
25+
1426
testRes = run(testSuite);
15-
disp(testRes)
27+
28+
end%fcn
29+
30+
31+
function printTopRule(symbol, n)
32+
fprintf('%s\n', repmat(symbol, 1, n));
33+
end%fcn

0 commit comments

Comments
 (0)