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

Commit c837285

Browse files
author
Nikhil Bhoski
committed
Tests modified and copyright added.
1 parent 5bbcb58 commit c837285

File tree

10 files changed

+87
-31
lines changed

10 files changed

+87
-31
lines changed

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

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

3+
/**
4+
* Copyright 2019-2020 The MathWorks, Inc.
5+
*
6+
*/
7+
38
import java.io.IOException;
49
import org.jenkinsci.plugins.workflow.steps.StepContext;
510
import org.jenkinsci.plugins.workflow.steps.StepExecution;

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

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

3+
/**
4+
* Copyright 2019-2020 The MathWorks, Inc.
5+
*
6+
*/
7+
38
import java.util.Set;
49
import org.jenkinsci.plugins.workflow.steps.Step;
510
import org.jenkinsci.plugins.workflow.steps.StepContext;

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package com.mathworks.ci;
22

3+
/**
4+
* Copyright 2019-2020 The MathWorks, Inc.
5+
*
6+
*/
7+
38
import java.util.ArrayList;
4-
import java.util.Arrays;
9+
import java.util.HashMap;
510
import java.util.List;
11+
import java.util.Map;
612
import java.util.Set;
713
import org.apache.commons.io.FilenameUtils;
814
import org.jenkinsci.plugins.workflow.steps.Step;
@@ -12,7 +18,6 @@
1218
import org.kohsuke.stapler.DataBoundConstructor;
1319
import org.kohsuke.stapler.DataBoundSetter;
1420
import com.google.common.collect.ImmutableSet;
15-
import com.mathworks.ci.RunMatlabTestsBuilder.PdfArtifact;
1621
import hudson.EnvVars;
1722
import hudson.Extension;
1823
import hudson.FilePath;
@@ -127,26 +132,30 @@ public String constructCommandForTest(String inputArguments) {
127132

128133

129134
private String getInputArgs() {
130-
List<String> inputArgs = new ArrayList<>();
131-
addInputArgs(PDF_REPORT_PATH, getTestResultsPdf(),inputArgs);
132-
addInputArgs(TAP_RESULTS_PATH, getTestResultsTAP(), inputArgs);
133-
addInputArgs(JUNIT_RESULTS_PATH, getTestResultsJUnit(), inputArgs);
134-
addInputArgs(STM_RESULTS_PATH, getTestResultsSimulinkTest(), inputArgs);
135-
addInputArgs(COBERTURA_CODE_COVERAGE_PATH,
136-
getCodeCoverageCobertura(), inputArgs);
137-
addInputArgs(COBERTURA_MODEL_COVERAGE_PATH,
138-
getModelCoverageCobertura(), inputArgs);
139-
135+
final List<String> inputArgs = new ArrayList<>();
136+
final Map<String, String> args = getMatlabArgs();
137+
138+
args.forEach((key, val) -> {
139+
if (val != null) {
140+
inputArgs.add("'" + key + "'" + "," + "'" + val + "'");
141+
}
142+
});
143+
140144
if (inputArgs.isEmpty()) {
141-
return "";
142-
}
143-
144-
return String.join(",", inputArgs);
145+
return "";
146+
}
147+
148+
return String.join(",", inputArgs);
145149
}
146150

147-
private void addInputArgs(String reportName, String reportPath, List<String> inputArgs) {
148-
if (reportPath != null) {
149-
inputArgs.add("'" + reportName + "'" + "," + "'" + reportPath + "'");
150-
}
151+
private Map<String, String> getMatlabArgs() {
152+
final Map<String, String> args = new HashMap<String, String>();
153+
args.put(PDF_REPORT_PATH, getTestResultsPdf());
154+
args.put(TAP_RESULTS_PATH, getTestResultsTAP());
155+
args.put(JUNIT_RESULTS_PATH, getTestResultsJUnit());
156+
args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest());
157+
args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura());
158+
args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura());
159+
return args;
151160
}
152161
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
package com.mathworks.ci;
2+
/**
3+
* Copyright 2019-2020 The MathWorks, Inc.
4+
*
5+
*/
26

37
import java.io.IOException;
48
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;

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

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

3+
/**
4+
* Copyright 2019-2020 The MathWorks, Inc.
5+
*
6+
*/
7+
38
import java.util.Set;
49
import org.jenkinsci.plugins.workflow.steps.StepContext;
510
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.mathworks.ci;
22

3+
/**
4+
* Copyright 2019-2020 The MathWorks, Inc.
5+
*
6+
*/
7+
38
import java.io.IOException;
49
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
510
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
@@ -89,4 +94,22 @@ public void verifyArtifactParameters() throws Exception {
8994
j.assertLogNotContains("SimulinkTestResultsPath", build);
9095
j.assertLogNotContains("CoberturaModelCoveragePath", build);
9196
}
97+
98+
/*
99+
* Verify runMatlabTests runs with empty parameters when nothing no artifact selected
100+
*/
101+
102+
@Test
103+
public void verifyEmptyParameter() throws Exception {
104+
project.setDefinition(new CpsFlowDefinition(
105+
"node {runMATLABTests()}", true));
106+
WorkflowRun build = project.scheduleBuild2(0).get();
107+
j.assertLogContains("runMatlabTests()", build);
108+
j.assertLogNotContains("PDFReportPath", build);
109+
j.assertLogNotContains("TAPResultsPath", build);
110+
j.assertLogNotContains("JUnitResultsPath", build);
111+
j.assertLogNotContains("CoberturaCodeCoveragePath", build);
112+
j.assertLogNotContains("SimulinkTestResultsPath", build);
113+
j.assertLogNotContains("CoberturaModelCoveragePath", build);
114+
}
92115
}

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

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

3+
/**
4+
* Copyright 2019-2020 The MathWorks, Inc.
5+
*
6+
*/
7+
38
import java.util.ArrayList;
49
import java.util.Arrays;
510
import java.util.Collections;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
package com.mathworks.ci;
2+
/**
3+
* Copyright 2019-2020 The MathWorks, Inc.
4+
*
5+
*/
26

37
import java.io.IOException;
48
import org.jenkinsci.plugins.workflow.steps.StepContext;
@@ -8,13 +12,13 @@
812
import hudson.Launcher.ProcStarter;
913
import hudson.model.TaskListener;
1014

11-
public class TestStepExecution extends MatlabStepExecution{
15+
public class TestStepExecution extends MatlabStepExecution {
1216

1317
public TestStepExecution(StepContext context, String command, boolean copyScratchFile) {
1418
super(context, command, copyScratchFile);
15-
19+
1620
}
17-
21+
1822
@Override
1923
public ProcStarter getProcessToRunMatlabCommand(FilePath workspace, Launcher launcher,
2024
TaskListener listener, EnvVars envVars, String matlabCommand, String uniqueName)
@@ -29,20 +33,16 @@ public ProcStarter getProcessToRunMatlabCommand(FilePath workspace, Launcher lau
2933
.cmds(tmpDir + "/" + runnerScriptName, matlabCommand).stdout(listener);
3034

3135
// Copy runner .sh for linux platform in workspace.
32-
copyFileInWorkspace("run_matlab_command_test.sh", runnerScriptName,
33-
targetWorkspace);
36+
copyFileInWorkspace("run_matlab_command_test.sh", runnerScriptName, targetWorkspace);
3437
} else {
3538
final String runnerScriptName = uniqueName + "\\run_matlab_command_test.bat";
3639
launcher = launcher.decorateByPrefix("cmd.exe", "/C");
3740
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars)
3841
.cmds(tmpDir + "\\" + runnerScriptName, "\"" + matlabCommand + "\"")
3942
.stdout(listener);
4043
// Copy runner.bat for Windows platform in workspace.
41-
copyFileInWorkspace("run_matlab_command_test.bat", runnerScriptName,
42-
targetWorkspace);
44+
copyFileInWorkspace("run_matlab_command_test.bat", runnerScriptName, targetWorkspace);
4345
}
4446
return matlabLauncher;
4547
}
46-
47-
4848
}

src/test/resources/run_matlab_command_test.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rem Copyright 2018 The MathWorks, Inc.
1+
rem Copyright 2020 The MathWorks, Inc.
22

33
echo off
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
#Copyright 2018 The MathWorks, Inc.
3+
#Copyright 2020 The MathWorks, Inc.
44

55
echo "tester_started"
66
echo $1

0 commit comments

Comments
 (0)