Skip to content

Commit cd5b6b4

Browse files
committed
Use custom testTask instead of built-in TestTask to enable passing example script filenames as parameter to test class definition.
1 parent 4da3d48 commit cd5b6b4

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

buildUtilities/testTask.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function results = testTask(tags)
2+
% Run unit tests
3+
4+
arguments
5+
tags string {mustBeText} = "";
6+
end
7+
8+
import matlab.unittest.TestRunner;
9+
import matlab.unittest.TestSuite;
10+
import matlab.unittest.Verbosity;
11+
import matlab.unittest.plugins.XMLPlugin;
12+
import matlab.unittest.parameters.Parameter;
13+
14+
projObj = currentProject;
15+
16+
% Get list of example scripts in path
17+
exName = {dir(fullfile(projObj.RootFolder,'toolbox/examples','**/*.m')).name}';
18+
exName = exName(isFileOnPath(exName));
19+
exParam = Parameter.fromData('exName',exName);
20+
21+
suite = TestSuite.fromProject(projObj,'ExternalParameters',exParam);
22+
if strlength(tags)>0
23+
suite = suite.selectIf("Tag",tags);
24+
else
25+
disp('No tag was passed as input. All test cases will be executed.');
26+
end
27+
28+
if isempty(suite)
29+
warning('No tests were found with tag(s) "%s" and none will be executed.',strjoin(tags,', '));
30+
end
31+
32+
runner = TestRunner.withTextOutput('OutputDetail', Verbosity.Detailed);
33+
runner.addPlugin(XMLPlugin.producingJUnitFormat(fullfile(projObj.RootFolder,'results.xml')));
34+
35+
results = runner.run(suite);
36+
results.assertSuccess;
37+
38+
end
39+
40+
function onPath = isFileOnPath(filename)
41+
onPath = boolean(zeros(1,length(filename)));
42+
for ii = 1:length(filename)
43+
onPath(ii) = exist(filename{ii},"file")>0;
44+
end
45+
end

buildfile.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
Actions = @(~) updateSGdeps,...
2020
Outputs = "toolbox/dependencies/sg/**");
2121

22-
plan("test") = TestTask( ...
22+
plan("test") = Task( ...
2323
Description = "Run unit tests", ...
2424
Dependencies = ["updateSGdeps","pcodeBossapi"],...
25-
SourceFiles = {'toolbox','tests'},...
26-
TestResults = "results.xml",...
27-
OutputDetail = Verbosity.Detailed,...
28-
Strict = true);
25+
Actions = @(~) testTask);
2926

3027
plan("buildDoc") = Task( ...
3128
Description = "Build HTML doc from sources", ...
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design"/>
5+
</Category>
6+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info location="testTask.m" type="File"/>

0 commit comments

Comments
 (0)