From 2746f57b9a34223979982cc15eec1c36033e8a79 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Wed, 18 Nov 2015 23:16:13 -0800 Subject: [PATCH] Pass TaskResult better in tests. --- .../beust/kobalt/internal/GenericRunner.kt | 46 +++++++++++-------- .../kobalt/internal/JvmCompilerPlugin.kt | 16 ++++--- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index 09819ed2..60b5fdfa 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -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().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().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 } - } } diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 5be076e7..ab1aab30 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -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"))