maiflai / gradle-scalatest

A plugin to enable the use of scalatest in a gradle Scala project.
The Unlicense
73 stars 35 forks source link

ASCII Control Characters Printed #69

Open SJrX opened 6 years ago

SJrX commented 6 years ago

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.

Discovery starting.
Discovery completed in 47 milliseconds.
Run starting. Expected test count is: 1
ATest:
- Hello (6 milliseconds)
Run completed in 90 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.
SJrX commented 6 years ago

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.

SJrX commented 6 years ago

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.

maiflai commented 6 years ago

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.

atais commented 4 years ago

You could add -W parameter for now: https://www.scalatest.org/user_guide/using_the_runner#configuringReporters W - without color

pan3793 commented 3 years ago

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?

maiflai commented 3 years ago

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