Skip to content

Commit

Permalink
SelfieGC now has a list of annotations which it supports for marking …
Browse files Browse the repository at this point in the history
…a test as existing.
  • Loading branch information
nedtwigg committed Dec 19, 2023
1 parent 538fe50 commit 17aa070
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ import java.nio.file.Files
import kotlin.io.path.name
import org.junit.jupiter.api.Test

/** Search for any test annotation classes which are present on the classpath. */
private val testAnnotations =
listOf(
"org.junit.jupiter.api.Test", // junit5,
"org.junit.Test" // junit4
)
.mapNotNull {
try {
Class.forName(it).asSubclass(Annotation::class.java)
} catch (e: ClassNotFoundException) {
null
}
}

/**
* Searches the whole snapshot directory, finds all the `.ss` files, and prunes any which don't have
* matching test files anymore.
Expand All @@ -41,7 +55,9 @@ internal fun findStaleSnapshotFiles(layout: SnapshotFileLayout): List<String> {
}
private fun classExistsAndHasTests(key: String): Boolean {
return try {
Class.forName(key).declaredMethods.any { it.isAnnotationPresent(Test::class.java) }
Class.forName(key).methods.any { method ->
testAnnotations.any { method.isAnnotationPresent(it) }
}
} catch (e: ClassNotFoundException) {
false
}
Expand Down

0 comments on commit 17aa070

Please sign in to comment.