Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASCII Control Characters Printed #69

Open
Tracked by #15
SJrX opened this issue Oct 6, 2018 · 6 comments
Open
Tracked by #15

ASCII Control Characters Printed #69

SJrX opened this issue Oct 6, 2018 · 6 comments

Comments

@SJrX
Copy link

SJrX commented Oct 6, 2018

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
@SJrX
Copy link
Author

SJrX commented Oct 6, 2018

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
Copy link
Author

SJrX commented Oct 6, 2018

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
Copy link
Owner

maiflai commented Oct 6, 2018

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
Copy link

atais commented Oct 5, 2020

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

@pan3793
Copy link

pan3793 commented Feb 3, 2021

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
Copy link
Owner

maiflai commented Feb 3, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants