|
2 | 2 |
|
3 | 3 | function failed = runMatlabTests(varargin) |
4 | 4 |
|
5 | | - |
6 | 5 | p = inputParser; |
7 | | -p.addParameter('PDFReportPath', '', @ischar); |
8 | | -p.addParameter('TAPResultsPath', '', @ischar); |
9 | | -p.addParameter('JUnitResultsPath', '', @ischar); |
10 | | -p.addParameter('SimulinkTestResultsPath', '', @ischar); |
11 | | -p.addParameter('CoberturaCodeCoveragePath', '', @ischar); |
12 | | -p.addParameter('CoberturaModelCoveragePath', '', @ischar); |
| 6 | +validationFcn = @(c)ischar(c) && (isempty(c) || isrow(c)); |
| 7 | + |
| 8 | +p.addParameter('PDFReportPath', '', validationFcn); |
| 9 | +p.addParameter('TAPResultsPath', '', validationFcn); |
| 10 | +p.addParameter('JUnitResultsPath', '', validationFcn); |
| 11 | +p.addParameter('SimulinkTestResultsPath', '', validationFcn); |
| 12 | +p.addParameter('CoberturaCodeCoveragePath', '', validationFcn); |
| 13 | +p.addParameter('CoberturaModelCoveragePath', '', validationFcn); |
13 | 14 |
|
14 | 15 | p.parse(varargin{:}); |
15 | 16 |
|
|
43 | 44 | warning('MATLAB:testArtifact:junitReportNotSupported', 'Producing JUnit xml results is not supported in this release.'); |
44 | 45 | else |
45 | 46 | import('matlab.unittest.plugins.XMLPlugin'); |
46 | | - xmlFile = getFullFileForReport(junitReportPath); |
47 | | - runner.addPlugin(XMLPlugin.producingJUnitFormat(xmlFile)); |
| 47 | + preparePath(junitReportPath); |
| 48 | + runner.addPlugin(XMLPlugin.producingJUnitFormat(junitReportPath)); |
48 | 49 | end |
49 | 50 | end |
50 | 51 |
|
|
77 | 78 | warning('MATLAB:testArtifact:coberturaReportNotSupported', 'Producing Cobertura code coverage results is not supported in this release.'); |
78 | 79 | else |
79 | 80 | import('matlab.unittest.plugins.CodeCoveragePlugin'); |
80 | | - coverageFile = getFullFileForReport(coberturaReportPath); |
| 81 | + preparePath(coberturaReportPath); |
81 | 82 | workSpace = fullfile(pwd); |
82 | 83 | runner.addPlugin(CodeCoveragePlugin.forFolder(workSpace,'IncludingSubfolders',true,... |
83 | | - 'Producing', CoberturaFormat(coverageFile))); |
| 84 | + 'Producing', CoberturaFormat(coberturaReportPath))); |
84 | 85 | end |
85 | 86 | end |
86 | 87 |
|
|
92 | 93 | else |
93 | 94 | import('sltest.plugins.ModelCoveragePlugin'); |
94 | 95 |
|
95 | | - coverageFile = getFullFileForReport(modelCoveragePath); |
96 | | - runner.addPlugin(ModelCoveragePlugin('Producing',CoberturaFormat(coverageFile))); |
| 96 | + preparePath(modelCoveragePath); |
| 97 | + runner.addPlugin(ModelCoveragePlugin('Producing',CoberturaFormat(modelCoveragePath))); |
97 | 98 | end |
98 | 99 | end |
99 | 100 |
|
|
104 | 105 | if ~stmResultsPluginPresent || ~exportSTMResultsSupported |
105 | 106 | issueExportSTMResultsUnsupportedWarning; |
106 | 107 | else |
107 | | - stmResultFile = getFullFileForReport(stmReportPath); |
108 | | - runner.addPlugin(TestManagerResultsPlugin('ExportToFile', stmResultFile)); |
| 108 | + preparePath(stmReportPath); |
| 109 | + runner.addPlugin(TestManagerResultsPlugin('ExportToFile', stmReportPath)); |
109 | 110 | stmResultsPluginAddedToRunner = true; |
110 | 111 | end |
111 | 112 | end |
|
118 | 119 | elseif ~testReportPluginPresent |
119 | 120 | issuePDFReportUnsupportedWarning; |
120 | 121 | else |
121 | | - pdfReportFile = getFullFileForReport(pdfReportPath); |
| 122 | + preparePath(pdfReportPath); |
122 | 123 | import('matlab.unittest.plugins.TestReportPlugin'); |
123 | | - runner.addPlugin(TestReportPlugin.producingPDF(pdfReportFile)); |
| 124 | + runner.addPlugin(TestReportPlugin.producingPDF(pdfReportPath)); |
124 | 125 |
|
125 | 126 | if ~stmResultsPluginAddedToRunner && stmResultsPluginPresent |
126 | 127 | runner.addPlugin(TestManagerResultsPlugin); |
|
131 | 132 | results = runner.run(suite); |
132 | 133 | failed = any([results.Failed]); |
133 | 134 |
|
134 | | -function fileName = getFullFileForReport(filePath) |
135 | | -[filepath,name,ext] = fileparts(filePath); |
136 | | -if (filepath == "") |
137 | | - fileName = fullfile(pwd,strcat(name,ext)); |
138 | | -else |
139 | | - mkdirIfNeeded(filepath) |
140 | | - fileName = fullfile(filepath, strcat(name,ext)); |
| 135 | +function preparePath(path) |
| 136 | +dir = fileparts(path); |
| 137 | +dirExists = isempty(dir) || exist(dir,'dir') == 7; |
| 138 | +if ~dirExists |
| 139 | + mkdir(dir); |
141 | 140 | end |
142 | 141 |
|
143 | 142 | function tapToFile = getTapResultFile(resultsDir) |
144 | 143 | import('matlab.unittest.plugins.ToFile'); |
145 | | -tapFile = getFullFileForReport(resultsDir); |
146 | | -fclose(fopen(tapFile,'w')); |
147 | | -tapToFile = matlab.unittest.plugins.ToFile(tapFile); |
| 144 | +preparePath(resultsDir); |
| 145 | +fclose(fopen(resultsDir,'w')); |
| 146 | +tapToFile = matlab.unittest.plugins.ToFile(resultsDir); |
148 | 147 |
|
149 | 148 | function suite = getTestSuite() |
150 | 149 | import('matlab.unittest.TestSuite'); |
|
155 | 154 | suite = testsuite(pwd,'IncludeSubfolders',true); |
156 | 155 | end |
157 | 156 |
|
158 | | - |
159 | | -function mkdirIfNeeded(dir) |
160 | | -if exist(dir,'dir') ~= 7 |
161 | | - mkdir(dir); |
162 | | -end |
163 | | - |
164 | 157 | function plugin = CoberturaFormat(varargin) |
165 | 158 | plugin = matlab.unittest.plugins.codecoverage.CoberturaFormat(varargin{:}); |
166 | 159 |
|
|
0 commit comments