ASCII Control Characters Printed
SJrX opened this issue · 6 comments
I noticed when I added your plugin to IntelliJ that I wasn't seeing tests (like in #67), however I also noticed that that even in the Gradle log the output was corrupted with ASCII control characters.
build.gradle
plugins {
id "com.github.maiflai.scalatest" version "0.23"
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.11.12'
testCompile 'org.scalatest:scalatest_2.11:3.0.1'
testRuntime 'org.pegdown:pegdown:1.4.2'
}
apply plugin: 'scala'
src/test/Test.scala
import org.scalatest._
class ATest extends WordSpec {
"Hello" in {
}
}
If I run ./gradlew test
I get
> Task :test
Discovery starting.
Discovery completed in 39 milliseconds.
Run starting. Expected test count is: 1
ATest:
- Hello (6 milliseconds)
Run completed in 79 milliseconds.
Total number of tests run: 1
Suites: completed 2, aborted 0
Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
If I run ./gradlew test | less
(piping through less).
ESC[36mDiscovery starting.ESC[0m
ESC[36mDiscovery completed in 43 milliseconds.ESC[0m
ESC[36mRun starting. Expected test count is: 1ESC[0m
ESC[32mATest:ESC[0m
ESC[32m- Hello (6 milliseconds)ESC[0m
ESC[36mRun completed in 85 milliseconds.ESC[0m
ESC[36mTotal number of tests run: 1ESC[0m
ESC[36mSuites: completed 2, aborted 0ESC[0m
ESC[36mTests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0ESC[0m
ESC[32mAll tests passed.ESC[0m
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed
Intellij Is about the same.
�[36mDiscovery starting.�[0m
�[36mDiscovery completed in 47 milliseconds.�[0m
�[36mRun starting. Expected test count is: 1�[0m
�[32mATest:�[0m
�[32m- Hello (6 milliseconds)�[0m
�[36mRun completed in 90 milliseconds.�[0m
�[36mTotal number of tests run: 1�[0m
�[36mSuites: completed 2, aborted 0�[0m
�[36mTests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0�[0m
�[32mAll tests passed.�[0m
I did some digging and was hoping to submit a PR to fix it however I have given up. Here is what I found:
ScalaTestAction.groovy
doesn't pass the W option to the scalatest runner, unless the ConsoleOutput reported by getConsoleOutput()
is Plain. When I run the value is Auto. Looking at the ConsoleOutput Gradle Doc says
Auto
Enable color and rich output when the current process is attached to a console, disable when not attached to a console.
To me this means, that we need to check whether or not the current process is attached to the console. The way to check this seems to be System.console()
Returns the unique Console object associated with the current Java virtual machine, if any. Returns The system console, if any, otherwise null.
However this does not work, it is always null when I run thus never sending the console.
I decided to dig into what Gradle is doing, it seems that ConsoleConfigureAction.getConsoleMetaData() line 73 returns the console if it's detected, and the code for that is here in NativePlatformConsoleDetector.getConsole().
However even if i use the same library (net.rubygrapefruit), I don't seem to ever get a true, when running normally so I'm not sure how to detect it, or how Gradle even deals with it.
Part of me wonders if this really should just be scalatest's job and that it should just clean up it's output if it's inappropriate.
Thanks - yes, a tricky question.
I think that the Gradle Plugin for IntelliJ should probably state that it requires plain text output, or should provide a terminal that can handle coloured output?
Not that this answers the eternal question posed by #67 ... I have been meaning to investigate using the JUnit reporter to integrate more tightly with Gradle's test frameworks, but I struggle to find the time to scratch the itch. Personally I find it straightforward to launch a build from the Terminal.
You could add -W
parameter for now:
https://www.scalatest.org/user_guide/using_the_runner#configuringReporters
W - without color
You could add
-W
parameter for now:
https://www.scalatest.org/user_guide/using_the_runner#configuringReporters
W - without color
How can I config it in gradle.build
? Or where should I config in IDE?
You can't add the -W
parameter yourself.
I think you need to ask the IDE team to fix it.
You might try to use the information at https://docs.gradle.org/current/userguide/build_environment.html and configure your personal gradle.properties
to have
org.gradle.console=plain