Skip to content

Commit b2947af

Browse files
committed
Add '--all' argument option
1 parent 8fc1e0f commit b2947af

File tree

8 files changed

+438
-7
lines changed

8 files changed

+438
-7
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,56 @@ The output will look something like:
130130
at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
131131
...
132132
```
133+
134+
### All Failures
135+
136+
To display all failures, use the `--all` option:
137+
138+
```console
139+
./bld reporter --all
140+
```
141+
142+
```console
143+
--------------------------------------------------
144+
[1] com.example.ExampleTests
145+
--------------------------------------------------
146+
147+
[1.1] Test: verifyFail(String)[1]
148+
- Name: [1] foo
149+
- Type: org.opentest4j.AssertionFailedError
150+
- Message:
151+
expected: <foo> but was: <Hello World!>
152+
- Time: 0.008s
153+
154+
[1.2] Test: verifyFail(String)[2]
155+
- Name: [2] bar
156+
- Type: org.opentest4j.AssertionFailedError
157+
- Message:
158+
expected: <bar> but was: <Hello World!>
159+
- Time: 0.001s
160+
161+
[1.3] Test: verifyHelloFoo()
162+
- Name: verifyHelloFoo()
163+
- Type: org.opentest4j.AssertionFailedError
164+
- Message:
165+
expected: <Hello Foo!> but was: <Hello World!>
166+
- Time: 0.001s
167+
168+
--------------------------------------------------
169+
[2] com.example.MoreTests
170+
--------------------------------------------------
171+
172+
[2.1] Test: verifyMore(String)[3]
173+
- Name: [3] qux
174+
- Type: org.opentest4j.AssertionFailedError
175+
- Message:
176+
expected: <true> but was: <false>
177+
- Time: 0.0s
178+
179+
[2.2] Test: verifyMore(String)[4]
180+
- Name: [4] quux
181+
- Type: org.opentest4j.AssertionFailedError
182+
- Message:
183+
expected: <true> but was: <false>
184+
- Time: 0.0s
185+
```

example/.github/workflows/bld.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727

2828
- name: Run reporter
2929
if: ${{ failure() }}
30-
run: ./bld reporter
30+
run: ./bld reporter -all

example/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Compile and test the project, then run the reporter
1+
## Compile and test the project, then display the reporter summary
22

33
```console
44
./bld compile test
@@ -16,3 +16,9 @@
1616
```console
1717
./bld reporter --i=1.2
1818
```
19+
20+
## Display all failures
21+
22+
```console
23+
./bld reporter --all
24+
```

src/main/java/rife/bld/extension/JUnitReporterOperation.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
*/
4242
public class JUnitReporterOperation extends AbstractProcessOperation<JUnitReporterOperation> {
4343
private static final Pattern ARG_MATCH_PATTERN = Pattern.compile("^--(i|index)=(\\d+(?:\\.\\d+)?)$");
44+
private static final String ARG_ALL = "--all";
4445
private static final Logger LOGGER = Logger.getLogger(JUnitReporterOperation.class.getName());
4546
private String argIndex_;
47+
private boolean isPrintAll_;
4648
private boolean failOnSummary_;
4749
private BaseProject project_;
4850
private Path reportFile_;
@@ -64,13 +66,18 @@ public void execute() throws ExitStatusException {
6466
LOGGER.log(Level.SEVERE, "A report file is required to run this operation.");
6567
}
6668
} else {
67-
6869
try {
6970
var groupedFailures =
7071
JUnitXmlParser.extractTestFailuresGrouped(reportFile_.toString());
7172

7273
if (!groupedFailures.isEmpty()) {
73-
if (argIndex_ != null) {
74+
if (isPrintAll_) {
75+
for (var i = 0; i < groupedFailures.size(); i++) {
76+
ReportPrinter.printDetails(String.valueOf(i + 1), groupedFailures);
77+
}
78+
status = EXIT_SUCCESS;
79+
}
80+
else if (argIndex_ != null) {
7481
ReportPrinter.printDetails(argIndex_, groupedFailures);
7582
status = EXIT_SUCCESS;
7683
} else {
@@ -136,11 +143,16 @@ public JUnitReporterOperation fromProject(BaseProject project) {
136143
var args = project.arguments();
137144
if (!args.isEmpty()) {
138145
var arg = args.get(0);
146+
if (ARG_ALL.equals(arg)) {
147+
isPrintAll_ = true;
148+
args.remove(0);
149+
} else {
139150
var matcher = ARG_MATCH_PATTERN.matcher(arg);
140151
if (matcher.matches()) {
141152
args.remove(0);
142153
argIndex_ = matcher.group(2);
143154
}
155+
}
144156
}
145157
}
146158
return this;

src/main/java/rife/bld/extension/junitreporter/ReportPrinter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ public static void printFailures(TestClassFailures failures, int groupIndex) {
195195
* @param title the title to print
196196
*/
197197
public static void printHeader(String title) {
198-
System.out.println();
199198
var separatorLength = Math.max(title.length(), 50);
200199
var separator = "-".repeat(separatorLength);
201200

src/test/java/rife/bld/extension/JUnitReporterOperationTest.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ void failOnSummaryWhenTrue() {
168168
@Nested
169169
@DisplayName("From Project Tests")
170170
class FromProjectTests {
171+
@Test
172+
void argAllIsSetFromProjectArguments() {
173+
var mockedProject = mock(BaseProject.class);
174+
when(mockedProject.arguments()).thenReturn(new ArrayList<>(List.of("--all")));
175+
when(mockedProject.buildDirectory()).thenReturn(new File("build"));
176+
177+
var operation = new JUnitReporterOperation().fromProject(mockedProject);
178+
assertThat(operation).extracting("isPrintAll_").isEqualTo(true);
179+
}
180+
171181
@Test
172182
void argIndexIsRemovedFromProjectArgumentsAfterUse() {
173183
var mockedProject = mock(BaseProject.class);
@@ -400,6 +410,62 @@ void executeThrowsUnexpectedRuntimeExceptionWithSilentMode() {
400410
}
401411
}
402412

413+
@Test
414+
void executeWithAllArgument() {
415+
var mockedProject = mock(BaseProject.class);
416+
when(mockedProject.arguments()).thenReturn(new ArrayList<>(List.of("--all")));
417+
when(mockedProject.buildDirectory()).thenReturn(new File("src/test/resources"));
418+
419+
var operation = new JUnitReporterOperation().fromProject(mockedProject);
420+
421+
var outContent = new ByteArrayOutputStream();
422+
System.setOut(new PrintStream(outContent));
423+
424+
assertThatCode(operation::execute).doesNotThrowAnyException();
425+
426+
var expectedOutput = String.format(
427+
"--------------------------------------------------%n" +
428+
"[1] com.example.ExampleTests%n" +
429+
"--------------------------------------------------%n%n" +
430+
"[1.1] Test: verifyFail(String)[1]%n" +
431+
" - Name: [1] foo%n" +
432+
" - Type: org.opentest4j.AssertionFailedError%n" +
433+
" - Message:%n" +
434+
" expected: <foo> but was: <Hello World!>%n" +
435+
" - Time: 0.009s%n" +
436+
"%n[1.2] Test: verifyFail(String)[2]%n" +
437+
" - Name: [2] bar%n" +
438+
" - Type: org.opentest4j.AssertionFailedError%n" +
439+
" - Message:%n" +
440+
" expected: <bar> but was: <Hello World!>%n" +
441+
" - Time: 0.001s%n%n" +
442+
"[1.3] Test: verifyHelloFoo()%n" +
443+
" - Name: verifyHelloFoo()%n" +
444+
" - Type: org.opentest4j.AssertionFailedError%n" +
445+
" - Message:%n" +
446+
" expected: <Hello Foo!> but was: <Hello World!>%n" +
447+
" - Time: 0.001s%n%n" +
448+
"--------------------------------------------------%n" +
449+
"[2] com.example.MoreTests%n" +
450+
"--------------------------------------------------%n%n" +
451+
"[2.1] Test: verifyMore(String)[3]%n" +
452+
" - Name: [3] qux%n" +
453+
" - Type: org.opentest4j.AssertionFailedError%n" +
454+
" - Message:%n" +
455+
" expected: <true> but was: <false>%n" +
456+
" - Time: 0.001s%n%n" +
457+
"[2.2] Test: verifyMore(String)[4]%n" +
458+
" - Name: [4] quux%n" +
459+
" - Type: org.opentest4j.AssertionFailedError%n" +
460+
" - Message:%n" +
461+
" expected: <true> but was: <false>%n" +
462+
" - Time: 0.0s%n%n"
463+
);
464+
assertThat(outContent.toString()).isEqualTo(expectedOutput);
465+
466+
System.setOut(System.out);
467+
}
468+
403469
@Test
404470
void executeWithInvalidFailureIndex() {
405471
var mockedProject = mock(BaseProject.class);

src/test/java/rife/bld/extension/junitreporter/ReportPrinterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void printSummaryWithEmptyGroupedFailures() {
324324
ReportPrinter.printSummary(groupedFailures);
325325

326326
var expectedOutput = String.format(
327-
"%n--------------------------------------------------%n" +
327+
"--------------------------------------------------%n" +
328328
"JUnit Failures Summary%n" +
329329
"--------------------------------------------------%n%n" +
330330
"%nTotal Failures: 0%n"
@@ -354,7 +354,7 @@ void printSummaryWithNonEmptyGroupedFailures() {
354354
ReportPrinter.printSummary(groupedFailures);
355355

356356
var expectedOutput = String.format(
357-
"%n--------------------------------------------------%n" +
357+
"--------------------------------------------------%n" +
358358
"JUnit Failures Summary%n" +
359359
"--------------------------------------------------%n%n" +
360360
"[1] TestClass1 (2 failures, 0.303s)%n" +

0 commit comments

Comments
 (0)