1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Pass TaskResult better in tests.

This commit is contained in:
Cedric Beust 2015-11-18 23:16:13 -08:00
parent 521dfc327b
commit 2746f57b9a
2 changed files with 36 additions and 26 deletions

View file

@ -36,30 +36,38 @@ abstract class GenericTestRunner(open val project: Project, open val classpath:
return result
}
fun runTests() {
/**
* @return true if all the tests passed
*/
fun runTests() : Boolean {
val jvm = JavaInfo.create(File(SystemProperties.javaBase))
val java = jvm.javaExecutable
val allArgs = arrayListOf<String>().apply {
add(java!!.absolutePath)
add("-classpath")
add(classpath.map { it.jarFile.get().absolutePath }.joinToString(File.pathSeparator))
add(mainClass)
addAll(args)
}
if (args.size > 0) {
val allArgs = arrayListOf<String>().apply {
add(java!!.absolutePath)
add("-classpath")
add(classpath.map { it.jarFile.get().absolutePath }.joinToString(File.pathSeparator))
add(mainClass)
addAll(args)
}
val pb = ProcessBuilder(allArgs)
pb.directory(File(project.directory))
pb.inheritIO()
log(1, "Running tests with classpath size ${classpath.size}")
log(2, "Launching " + allArgs.joinToString(" "))
val process = pb.start()
val errorCode = process.waitFor()
if (errorCode == 0) {
log(1, "All tests passed")
val pb = ProcessBuilder(allArgs)
pb.directory(File(project.directory))
pb.inheritIO()
log(1, "Running tests with classpath size ${classpath.size}")
log(2, "Launching " + allArgs.joinToString(" "))
val process = pb.start()
val errorCode = process.waitFor()
if (errorCode == 0) {
log(1, "All tests passed")
} else {
log(1, "Test failures")
}
return errorCode == 0
} else {
log(1, "Test failures")
log(2, "Couldn't find any test classes")
return true
}
}
}

View file

@ -64,18 +64,20 @@ abstract class JvmCompilerPlugin @Inject constructor(
result.addAll(dependencyManager.calculateDependencies(project, context, it))
}
}
return dependencyManager.reorderDependencies(result)
val result2 = dependencyManager.reorderDependencies(result)
return result2
}
@Task(name = TASK_TEST, description = "Run the tests", runAfter = arrayOf("compile", "compileTest"))
fun taskTest(project: Project) : TaskResult {
lp(project, "Running tests")
if (project.testDependencies.any { it.id.contains("testng")} ) {
TestNgRunner(project, testDependencies(project)).runTests()
} else {
JUnitRunner(project, testDependencies(project)).runTests()
}
return TaskResult()
val success =
if (project.testDependencies.any { it.id.contains("testng")} ) {
TestNgRunner(project, testDependencies(project)).runTests()
} else {
JUnitRunner(project, testDependencies(project)).runTests()
}
return TaskResult(success)
}
@Task(name = TASK_CLEAN, description = "Clean the project", runBefore = arrayOf("compile"))