Skip to content

Commit

Permalink
feat(failure): Show location as nested descriptions (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion authored Mar 2, 2024
1 parent 80f97ca commit 0b9899c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static String locationOf(final @Nullable TestDescriptor desc, final int
if (desc != null && i >= 0) {
final var concatText = text.isEmpty()
? desc.getDisplayName()
: desc.getDisplayName().concat(" => ").concat(text);
: desc.getDisplayName().concat("\n").concat(" ".repeat(i + 1)).concat(text);

return locationOf(desc.getParent(), i - 1, concatText);
}
Expand Down
44 changes: 29 additions & 15 deletions src/test/java/io/github/joselion/prettyjupiter/lib/FailureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;

import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.gradle.testfixtures.ProjectBuilder;
Expand Down Expand Up @@ -72,22 +74,34 @@

@Nested class location {
@TestFactory Stream<DynamicTest> returns_the_location_based_on_the_descriptor_level() {
return Map.of(
0, "",
1, "",
2, "Test description 1",
3, "Test description 1 => Test description 2",
4, "Test description 1 => Test description 2 => Test description 3"
)
.entrySet()
.stream()
.map(entry ->
dynamicTest("[level: %d]".formatted(entry.getKey()), () -> {
final var failure = Failure.of(new Exception(), Helpers.descriptorOf(entry.getKey()), EXT);

assertThat(failure.location()).isEqualTo(entry.getValue());
})
final var results = List.of(
"",
"",
"Test description 1",
"""
Test description 1
Test description 2\
""",
"""
Test description 1
Test description 2
Test description 3\
""",
"""
Test description 1
Test description 2
Test description 3
Test description 4\
"""
);

return IntStream.range(0, results.size())
.mapToObj(i -> dynamicTest("[level: %d]".formatted(i), () -> {
final var failure = Failure.of(new Exception(), Helpers.descriptorOf(i), EXT);
final var result = results.get(i);

assertThat(failure.location()).isEqualTo(result);
}));
}
}

Expand Down

0 comments on commit 0b9899c

Please sign in to comment.