Skip to content

Commit 850b334

Browse files
author
Mantas Mikaitis
committed
Output unit test results optionally
1 parent 5182a1a commit 850b334

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

testing/test_anymatrix_properties.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
function test_anymatrix_properties(regenerate_tests, warnings_on)
1+
function results = test_anymatrix_properties(regenerate_tests, ...
2+
warnings_on, results_out)
23
%TEST_ANYMATRIX_PROPERTIES Test anymatrix matrix properties.
34
% TEST_ANYMATRIX_PROPERTIES(regenerate_tests, warnings_on)
45
% runs unit tests for anymatrix matrix properties.
56
% It auto generates the function-based unit tests.
67
% If regenerate_tests == 1 (default 0) then the tests are regenerated.
78
% If warnings_on == 1 (default 0) then warnings are generated for
8-
% properties that do not have tests available
9+
% properties that do not have tests available.
10+
% If results_out == 1 (default 0) then the test results are returned
11+
% which can be useful for generating reports with generatePDFReport()
12+
% and other similar functions.
13+
14+
import matlab.unittest.plugins.DiagnosticsRecordingPlugin
15+
import matlab.unittest.Verbosity
16+
import matlab.unittest.plugins.TestRunProgressPlugin
17+
import matlab.unittest.plugins.DiagnosticsOutputPlugin
918

1019
anymatrix('sc');
1120
root_path = fileparts(strcat(mfilename('fullpath'), '.m'));
1221

1322
if nargin < 1 || isempty(regenerate_tests), regenerate_tests = 0; end
1423
if nargin < 2, warnings_on = 0; end
24+
if nargin < 3, results_out = 0; end
1525

1626
% Check which properties recognized by anymatrix have tests and throw
1727
% warnings for those that can't be tested.
@@ -120,13 +130,21 @@ function test_anymatrix_properties(regenerate_tests, warnings_on)
120130

121131
% Configure a test runner.
122132
runner = matlab.unittest.TestRunner.withNoPlugins;
123-
import matlab.unittest.plugins.TestRunProgressPlugin
124-
import matlab.unittest.plugins.DiagnosticsOutputPlugin
125133
runner.addPlugin(TestRunProgressPlugin.withVerbosity(2))
126134
runner.addPlugin(DiagnosticsOutputPlugin('OutputDetail', 2))
127135

136+
if (results_out)
137+
runner.addPlugin(DiagnosticsRecordingPlugin( ...
138+
IncludingPassingDiagnostics=false,LoggingLevel=Verbosity.Verbose))
139+
end
140+
128141
% Run the testsuite.
129142
test_results = runner.run(anymatrix_func_based_tests);
130143
table(test_results)
131144

145+
% Output the test results if required.
146+
if results_out
147+
results = test_results;
148+
end
149+
132150
end

0 commit comments

Comments
 (0)