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

Include the output $stderr and $stdout in JUnit formatted XML #259

Merged
merged 6 commits into from Apr 30, 2012
Merged

Include the output $stderr and $stdout in JUnit formatted XML #259

merged 6 commits into from Apr 30, 2012

Conversation

rtyler
Copy link
Contributor

@rtyler rtyler commented Apr 2, 2012

This is useful for Jenkins users who might have valuable information getting pumped into $stderr or $stdout..

In my case, I need to put data into the <system-out/> for some plugin integration in Jenkins, but I can see it useful for the general case.

I tried to make the Interceptor::Pipe class as re-usable as possible, but also low impact. This is my first pull request, so be gentle :)

Willing to accept free BDD coaching if @mattwynee is up for it ;)

@mattwynne
Copy link
Member

I think this is great. Nice specs, easy to read code.

@rtyler
Copy link
Contributor Author

rtyler commented Apr 17, 2012

I'm not aware of any way to know what global pipe was passed in originally (being a reference and all), so I've cleaned up as best I could.

In the case of #unwrap! it also does the added bonus of disabling the interception if for some unforeseen reason the caller of Interceptor::Pipe doesn't properly reset the pipe.

@mattwynne
Copy link
Member

Nice!

How about just taking a symbol to represent which global pipe it should wrap, then doing the interception in that method:

@wrappedstderr = Interceptor::Pipe.wrap(:stderr)

WDYT? It would keep the formatter itself cleaner, even if the interceptor has to get a little bit more ugly.

@rtyler
Copy link
Contributor Author

rtyler commented Apr 18, 2012

How symmetrical should the #wrap/#unwrap! API be? The way you use/reference #wrap there says to me it should be a class method.

Should #unwrap! then be used as such?:

Interceptor::Pipe.unwrap!(@wrappedstderr)

R. Tyler Croy added 6 commits April 23, 2012 22:24
…y intercepting writes to pipes

This will ultimately be used to consume $stderr and $stdout for formatters
Per @mattwynne's feedback, wrapping can now be done with:

    Interceptor::Pipe.wrap :stdout
    Interceptor::Pipe.unwrap! :stdout

Both methods will return the Interceptor::Pipe object such that the consumer
can then inspect the interceptor's buffer.
@rtyler
Copy link
Contributor Author

rtyler commented Apr 24, 2012

I hope this finally meets your satisfaction :) 🍰

@mattwynne
Copy link
Member

Thanks! I'll take a look shortly.

@mattwynne
Copy link
Member

Beautiful!

mattwynne added a commit that referenced this pull request Apr 30, 2012
Include the output $stderr and $stdout in JUnit formatted XML
@mattwynne mattwynne merged commit ef187d3 into cucumber:master Apr 30, 2012
@penberg
Copy link

penberg commented May 21, 2012

So does this feature actually work? I'm running Cucumber 1.2.0 on Linux and don't seem to get anything to "system-err" or "system-out".

I tried adding a

puts "HELLO"

line to fixtures/junit/features/step_definitions/steps.rb for the "passing scenario" but didn't see any test breakage. Shouldn't legacy_features/junit_formatter.feature pick that up?

@mattwynne
Copy link
Member

Thanks for the feedback @penberg. Any comments @rtyler?

@rtyler
Copy link
Contributor Author

rtyler commented May 21, 2012

@penberg is correct, it looks like I overlooked the fact that "puts" inside of a step-definition is something else that doesn't seem to print to stdout/stderr at all.

A raw:

  $stdout.write("HELLO!\n")

in a step-definition will be placed in the right XML tags though.

Guess this isn't over just yet ;)

@mattwynne
Copy link
Member

Ah I forgot. This is a feature which @aslakhellesoy implemented a while back. We used to call this method #announce.

What do you guys think would be the least surprising behaviour to implement here?

@rtyler
Copy link
Contributor Author

rtyler commented May 21, 2012

It does take me a little by surprise that Kernel methods are being overwritten by the default World.

What this means is that puts calls in my step definitions will not hit $stdout and in turn the Interceptor code, but puts calls in other methods/modules that I invoke will.

It is a little bonkers IMHO.

@mattwynne
Copy link
Member

So @penberg can you try using Kernel.puts instead?

@rtyler now you know the lay of the land, what do you think it should do? Maybe we should start using the pipe interceptor everywhere and push all stdout / stderror output to the formatters as events? That way we'd still get the current behaviour (puts statements in your step defs are rendered all pretty by the formatter) and that would also work for puts statements elsewhere in the codebase.

@rtyler
Copy link
Contributor Author

rtyler commented May 22, 2012

FWIW, Kernel#puts will work properly in the same way that $stdout#write will.

Anything you're up for @mattwynne I can take a crack at if you want to file an issue, I'm still sufficiently fresh to Cucumber's codebase that I'm not comfortable making these kinds of decisions just yet.

@penberg
Copy link

penberg commented May 23, 2012

@rtyler $stderr.write() indeed works just fine. Thanks!

@mattwynne
Copy link
Member

I can't get my head around it. Let's leave it until it pops back up.

@luvs
Copy link

luvs commented Aug 10, 2012

Hello. Its possible to print stdout/stderr into tag, now all stdout writes to level and Jenkins doesn't print output in test results?


My workaround, maybe it will be useful for somebody:
Modify lib/cucumber/formatter/json.rb

  1. Add this string to before_steps
    @interceptedout_steps = Interceptor::Pipe.wrap(:stdout)
    @interceptederr_steps = Interceptor::Pipe.wrap(:stderr)
  2. Modify build_testcase - add 2 param and output them into system-out/system-err
    def build_testcase(duration, status, sys_output, sys_err, exception = nil, suffix = "")
    ....
    @builder.tag!('system-out') do
    @builder.cdata! sys_output.buffer.join
    end
    @builder.tag!('system-err') do
    @builder.cdata! sys_err.buffer.join
    end
    ....
  3. Modify call build_testcase in 2 place
    build_testcase(duration, steps.status, @interceptedout_steps, @interceptederr_steps, steps.exception)
    build_testcase(duration, table_row.status, @interceptedout_steps, @interceptederr_steps, table_row.exception, name_suffix)

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants