mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Fix test class finding.
This commit is contained in:
parent
bb6f9e115f
commit
31e6576faf
1 changed files with 18 additions and 3 deletions
|
@ -7,6 +7,7 @@ import com.beust.kobalt.maven.IClasspathDependency
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
|
||||||
abstract class GenericTestRunner(open val project: Project, open val classpath: List<IClasspathDependency>) {
|
abstract class GenericTestRunner(open val project: Project, open val classpath: List<IClasspathDependency>) {
|
||||||
abstract val mainClass: String
|
abstract val mainClass: String
|
||||||
|
@ -14,11 +15,25 @@ abstract class GenericTestRunner(open val project: Project, open val classpath:
|
||||||
|
|
||||||
protected fun findTestClasses(): List<String> {
|
protected fun findTestClasses(): List<String> {
|
||||||
val path = KFiles.joinDir(project.directory, project.buildDirectory!!, KFiles.TEST_CLASSES_DIR)
|
val path = KFiles.joinDir(project.directory, project.buildDirectory!!, KFiles.TEST_CLASSES_DIR)
|
||||||
val result = KFiles.findRecursively(File(path),
|
val result = KFiles.findRecursively(File(path), arrayListOf(File(".")), {
|
||||||
arrayListOf(File("."))) { file -> file.endsWith("Test.class")
|
file -> file.endsWith(".class")
|
||||||
}.map {
|
}).map {
|
||||||
it.replace("/", ".").replace("\\", ".").replace(".class", "").substring(2)
|
it.replace("/", ".").replace("\\", ".").replace(".class", "").substring(2)
|
||||||
|
}.filter {
|
||||||
|
try {
|
||||||
|
// Only keep classes with a parameterless constructor
|
||||||
|
val urls = arrayOf(File(path).toURI().toURL()) +
|
||||||
|
classpath.map { it.jarFile.get().toURI().toURL() }
|
||||||
|
val classLoader = URLClassLoader(urls)
|
||||||
|
classLoader.loadClass(it).getConstructor()
|
||||||
|
true
|
||||||
|
} catch(ex: Exception) {
|
||||||
|
log(2, "Skipping non test class $it: ${ex.message}")
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log(2, "Found ${result.size} test classes")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue