Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-69668- Add possibility to add error messages to failed token macro #79

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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));
}
}
Loading