From 8888394112f0d10307c721421ccc760bd6969321 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Tue, 5 Jan 2021 22:22:09 -0700 Subject: [PATCH] Skip honor refspec test if env is an empty value Fixes an array out of bounds when the environment variable being tested is an empty string. The test is checking that the variable is correctly expanded in the refspec but is not designed to test the case where the string is empty. It is possible to create a refspec that would work with the empty string value of the environment variable, but it is more complicated and does not add value to the scenarios evaluated by the test. The plugin bom tests of the most recent git plugin release are failing because the plugin bom test environment has the value of the environment variable `USER` as the empty string. --- .../git/extensions/impl/CloneOptionHonorRefSpecTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionHonorRefSpecTest.java b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionHonorRefSpecTest.java index a339dfc7ce..665ae289d3 100644 --- a/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionHonorRefSpecTest.java +++ b/src/test/java/hudson/plugins/git/extensions/impl/CloneOptionHonorRefSpecTest.java @@ -84,7 +84,7 @@ public void setUp() throws Exception { List logs = b.getLog(50); for (String line : logs) { if (line.startsWith(refSpecName + '=')) { - refSpecExpectedValue = line.split("=")[1]; + refSpecExpectedValue = line.substring(refSpecName.length() + 1, line.length()); } } @@ -103,6 +103,12 @@ public void setUp() throws Exception { @Test @Issue("JENKINS-56063") public void testRefSpecWithExpandedVariables() throws Exception { + if (refSpecExpectedValue == null || refSpecExpectedValue.isEmpty()) { + /* Test does not support an empty or null expected value. + Skip the test if the expected value is empty or null */ + System.out.println("*** testRefSpecWithExpandedVariables empty expected value for '" + refSpecName + "' ***"); + return; + } // Create initial commit final String commitFile1 = "commitFile1"; commit(commitFile1, johnDoe, "Commit in master branch");