How to use colours method of io.kotest.engine.launcher.console class

Best Kotest code snippet using io.kotest.engine.launcher.console.colours

Kotest.kt

Source:Kotest.kt Github

copy

Full Screen

1package io.kotest.gradle2import jetbrains.buildServer.messages.serviceMessages.ServiceMessagesParser3import org.gradle.api.GradleException4import org.gradle.api.file.FileCollection5import org.gradle.api.internal.file.FileCollectionFactory6import org.gradle.api.internal.file.FileResolver7import org.gradle.api.internal.tasks.testing.DefaultTestSuiteDescriptor8import org.gradle.api.internal.tasks.testing.results.DefaultTestResult9import org.gradle.api.tasks.TaskAction10import org.gradle.api.tasks.options.Option11import org.gradle.api.tasks.testing.Test12import org.gradle.api.tasks.testing.TestListener13import org.gradle.api.tasks.testing.TestOutputListener14import org.gradle.api.tasks.testing.TestResult15import org.gradle.internal.concurrent.ExecutorFactory16import org.gradle.process.internal.DefaultExecActionFactory17import org.gradle.process.internal.JavaExecAction18import java.io.PipedInputStream19import java.io.PipedOutputStream20import javax.inject.Inject21import kotlin.concurrent.thread22// gradle seems to require the class be open23open class Kotest @Inject constructor(24 private val fileResolver: FileResolver,25 private val fileCollectionFactory: FileCollectionFactory,26 private val executorFactory: ExecutorFactory27) : Test() {28 companion object {29 private const val IntellijTestListenerClassName = "IJTestEventLogger"30 private const val ReporterArg = "--reporter"31 private const val TermArg = "--termcolor"32 private const val TagsArg = "--tags"33 private const val TeamCityReporter = "teamcity"34 private const val TaycanReporter = "io.kotest.engine.reporter.TaycanConsoleReporter"35 private const val PlainColours = "ansi16"36 private const val TrueColours = "ansi256"37 }38 private val listeners = mutableListOf<TestListener>()39 private val outputListeners = mutableListOf<TestOutputListener>()40 private var tags: String? = null41 // gradle will call this if --tags was specified on the command line42 @Option(option = "tags", description = "Set tag expression to include or exclude tests")43 fun setTags(tags: String) {44 this.tags = tags45 }46 // intellij will call this to register its listeners for the test event run window47 override fun addTestListener(listener: TestListener) {48 listeners.add(listener)49 }50 override fun addTestOutputListener(listener: TestOutputListener) {51 outputListeners.add(listener)52 }53 /**54 * Returns args to be used for the tag expression.55 *56 * If --tags was passed as a command line arg, then that takes precedence over the value57 * set in the gradle build.58 *59 * Returns empty list if no tag expression was specified.60 */61 private fun tagArgs(): List<String> {62 tags?.let { return listOf(TagsArg, it) }63 project.kotest()?.tags?.orNull?.let { return listOf(TagsArg, it) }64 return emptyList()65 }66 // -- reporter was added in 4.2.167 private fun args() = when {68 isIntellij() -> listOf(ReporterArg, TeamCityReporter, TermArg, PlainColours) + tagArgs()69 else -> listOf(ReporterArg, TaycanReporter, TermArg, TrueColours) + tagArgs()70 }71 private fun exec(classpath: FileCollection): JavaExecAction {72 val exec =73 DefaultExecActionFactory.of(fileResolver, fileCollectionFactory, executorFactory, null).newJavaExecAction()74 copyTo(exec)75 exec.main = "io.kotest.engine.launcher.MainKt"76 exec.classpath = classpath77 exec.jvmArgs = allJvmArgs78 exec.args = args()79 // this must be true so we can handle the failure ourselves by throwing GradleException80 // otherwise we get a nasty stack trace from gradle81 exec.isIgnoreExitValue = true82 return exec83 }84 /**85 * Returns true if we are running inside intellij.86 * We detect this by looking to see if intellij added it's own test listener to this task, which it87 * does for any task tat extends Test.88 * The intellij test listener is an instance of IJTestEventLogger.89 */90 private fun isIntellij(): Boolean {91 return listeners.map { it::class.java.name }.any { it.contains(IntellijTestListenerClassName) }92 }93 private fun rerouteTeamCityListener(exec: JavaExecAction) {94 val input = PipedInputStream()95 exec.standardOutput = PipedOutputStream(input)96 thread {97 val root = DefaultTestSuiteDescriptor("root", "root")98 listeners.forEach {99 it.beforeSuite(root)100 }101 input.bufferedReader().useLines { lines ->102 val parser = ServiceMessagesParser()103 val callback = KotestServiceMessageParserCallback(root, listeners, outputListeners)104 lines.forEach { parser.parse(it, callback) }105 }106 listeners.forEach {107 it.afterSuite(root, DefaultTestResult(TestResult.ResultType.SUCCESS, 0, 0, 0, 0, 0, emptyList()))108 }109 }110 }111 @TaskAction112 override fun executeTests() {113 //val testResultsDir = project.buildDir.resolve("test-results")114 val sourceset = project.javaTestSourceSet() ?: return115 val result = try {116 val exec = exec(sourceset.runtimeClasspath)117 if (isIntellij()) rerouteTeamCityListener(exec)118 exec.execute()119 } catch (e: Exception) {120 println(e)121 e.printStackTrace()122 throw GradleException("Test process failed", e)123 }124 if (result.exitValue != 0) {125 throw GradleException("There were test failures")126 }127 }128}...

Full Screen

Full Screen

console.kt

Source:console.kt Github

copy

Full Screen

...13 // we support "teamcity", "taycan", "enhanced" as special values14 // taycan was the name for the fancy kotest output but has been renamed to simply enhanced15 when (args.listener) {16 "teamcity" -> TeamCityTestEngineListener()17 "taycan", "enhanced" -> EnhancedConsoleTestEngineListener(colours(args))18 null -> defaultConsoleListener()19 else -> Class.forName(args.listener).getDeclaredConstructor().newInstance() as TestEngineListener20 }21 } catch (t: Throwable) {22 println(t.message)23 t.printStackTrace()24 defaultConsoleListener()25 }26}27internal fun colours(args: LauncherArgs): TermColors {28 return when (args.termcolor) {29 "true" -> TermColors(TermColors.Level.TRUECOLOR)30 "ansi256" -> TermColors(TermColors.Level.ANSI256)31 "ansi16" -> TermColors(TermColors.Level.ANSI16)32 "auto" -> TermColors()33 else -> TermColors()34 }35}36// returns a TestEngineListener appropriate for the environment when none was specified37// If we are running from intellij, we use an IDEA compatible team city writer38// otherwise we use the default enhanced writer39internal fun defaultConsoleListener(): TestEngineListener =40 if (isIntellij()) TeamCityTestEngineListener() else EnhancedConsoleTestEngineListener(TermColors())...

Full Screen

Full Screen

colours

Using AI Code Generation

copy

Full Screen

1val colors = Colors()2val launcher = KotestEngineLauncher()3launcher.execute()4launcher.printSummary(colors)5val colors = Colors()6val launcher = KotestEngineLauncher()7launcher.execute()8launcher.printSummary(colors)

Full Screen

Full Screen

colours

Using AI Code Generation

copy

Full Screen

1fun main(args: Array<String>) {2val spec = object : StringSpec({3"some test" {4println("Hello World")5}6})7val console = ConsoleLauncher()8console.execute(spec, args)9}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful