Skip to content
Permalink
Browse files

[JENKINS-45575, JENKINS-49679] Test multiple assignment CPS fixes

  • Loading branch information...
abayer committed Feb 26, 2018
1 parent b3d7ea3 commit 9a82584c267f84a4dce925a69d45ad6018196a0a
Showing with 43 additions and 1 deletion.
  1. +1 −1 pom.xml
  2. +42 −0 src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java
@@ -68,7 +68,7 @@
<git-plugin.version>3.1.0</git-plugin.version>
<workflow-support-plugin.version>2.17</workflow-support-plugin.version>
<scm-api-plugin.version>2.0.8</scm-api-plugin.version>
<groovy-cps.version>1.22</groovy-cps.version>
<groovy-cps.version>1.23-20180226.150651-1</groovy-cps.version> <!-- TODO: Change to release -->
<jenkins-test-harness.version>2.33</jenkins-test-harness.version>
</properties>
<dependencies>
@@ -423,4 +423,46 @@ public void variableDecl() throws Exception {
p.setDefinition(new CpsFlowDefinition("String foo", true));
jenkins.buildAndAssertSuccess(p);
}

@Issue("JENKINS-45575")
@Test
public void multipleAssignmentInSandbox() throws Exception {
WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p");
job.setDefinition(new CpsFlowDefinition("def (a, b) = ['first', 'second']\n" +
"def c, d\n" +
"(c, d) = ['third', 'fourth']\n" +
"assert a+b+c+d == 'firstsecondthirdfourth'\n", true));
jenkins.buildAndAssertSuccess(job);
}

@Issue("JENKINS-45575")
@Test
public void multipleAssignmentOutsideSandbox() throws Exception {
WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p");
job.setDefinition(new CpsFlowDefinition("def (a, b) = ['first', 'second']\n" +
"def c, d\n" +
"(c, d) = ['third', 'fourth']\n" +
"assert a+b+c+d == 'firstsecondthirdfourth'\n", false));
jenkins.buildAndAssertSuccess(job);
}

@Issue("JENKINS-49679")
@Test
public void multipleAssignmentFunctionCalledOnce() throws Exception {
WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p");
job.setDefinition(new CpsFlowDefinition("alreadyRun = false\n" +
"def getAandB() {\n" +
" if (!alreadyRun) {\n" +
" alreadyRun = true\n" +
" return ['first', 'second']\n" +
" } else {\n" +
" return ['bad', 'worse']\n" +
" }\n" +
"}\n" +
"def (a, b) = getAandB()\n" +
"def c, d\n" +
"(c, d) = ['third', 'fourth']\n" +
"assert a+b+c+d == 'firstsecondthirdfourth'\n", true));
jenkins.buildAndAssertSuccess(job);
}
}

0 comments on commit 9a82584

Please sign in to comment.
You can’t perform that action at this time.