Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 11e286d

Browse files
author
Nikhil Bhoski
committed
Updated review comments
1 parent b03aa82 commit 11e286d

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package com.mathworks.ci;
22

3+
/**
4+
* Copyright 2019-2020 The MathWorks, Inc.
5+
*
6+
* MATLAB test run builder used to run all MATLAB & Simulink tests automatically and generate
7+
* selected test artifacts.
8+
*
9+
*/
10+
311
import java.io.IOException;
412
import java.util.ArrayList;
513
import java.util.List;
@@ -142,7 +150,7 @@ public StmResultsChkBx getStmResultsChkBx() {
142150
}
143151

144152
public String getStmResultsFilePath() {
145-
return stmResultsFilePath;
153+
return this.stmResultsFilePath;
146154
}
147155

148156
public boolean getIsStmChecked() {

src/main/resources/com/mathworks/ci/RunMatlabTestsBuilder/runMatlabTests.m

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
function failed = runMatlabTests(varargin)
44

5-
65
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);
1314

1415
p.parse(varargin{:});
1516

@@ -43,8 +44,8 @@
4344
warning('MATLAB:testArtifact:junitReportNotSupported', 'Producing JUnit xml results is not supported in this release.');
4445
else
4546
import('matlab.unittest.plugins.XMLPlugin');
46-
xmlFile = getFullFileForReport(junitReportPath);
47-
runner.addPlugin(XMLPlugin.producingJUnitFormat(xmlFile));
47+
preparePath(junitReportPath);
48+
runner.addPlugin(XMLPlugin.producingJUnitFormat(junitReportPath));
4849
end
4950
end
5051

@@ -77,10 +78,10 @@
7778
warning('MATLAB:testArtifact:coberturaReportNotSupported', 'Producing Cobertura code coverage results is not supported in this release.');
7879
else
7980
import('matlab.unittest.plugins.CodeCoveragePlugin');
80-
coverageFile = getFullFileForReport(coberturaReportPath);
81+
preparePath(coberturaReportPath);
8182
workSpace = fullfile(pwd);
8283
runner.addPlugin(CodeCoveragePlugin.forFolder(workSpace,'IncludingSubfolders',true,...
83-
'Producing', CoberturaFormat(coverageFile)));
84+
'Producing', CoberturaFormat(coberturaReportPath)));
8485
end
8586
end
8687

@@ -92,8 +93,8 @@
9293
else
9394
import('sltest.plugins.ModelCoveragePlugin');
9495

95-
coverageFile = getFullFileForReport(modelCoveragePath);
96-
runner.addPlugin(ModelCoveragePlugin('Producing',CoberturaFormat(coverageFile)));
96+
preparePath(modelCoveragePath);
97+
runner.addPlugin(ModelCoveragePlugin('Producing',CoberturaFormat(modelCoveragePath)));
9798
end
9899
end
99100

@@ -104,8 +105,8 @@
104105
if ~stmResultsPluginPresent || ~exportSTMResultsSupported
105106
issueExportSTMResultsUnsupportedWarning;
106107
else
107-
stmResultFile = getFullFileForReport(stmReportPath);
108-
runner.addPlugin(TestManagerResultsPlugin('ExportToFile', stmResultFile));
108+
preparePath(stmReportPath);
109+
runner.addPlugin(TestManagerResultsPlugin('ExportToFile', stmReportPath));
109110
stmResultsPluginAddedToRunner = true;
110111
end
111112
end
@@ -118,9 +119,9 @@
118119
elseif ~testReportPluginPresent
119120
issuePDFReportUnsupportedWarning;
120121
else
121-
pdfReportFile = getFullFileForReport(pdfReportPath);
122+
preparePath(pdfReportPath);
122123
import('matlab.unittest.plugins.TestReportPlugin');
123-
runner.addPlugin(TestReportPlugin.producingPDF(pdfReportFile));
124+
runner.addPlugin(TestReportPlugin.producingPDF(pdfReportPath));
124125

125126
if ~stmResultsPluginAddedToRunner && stmResultsPluginPresent
126127
runner.addPlugin(TestManagerResultsPlugin);
@@ -131,20 +132,18 @@
131132
results = runner.run(suite);
132133
failed = any([results.Failed]);
133134

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);
141140
end
142141

143142
function tapToFile = getTapResultFile(resultsDir)
144143
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);
148147

149148
function suite = getTestSuite()
150149
import('matlab.unittest.TestSuite');
@@ -155,12 +154,6 @@
155154
suite = testsuite(pwd,'IncludeSubfolders',true);
156155
end
157156

158-
159-
function mkdirIfNeeded(dir)
160-
if exist(dir,'dir') ~= 7
161-
mkdir(dir);
162-
end
163-
164157
function plugin = CoberturaFormat(varargin)
165158
plugin = matlab.unittest.plugins.codecoverage.CoberturaFormat(varargin{:});
166159

0 commit comments

Comments
 (0)