1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-25 16:07:12 -07:00
This commit is contained in:
Cedric Beust 2017-03-21 16:32:20 -07:00
parent 34185a6b2a
commit b68ec28050
3 changed files with 143 additions and 16 deletions

View file

@ -110,7 +110,8 @@ val kobaltPluginApi = project {
"org.eclipse.jgit:org.eclipse.jgit:4.5.0.201609210915-r", "org.eclipse.jgit:org.eclipse.jgit:4.5.0.201609210915-r",
"org.slf4j:slf4j-simple:${Versions.slf4j}", "org.slf4j:slf4j-simple:${Versions.slf4j}",
*mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"), *mavenResolver("api", "spi", "util", "impl", "connector-basic", "transport-http", "transport-file"),
"org.apache.maven:maven-aether-provider:3.3.9" "org.apache.maven:maven-aether-provider:3.3.9",
"org.testng.testng-remote:testng-remote:1.3.0"
) )
exclude(*aether("impl", "spi", "util", "api")) exclude(*aether("impl", "spi", "util", "api"))
} }

View file

@ -17,16 +17,16 @@ class AsciiArt {
companion object { companion object {
private val BANNERS = arrayOf( private val BANNERS = arrayOf(
" __ __ __ __ __ \n" + " __ __ __ __ __ \n" +
" / //_/ ____ / /_ ____ _ / / / /_\n" + " / //_/ ____ / /_ ____ _ / / / /_\n" +
" / ,< / __ \\ / __ \\ / __ `/ / / / __/\n" + " / ,< / __ \\ / __ \\ / __ `/ / / / __/\n" +
" / /| | / /_/ / / /_/ // /_/ / / / / /_ \n" + " / /| | / /_/ / / /_/ // /_/ / / / / /_ \n" +
" /_/ |_| \\____/ /_.___/ \\__,_/ /_/ \\__/ ", " /_/ |_| \\____/ /_.___/ \\__,_/ /_/ \\__/ ",
" _ __ _ _ _ \n" + " _ __ _ _ _ \n" +
" | |/ / ___ | |__ __ _ | | | |_ \n" + " | |/ / ___ | |__ __ _ | | | |_ \n" +
" | ' / / _ \\ | '_ \\ / _` | | | | __|\n" + " | ' / / _ \\ | '_ \\ / _` | | | | __|\n" +
" | . \\ | (_) | | |_) | | (_| | | | | |_ \n" + " | . \\ | (_) | | |_) | | (_| | | | | |_ \n" +
" |_|\\_\\ \\___/ |_.__/ \\__,_| |_| \\__| " " |_|\\_\\ \\___/ |_.__/ \\__,_| |_| \\__| "
) )
val banner : String get() = BANNERS[Random().nextInt(BANNERS.size)] val banner : String get() = BANNERS[Random().nextInt(BANNERS.size)]
@ -85,7 +85,7 @@ class AsciiArt {
} }
fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, indent: Int = 0) fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, indent: Int = 0)
= logBox(listOf(s), bl, br, indent) = logBox(listOf(s), bl, br, indent)
fun fill(n: Int) = buildString { repeat(n, { append(" ")})}.toString() fun fill(n: Int) = buildString { repeat(n, { append(" ")})}.toString()
@ -105,7 +105,7 @@ class AsciiArt {
const val CYAN = "\u001B[36m" const val CYAN = "\u001B[36m"
const val WHITE = "\u001B[37m" const val WHITE = "\u001B[37m"
private fun wrap(s: CharSequence, color: String) = color + s + RESET fun wrap(s: CharSequence, color: String) = color + s + RESET
private fun blue(s: CharSequence) = wrap(s, BLUE) private fun blue(s: CharSequence) = wrap(s, BLUE)
private fun red(s: CharSequence) = wrap(s, RED) private fun red(s: CharSequence) = wrap(s, RED)
private fun yellow(s: CharSequence) = wrap(s, YELLOW) private fun yellow(s: CharSequence) = wrap(s, YELLOW)
@ -141,10 +141,10 @@ class AsciiTable {
fun build() : String { fun build() : String {
val formattedHeaders = val formattedHeaders =
headers.mapIndexed { index, s -> headers.mapIndexed { index, s ->
val s2 = col(widths[index], s) val s2 = col(widths[index], s)
s2 s2
}.joinToString(vb) }.joinToString(vb)
val result = StringBuffer().apply { val result = StringBuffer().apply {
append(AsciiArt.logBox(formattedHeaders, AsciiArt.bottomLeft2, AsciiArt.bottomRight2)) append(AsciiArt.logBox(formattedHeaders, AsciiArt.bottomLeft2, AsciiArt.bottomRight2))
append("\n") append("\n")

View file

@ -1,12 +1,22 @@
package com.beust.kobalt.internal package com.beust.kobalt.internal
import com.beust.kobalt.AsciiArt
import com.beust.kobalt.TestConfig import com.beust.kobalt.TestConfig
import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.aether.AetherDependency
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.Versions
import com.beust.kobalt.misc.runCommand
import com.beust.kobalt.misc.warn import com.beust.kobalt.misc.warn
import org.testng.remote.RemoteArgs
import org.testng.remote.strprotocol.JsonMessageSender
import org.testng.remote.strprotocol.MessageHelper
import org.testng.remote.strprotocol.MessageHub
import org.testng.remote.strprotocol.TestResultMessage
import java.io.File import java.io.File
import java.io.IOException
class TestNgRunner : GenericTestRunner() { class TestNgRunner : GenericTestRunner() {
@ -39,7 +49,7 @@ class TestNgRunner : GenericTestRunner() {
add("-testclass") add("-testclass")
add(testClasses.joinToString(",")) add(testClasses.joinToString(","))
} else { } else {
if (! testConfig.isDefault) warn("Couldn't find any test classes for ${project.name}") if (!testConfig.isDefault) warn("Couldn't find any test classes for ${project.name}")
// else do nothing: since the user didn't specify an explicit test{} directive, not finding // else do nothing: since the user didn't specify an explicit test{} directive, not finding
// any test sources is not a problem // any test sources is not a problem
} }
@ -48,4 +58,120 @@ class TestNgRunner : GenericTestRunner() {
addAll(testConfig.testArgs) addAll(testConfig.testArgs)
} }
} }
val VERSION_6_10 = 600100000L
override fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
configName: String): Boolean {
val testngDependency = (project.testDependencies.filter { it.id.contains("testng") }
.firstOrNull() as AetherDependency).version
val testngDependencyVersion = Versions.toLongVersion(testngDependency)
val result =
if (testngDependencyVersion >= VERSION_6_10) {
displayPrettyColors(project, context, classpath)
} else {
super.runTests(project, context, classpath, configName)
}
return result
}
fun displayPrettyColors(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>)
: Boolean {
val port = 2345
val jf = context.dependencyManager.create("org.testng.testng-remote:testng-remote:1.3.0")
val tr = context.dependencyManager.create("org.testng.testng-remote:testng-remote6_10:1.3.0")
val testng = context.dependencyManager.create("org.testng:testng:6.10")
val dep1 = context.dependencyManager.transitiveClosure(listOf(jf, tr, testng))
val v = Versions.toLongVersion("6.10")
val cp = (classpath + dep1).map { it.jarFile.get() }
.joinToString(File.pathSeparator)
val passedArgs = listOf(
"-classpath",
cp,
"org.testng.remote.RemoteTestNG",
"-serport", port.toString(),
"-version", "6.10",
"-dontexit",
RemoteArgs.PROTOCOL,
"json",
"src/test/resources/testng.xml")
Thread {
val exitCode = runCommand {
command = "java"
directory = File(project.directory)
args = passedArgs
}
}.start()
// Thread {
// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json",
// "-version", "6.10",
// "src/test/resources/testng.xml")
// RemoteTestNG.main(args2)
// }.start()
val mh = MessageHub(JsonMessageSender("localhost", port, true))
mh.setDebug(true)
mh.initReceiver()
val passed = arrayListOf<String>()
data class FailedTest(val method: String, val cls: String, val stackTrace: String)
val failed = arrayListOf<FailedTest>()
var skipped = arrayListOf<String>()
fun d(n: Int, color: String)
= AsciiArt.wrap(String.format("%4d", n), color)
fun red(s: String) = AsciiArt.wrap(s, AsciiArt.RED)
fun green(s: String) = AsciiArt.wrap(s, AsciiArt.GREEN)
fun yellow(s: String) = AsciiArt.wrap(s, AsciiArt.YELLOW)
try {
var message = mh.receiveMessage()
println("")
println(green("PASSED") + " | " + red("FAILED") + " | " + yellow("SKIPPED"))
while (message != null) {
message = mh.receiveMessage()
if (message is TestResultMessage) {
when (message.result) {
MessageHelper.PASSED_TEST -> passed.add(message.name)
MessageHelper.FAILED_TEST -> failed.add(FailedTest(message.testClass,
message.method, message.stackTrace))
MessageHelper.SKIPPED_TEST -> skipped.add(message.name)
}
}
print("\r " + d(passed.size, AsciiArt.GREEN)
+ " | " + d(failed.size, AsciiArt.RED)
+ " | " + d(skipped.size, AsciiArt.YELLOW))
// Thread.sleep(500)
// print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size))
// Thread.sleep(200)
}
} catch(ex: IOException) {
println("Exception: ${ex.message}")
}
println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size)
failed.forEach {
val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n"))
println(" " + it.cls + "." + it.method + "\n " + top)
}
return failed.isEmpty() && skipped.isEmpty()
}
}
fun main(args: Array<String>) {
fun d(n: Int, color: String)
= AsciiArt.wrap(String.format("%4d", n), color)
println("PASSED | FAILED | SKIPPED")
repeat(20) { i ->
print("\r " + d(i, AsciiArt.GREEN) + " | " + d(i * 2, AsciiArt.RED) + " | " + d(i, AsciiArt.YELLOW))
Thread.sleep(500)
}
println("")
} }