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

Add option to suppress console output for successful tests #405

Closed
alexeyr opened this issue Oct 6, 2014 · 7 comments
Closed

Add option to suppress console output for successful tests #405

alexeyr opened this issue Oct 6, 2014 · 7 comments

Comments

@alexeyr
Copy link

alexeyr commented Oct 6, 2014

It would sometimes be useful to redirect standard output and avoid noise in SBT results, similar to -q in https://github.com/sbt/junit-interface. If you are willing to add it, I'd be happy to submit a pull request.

@bvenners
Copy link
Contributor

bvenners commented Oct 6, 2014

Just to make sure you're aware, there are a few things you can do today. One is to use -f to put the string output into a file. I think that's likely half of what you'd accomplish with a -q. The other half is reducing the "log" messages sent to sbt. What you can do there today is reduce that to just failures by using options after -o. These are listed here:

http://doc.scalatest.org/2.2.0/index.html#org.scalatest.tools.Runner$@configuringReporters

In sbt -o is the reporter that fires events back at sbt, which it displays at the standard output. I'm not sure if all of these options will work with sbt, because we may have needed to send some anyway because sbt needed them. But you can try just turning them all of with:

-oNCXEHLOPQRM

Let me know if that sufficiently addresses your issue.

@bvenners
Copy link
Contributor

bvenners commented Apr 8, 2015

Closing this issue assuming the reporter options address the issue.

@bvenners bvenners closed this as completed Apr 8, 2015
@Smeb
Copy link

Smeb commented Jul 16, 2019

Sorry to bump an old thread, but this would be very interesting for our use case. We'd ideally like to have successful tests show no stdout, while failing tests would have stdout printed.

I'm not sure we can use the current reporter options to provide the same functionality as junit, since I don't see a way to redirect only successful tests using -f while keeping stdout for failing tests.

@copumpkin
Copy link

@bvenners to clarify the difference from suppressing all the events, the issue is when tests print to stderr or stdout, and I don't believe (right?) that Scalatest performs any output redirection of the standard streams or any buffering. So after experimenting with all sorts of -oNCXEHLOPQRM options and similar, I was unable to get scalatest to suppress the actual stream output from my tests, and ended up wrapping them myself in Console.withOut(Console.withErr(...)) and such. I think that's the closest analog to -q, and it would be nice if the test framework could do it for me.

Or am I missing anything?

@bvenners
Copy link
Contributor

bvenners commented Mar 5, 2020

It should work to do -oC to drop TestSucceeded events from the sbt console, while using -f to also create a file with all of the output. Did you try that combo?

@bvenners
Copy link
Contributor

bvenners commented Mar 5, 2020

Sorry, just realized this is about redirecting stdout in general. ScalaTest doesn't have a built-in feature for that. It is hard to do in general, because in the Java API you need to replace System.err, in, or out (which are static public fields). I looked at doing that years ago, and the problem is that other libraries and frameworks may do that also (like Spring, if I remember) and they conflict. Scala has a better way of doing it with Console, but it only works if you go through Console. I decided neither approach was sufficiently complete to justify adding a feature to ScalaTest. What you can do is use either of those approaches yourself, because in your case you may always be going through Console, or you may not be using some other framework or library that replaces Java's standard IO streams. I'll think about how to customize ScalaTest so that it treats standard output as log messages that only show up on failed tests and post again here when I have a more detailed suggestion.

@copumpkin
Copy link

Yeah, I get that it's not a beautiful solution, but it seems like even satisfying the common case (with a warning that if people go out of their way to mess with it, they can) would scratch a common itch in Scalatest users and generally improve usability on big noisy test suites.

FWIW, I'm not actually using sbt here and am using it with the Bazel build rules for Scala instead. From looking around on StackOverflow it seems like several people have asked for how to do this and all received answers about the options to suppress events, so I don't think it's just me who wants (even an imperfect version of) it.

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