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

Commit 3640322

Browse files
committed
UPdated test cases
1 parent 2ec6b1c commit 3640322

File tree

4 files changed

+54
-65
lines changed

4 files changed

+54
-65
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<build>
5757
<plugins>
5858
<!-- Plugin to download the matlab run scripts and keep it under class
59-
path -->
59+
resource folder -->
6060
<plugin>
6161
<groupId>com.googlecode.maven-download-plugin</groupId>
6262
<artifactId>download-maven-plugin</artifactId>

src/main/resources/com/mathworks/ci/RunMatlabCommandBuilder/help-matlabCommand.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Enter the command you want to run in MATLAB. If the command represents a MATLAB function or script, do not specify the file extension.<br>
33
<b>Examples:</b><br>
44
<b>Commands:</b> <br>cd c:\MATLAB\tests; runtests('IncludingSubfolder','true')<br>
5-
<b>Script or functions:</b><br>cd c:\MATLAB\myscripts; runMyScript(arg1, arg2...)<br>
5+
<b>Run a function:</b><br>cd c:\MATLAB\myscripts; runMyScript(arg1, arg2)<br>
66
<br>&nbsp;</br>
77
<b>Recommendation:</b>If you require a number of MATLAB commands to execute your build, consider writing a MATLAB script and executing the script file instead.<br>
88
<b>Note:</b> The build will fail if the execution of any MATLAB command causes an error.

src/test/java/com/mathworks/ci/RunMatlabCommandBuilderTest.java

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,9 @@ public void verifyBuildStepWithRunMatlab() throws Exception {
112112
Assert.assertTrue("Build step does not contain Run MATLAB Command option", found);
113113
}
114114

115-
/*
116-
* Test To verify MATLAB is launched with default arguments and with -batch when release
117-
* supports -batch
118-
*/
119-
120-
@Test
121-
public void verifyMATLABlaunchedWithDefaultArgumentsBatch() throws Exception {
122-
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
123-
project.getBuildWrappersList().add(this.buildWrapper);
124-
scriptBuilder.setMatlabCommand("pwd");
125-
project.getBuildersList().add(this.scriptBuilder);
126-
FreeStyleBuild build = project.scheduleBuild2(0).get();
127-
jenkins.assertLogContains("-batch", build);
128-
}
129115

130116
/*
131-
* Test To verify MATLAB is launched with default arguments and with -r when release supports -r
117+
* Test To verify MATLAB is launched using the default matlab runner script.
132118
*
133119
*/
134120

@@ -139,8 +125,8 @@ public void verifyMATLABlaunchedWithDefaultArguments() throws Exception {
139125
scriptBuilder.setMatlabCommand("pwd");
140126
project.getBuildersList().add(this.scriptBuilder);
141127
FreeStyleBuild build = project.scheduleBuild2(0).get();
142-
jenkins.assertLogContains("-r", build);
143-
jenkins.assertLogContains("eval(", build);
128+
jenkins.assertLogContains("run_matlab_command", build);
129+
jenkins.assertLogContains("pwd", build);
144130
}
145131

146132
/*
@@ -190,7 +176,7 @@ public void verifyBuildFailureWhenMatlabCommandPasses() throws Exception {
190176
}
191177

192178
/*
193-
* Test to verify Builder picks the exact command that user entered in batch mode
179+
* Test to verify Builder picks the exact command that user entered.
194180
*/
195181

196182
@Test
@@ -200,25 +186,10 @@ public void verifyBuildPicksTheCorretCommandBatch() throws Exception {
200186
scriptBuilder.setMatlabCommand("pwd");
201187
project.getBuildersList().add(this.scriptBuilder);
202188
FreeStyleBuild build = project.scheduleBuild2(0).get();
203-
jenkins.assertLogContains("-batch", build);
189+
jenkins.assertLogContains("run_matlab_command", build);
204190
jenkins.assertLogContains("pwd", build);
205191
}
206192

207-
/*
208-
* Test to verify Builder picks the exact command that user entered in -r mode
209-
*/
210-
211-
@Test
212-
public void verifyBuildPicksTheCorretCommandR() throws Exception {
213-
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2017a"));
214-
project.getBuildWrappersList().add(this.buildWrapper);
215-
scriptBuilder.setMatlabCommand("pwd");
216-
project.getBuildersList().add(this.scriptBuilder);
217-
FreeStyleBuild build = project.scheduleBuild2(0).get();
218-
jenkins.assertLogContains("-r", build);
219-
jenkins.assertLogContains("eval('pwd')", build);
220-
}
221-
222193
/*
223194
* Test to verify if MATALB scratch file is not generated in workspace for this builder.
224195
*/
@@ -249,4 +220,24 @@ public void verifyCommandSupportsEnvVar() throws Exception {
249220
FreeStyleBuild build = project.scheduleBuild2(0).get();
250221
jenkins.assertLogContains("pwd", build);
251222
}
223+
224+
/*
225+
* Test to verify if appropriate MATALB runner file is copied in workspace.
226+
*/
227+
@Test
228+
public void verifyMATLABrunnerFileGeneratedForAutomaticOption() throws Exception {
229+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
230+
project.getBuildWrappersList().add(this.buildWrapper);
231+
scriptBuilder.setMatlabCommand("pwd");
232+
project.getBuildersList().add(scriptBuilder);
233+
FreeStyleBuild build = project.scheduleBuild2(0).get();
234+
String runnerFile;
235+
if (!System.getProperty("os.name").startsWith("Win")) {
236+
runnerFile = "run_matlab_command.sh";
237+
}else {
238+
runnerFile = "run_matlab_command.bat";
239+
}
240+
File matlabRunner = new File(build.getWorkspace() + File.separator + runnerFile);
241+
Assert.assertTrue(matlabRunner.exists());
242+
}
252243
}

src/test/java/com/mathworks/ci/RunMatlabTestsBuilderTest.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public void verifyBuildStepWithMatlabTestBuilder() throws Exception {
118118
}
119119

120120
/*
121-
* Test To verify MATLAB is launched with default arguments and with -batch when release
122-
* supports -batch
121+
* Test To verify MATLAB is launched using run matlab script for version above R2018b
122+
*
123123
*/
124124

125125
@Test
@@ -129,12 +129,12 @@ public void verifyMATLABlaunchedWithDefaultArgumentsBatch() throws Exception {
129129
setAllTestArtifacts(false, this.testBuilder);
130130
project.getBuildersList().add(this.testBuilder);
131131
FreeStyleBuild build = project.scheduleBuild2(0).get();
132-
jenkins.assertLogContains("-batch", build);
132+
jenkins.assertLogContains("run_matlab_command", build);
133133
jenkins.assertLogContains("exit(runMatlabTests", build);
134134
}
135135

136136
/*
137-
* Test To verify MATLAB is launched with default arguments and with -r when release supports -r
137+
* Test To verify MATLAB is launched using run matlab script for version below R2018b
138138
* on windows
139139
*/
140140

@@ -145,8 +145,8 @@ public void verifyMATLABlaunchedWithDefaultArgumentsRWindows() throws Exception
145145
setAllTestArtifacts(false, this.testBuilder);
146146
project.getBuildersList().add(testBuilder);
147147
FreeStyleBuild build = project.scheduleBuild2(0).get();
148-
jenkins.assertLogContains("-r", build);
149-
jenkins.assertLogContains("runMatlabTests", build);
148+
jenkins.assertLogContains("run_matlab_command", build);
149+
jenkins.assertLogContains("exit(runMatlabTests", build);
150150
}
151151

152152
/*
@@ -224,7 +224,7 @@ public void verifyRunTestAutomaticallyIsDefault() throws Exception {
224224
setAllTestArtifacts(true, testBuilder);
225225
project.getBuildersList().add(this.testBuilder);
226226
FreeStyleBuild build = project.scheduleBuild2(0).get();
227-
jenkins.assertLogContains("-batch", build);
227+
jenkins.assertLogContains("run_matlab_command", build);
228228
jenkins.assertLogContains("\'PDFReport\',true,\'TAPResults\',true,"
229229
+ "\'JUnitResults\',true,\'SimulinkTestResults\',true,"
230230
+ "\'CoberturaCodeCoverage\',true,\'CoberturaModelCoverage\',true", build);
@@ -243,6 +243,26 @@ public void verifyMATLABscratchFileGeneratedForAutomaticOption() throws Exceptio
243243
File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m");
244244
Assert.assertTrue(matlabRunner.exists());
245245
}
246+
247+
/*
248+
* Test to verify if appropriate MATALB runner file is copied in workspace.
249+
*/
250+
@Test
251+
public void verifyMATLABrunnerFileGeneratedForAutomaticOption() throws Exception {
252+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
253+
project.getBuildWrappersList().add(this.buildWrapper);
254+
255+
project.getBuildersList().add(testBuilder);
256+
FreeStyleBuild build = project.scheduleBuild2(0).get();
257+
String runnerFile;
258+
if (!System.getProperty("os.name").startsWith("Win")) {
259+
runnerFile = "run_matlab_command.sh";
260+
}else {
261+
runnerFile = "run_matlab_command.bat";
262+
}
263+
File matlabRunner = new File(build.getWorkspace() + File.separator + runnerFile);
264+
Assert.assertTrue(matlabRunner.exists());
265+
}
246266

247267
/*
248268
* Test To verify UI displays Cobertura Warning message when unsupported MATLAB version used.
@@ -365,28 +385,6 @@ public void verifyInvalidMatlabWarningForSTMResults() throws Exception {
365385
.contains(TestMessage.getValue("Builder.invalid.matlab.root.warning")));
366386
}
367387

368-
/*
369-
* Test to verify if MatlabRoot field supports Jenkins environment variables.
370-
*
371-
*/
372-
373-
@Test
374-
public void verifyEnvVarSupportForMatlabRoot() throws Exception {
375-
EnvironmentVariablesNodeProperty prop = new EnvironmentVariablesNodeProperty();
376-
EnvVars var = prop.getEnvVars();
377-
var.put("MATLAB", "R2017a");
378-
jenkins.jenkins.getGlobalNodeProperties().add(prop);
379-
String mroot = getMatlabroot("R2017a");
380-
this.buildWrapper.setMatlabRootFolder(mroot.replace("R2017a", "$MATLAB"));
381-
project.getBuildWrappersList().add(this.buildWrapper);
382-
setAllTestArtifacts(false, testBuilder);
383-
project.getBuildersList().add(this.testBuilder);
384-
FreeStyleBuild build = project.scheduleBuild2(0).get();
385-
jenkins.assertLogContains(mroot, build);
386-
387-
}
388-
389-
390388
private void setAllTestArtifacts(boolean val, RunMatlabTestsBuilder testBuilder) {
391389
testBuilder.setCoberturaChkBx(val);
392390
testBuilder.setJunitChkBx(val);

0 commit comments

Comments
 (0)