Skip to content

Commit

Permalink
extract and add tags to failed init descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
giurim committed May 11, 2022
1 parent f4a979c commit 81e819f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/co/helmethair/scalatest/runtime/Discovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestTag;
import org.scalatest.Suite;
import org.scalatest.TagAnnotation;
import scala.Option;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand All @@ -23,15 +25,16 @@ public ScalatestEngineDescriptor discover(ScalatestEngineDescriptor engineDescri
Suite suite = ((Suite) classLoader.loadClass(c.getName()).newInstance());
addSuite(suite, engineDescriptor);
} catch (Throwable e) {
addFailedInit(e, c.getName(), engineDescriptor);
addFailedInit(e, c, engineDescriptor);
}
});

return engineDescriptor;
}

private void addFailedInit(Throwable cause, String className, TestDescriptor parent) {
ScalatestFailedInitDescriptor failed = new ScalatestFailedInitDescriptor(cause, className);
private void addFailedInit(Throwable cause, Class<? extends Suite> clazz, TestDescriptor parent) {
String className = clazz.getName();
ScalatestFailedInitDescriptor failed = new ScalatestFailedInitDescriptor(cause, className, extractTags(clazz));
linkChild(parent, failed);
}

Expand All @@ -43,7 +46,7 @@ private void addSuite(Suite suite, TestDescriptor parent) {
try {
addSuite(scalatestNestedSuite, scalatestSuiteDescriptor);
} catch (Throwable e) {
addFailedInit(e, scalatestNestedSuite.getClass().getName(), scalatestSuiteDescriptor);
addFailedInit(e, scalatestNestedSuite.getClass(), scalatestSuiteDescriptor);
}
});
}
Expand All @@ -58,6 +61,13 @@ private void addTests(ScalatestSuiteDescriptor suite, Set<String> testNames) {
linkChild(suite, new ScalatestTestDescriptor(suite, testName, getTags(suite.getScalasuite(), testName))));
}

private Set<TestTag> extractTags(Class<? extends Suite> clazz) {
return Arrays.stream(clazz.getAnnotations()).filter(a ->
a.annotationType().isAnnotationPresent(TagAnnotation.class)
).map(a -> TestTag.create(a.annotationType().getName()))
.collect(Collectors.toSet());
}

private Set<TestTag> getTags(Suite scalasuite, String testName) {
Option<scala.collection.immutable.Set<String>> tagSetOption = scalasuite.tags().get(testName);
if (tagSetOption.isDefined()) {
Expand Down

0 comments on commit 81e819f

Please sign in to comment.