Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(failure): Show location as nested descriptions #158

Merged
merged 1 commit into from
Mar 2, 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 @@ -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
Loading