Skip to content
Browse files

Add tests exploring JENKINS-6856 - token macro expansion

BranchSpec does not seem to honor token macros. For example,
  $GIT_BRANCH matches as expected
  ${GIT_BRANCH} matches as expected
  ${GIT_BRANCH,fullName=False} does not match
  ${GIT_BRANCH,fullName=True} does not match

I expected either all of them to match as expected (token macro expansion
was being applied), or none of them to match (no variable expansion and
no token macro expansion).  As far as I can tell, variable expansion is
being applied, but token macro expansion is not being applied.
  • Loading branch information
MarkEWaite committed Oct 12, 2015
1 parent c84fc2c commit 91a1ffc3a6030e8d74fe463edff13d7f1f08fd41
Showing with 57 additions and 0 deletions.
  1. +57 −0 src/test/java/hudson/plugins/git/
@@ -4,6 +4,7 @@
import java.util.HashMap;
import static org.junit.Assert.*;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

public class TestBranchSpec {
@@ -171,4 +172,60 @@ public void testUsesJavaPatternWithRepetition() {

private EnvVars createEnvMap(String key, String value) {
HashMap<String, String> envMap = new HashMap<String, String>();
envMap.put(key, value);
return new EnvVars(envMap);

/* BranchSpec does not seem to honor token macros. For example,
* $GIT_BRANCH matches as expected
* ${GIT_BRANCH} matches as expected
* ${GIT_BRANCH,fullName=False} does not match
* ${GIT_BRANCH,fullName=True} does not match
public void testUsesEnvValueWithBraces() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withBraces = new BranchSpec("${GIT_BRANCH}");
assertTrue(withBraces.matches("refs/heads/origin/master", env));
assertTrue(withBraces.matches("origin/master", env));
assertFalse(withBraces.matches("master", env));

public void testUsesEnvValueWithoutBraces() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withoutBraces = new BranchSpec("$GIT_BRANCH");
assertTrue(withoutBraces.matches("refs/heads/origin/master", env));
assertTrue(withoutBraces.matches("origin/master", env));
assertFalse(withoutBraces.matches("master", env));

public void testUsesEnvValueWithToken() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withToken = new BranchSpec("${GIT_BRANCH,fullName=True}");
assertFalse(withToken.matches("refs/heads/origin/master", env));
assertFalse(withToken.matches("origin/master", env));
assertFalse(withToken.matches("master", env));

public void testUsesEnvValueWithTokenFalse() {
EnvVars env = createEnvMap("GIT_BRANCH", "origin/master");

BranchSpec withTokenFalse = new BranchSpec("${GIT_BRANCH,fullName=false}");
assertFalse(withTokenFalse.matches("refs/heads/origin/master", env));
assertFalse(withTokenFalse.matches("origin/master", env));
assertFalse(withTokenFalse.matches("master", env));

0 comments on commit 91a1ffc

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