Skip to content

Commit

Permalink
Fix handling for unknown JUnit segment types (#128)
Browse files Browse the repository at this point in the history
Necessary to get sbt-jupiter-interface working with Kotlin's Kotest com-lihaoyi/mill#4048

Rather than skipping the entire unknown segment types, we filter out `"suite"` segments explicitly (which appears to be what we actually need to do, e.g. in https://github.com/sbt/sbt-jupiter-interface/blob/43918484453f25ae8e852fae48d54d84be77e0fe/src/library/src/main/java/com/github/sbt/junit/jupiter/internal/event/TaskName.java#L123) and leave unknown segment types as space-separated. We perform a final `.trim` on the generated string to ensure any leading spaces are removed, since when generating the strings for each segment we do not know whether it will be the leading segment or not

This appears to have been broken in https://github.com/sbt/sbt-jupiter-interface/pull/126/files, where returning `null` caused the entire test identifier to not render

It's not entirely clear to me why we filter out the `suite`  segments to begin with, but given that we do this seems like the better way to do it
  • Loading branch information
lihaoyi authored Dec 2, 2024
1 parent 4391848 commit 02e4226
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,22 @@ public String format() {
.reduce((first, last) -> last)
.orElse(null);

return path.stream().map(this::toName).filter(Objects::nonNull).collect(Collectors.joining());
return path.stream()
.map(this::toName)
.filter(Objects::nonNull)
.collect(Collectors.joining())
.trim();
}

private List<TestIdentifier> getPath(TestPlan testPlan, TestIdentifier identifier) {

List<TestIdentifier> result = new ArrayList<>();

do {
if (identifier.getSource().isPresent()) {
// If there is only one segment, do not filter it out even
// if the source is not present, since we need to show something
boolean isOnlySegment = (result.isEmpty());
if (identifier.getSource().isPresent() || isOnlySegment) {
result.add(identifier);
}
identifier = testPlan.getParent(identifier).orElse(null);
Expand Down Expand Up @@ -385,9 +392,12 @@ private String toName(TestIdentifier identifier, Segment segment) {
case "test-template-invocation":
name = colorTheme.container().format(":" + segment.getValue());
break;
default:
case "suite": // Don't show junit5 suite as part of name
name = null;
break;
default:
name = " " + segment.getValue();
break;
}

if (options.isTypesEnabled()) {
Expand Down

0 comments on commit 02e4226

Please sign in to comment.