Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-45575, JENKINS-49679] Test multiple assignment CPS fixes
  • Loading branch information
abayer committed Feb 26, 2018
1 parent b3d7ea3 commit 9a82584
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down
Expand Up @@ -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.