capture StandardOutputReporter output

289 views
Skip to first unread message

SharkZ

unread,
Nov 1, 2013, 2:51:53 AM11/1/13
to scalate...@googlegroups.com
Hi,
I need to redirect scalatest console output to websocket,  I enabled StandardOutputReporter by using "-o" option, I can see the colorized output on my console, but it can't be redirected.

The console output from scalatest is also not captured by my logback file appender.

Normally, I can redirect the stdout like:

val pipedOut = new PipedOutputStream ()
System.setOut(new PrintStream(pipedOut, true))
System.setErr(new PrintStream(pipedOut, true))

I don't know how scalatest write output to stdout, and how can I capture the outputstream?


Thanks!



Bill Venners

unread,
Nov 1, 2013, 7:41:41 AM11/1/13
to scalate...@googlegroups.com

Hi Sharkz,

ScalaTest doesn't do anything special to write to standard output, except that it likely goes through Scala's Console. I'd try redirecting Console instead of System.out.

There is also a FileReporter that will write the same kind of string report as the standard out reporter to a file.

Bill

--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
scalatest-use...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

SharkZ

unread,
Nov 1, 2013, 8:37:04 AM11/1/13
to scalate...@googlegroups.com
Hi Bill,
I found one of your post: http://www.scala-lang.org/old/node/9443.html#comment-40483
And in that comment, you addressed the concerns about in scala and java mixed application, the System.setOut might be confusing, you said it all right! Logback is widely used in Scala project but written in Java, apparently it captures System.out not Console.out.

The FileReporter seems doesn't write the output line by line, instead, it'll cached all the report content and write it at last, that's what I've observed, or maybe it has a big buffer size which is bigger than my whole report.

I want  console.out to be redirected to browser incrementally, I really want to extend the ScalaTest reporters, but all of them are package private. I think we should make it open for extension right?

Thanks!

Bill Venners

unread,
Nov 1, 2013, 10:51:02 AM11/1/13
to scalate...@googlegroups.com

Hi Sharkz,

I will check the code when I get back to my laptop after breakfast. Can you elaborate on your particular use case? Why do you want to send console output across the net?

Thanks.

Bill

Bill Venners

unread,
Nov 1, 2013, 1:33:53 PM11/1/13
to scalate...@googlegroups.com
Hi Sharkz,

I checked the code. We are indeed using Console.out:

private[scalatest] class StandardOutReporter(
 ...
 extends PrintReporter(
  Console.out,
  ...

If you look at Console's Scaladoc, you'll see there are two withConsole methods. I'd try using those to redirect the Console output. That should in theory work, though this is un-promised behavior of the standard out reporter. If it works, though, I could make it promised behavior.

I didn't want to make StringReporter public because it would add more surface area to the API and more work of documentation, need to make only compatible changes, etc. In 6 years I think your'e the first to ask for it, so I'm not keen on making it public. I would like to understand your use case though, and make sure there's a solutions that is reasonable. One solution, of course, is to just take the code of StringReporter, and make a new subclass. But we also have a SocketReporter that may be able to pay a role in a solution. So I'd like to know more about why you want to do what you want to do.

Thanks.

Bill
--
Bill Venners
Artima, Inc.
http://www.artima.com

Bill Venners

unread,
Nov 1, 2013, 1:36:31 PM11/1/13
to scalate...@googlegroups.com
Hi Sharkz,

Sorry, sent my last email with a typo. The method on Console is withOut, not withConsole. I'm thinking if you put at the top of your suite of tests a call to withOut, and pass in your PipedOutputStream for the PrintStream, you'd get what you want. How to get it "at the top" depends on how you are running your tests. How are you running? sbt? maven? something else?

Bill

SharkZ

unread,
Nov 2, 2013, 8:54:48 AM11/2/13
to scalate...@googlegroups.com
Hi Bill, thank you very much!

The tests are ran by calling ScalaTest's Runner.run() from an hourly scheduled actor, and the users can also run the tests from their browser, the output should redirect to the browser. My testcases are service test cases, verifying the external service responses and generating reports, not code unit tests.

Console.setOut and Console.withOut don't work, probably because actor spawns their own threads. Scala's Console.setOut is broken see https://issues.scala-lang.org/browse/SI-4793

Last time I wrote myself a database reporter, it would redirect all the test results into DB for analyzing. The reporter API is not extensible, I basically checked out the ScalaTest source and copied all the dependent sources to my code base only to remove the private[scalatest].

I am looking the SocketReporter you mentioned.
Reply all
Reply to author
Forward
0 new messages