Skip to content

Commit

Permalink
Add possibility to add error messages to failed token macro (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
asimell authored Nov 15, 2024
1 parent 0996b03 commit 11c55f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
@Extension(optional = true)
public class RobotFailedCasesTokenMacro extends DataBoundTokenMacro {

@Parameter
public boolean addErrorMessages;

@Override
public String evaluate(AbstractBuild<?, ?> context, TaskListener listener,
String macroName) throws MacroEvaluationException, IOException,
Expand All @@ -35,6 +38,9 @@ public String evaluate(Run<?, ?> context, FilePath workspace, TaskListener liste
String newline = "";
for (RobotCaseResult failedCase : result.getAllFailedCases()){
builder.append(newline).append(failedCase.getRelativePackageName(result));
if (addErrorMessages && failedCase.getErrorMsg() != null && !failedCase.getErrorMsg().isEmpty()) {

Check warning on line 41 in src/main/java/hudson/plugins/robot/tokens/RobotFailedCasesTokenMacro.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 41 is only partially covered, 2 branches are missing
builder.append(": ").append(failedCase.getErrorMsg());
}
newline = "\n";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public void setUp(){

RobotCaseResult case1 = Mockito.mock(RobotCaseResult.class);
Mockito.when(case1.getRelativePackageName(result)).thenReturn("Failcases.subcases.Failure1");

Mockito.when(case1.getErrorMsg()).thenReturn("Case1 failed");

RobotCaseResult case2 = Mockito.mock(RobotCaseResult.class);
Mockito.when(case2.getRelativePackageName(result)).thenReturn("Morefails.Failure2");

Mockito.when(case2.getErrorMsg()).thenReturn("Case2 failed");

failedList.add(case1);
failedList.add(case2);

Expand All @@ -52,7 +54,12 @@ public void testAcceptsName(){
assertTrue(new RobotFailedCasesTokenMacro().acceptsMacroName(macroName));
}

public void testTokenConversion() throws MacroEvaluationException, IOException, InterruptedException{
public void testTokenConversionWithoutMessages() throws MacroEvaluationException, IOException, InterruptedException{
assertEquals("Failcases.subcases.Failure1\nMorefails.Failure2",token.evaluate(build, listener, macroName));
}

public void testTokenConversionWithMessages() throws MacroEvaluationException, IOException, InterruptedException{
token.addErrorMessages = true;
assertEquals("Failcases.subcases.Failure1: Case1 failed\nMorefails.Failure2: Case2 failed",token.evaluate(build, listener, macroName));
}
}

0 comments on commit 11c55f8

Please sign in to comment.