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

println! in steps is not working as expected. #177

Closed
antonkol opened this issue Dec 6, 2021 · 7 comments
Closed

println! in steps is not working as expected. #177

antonkol opened this issue Dec 6, 2021 · 7 comments
Assignees
Labels
enhancement Improvement of existing features or bugfix question Further information is requested
Milestone

Comments

@antonkol
Copy link

antonkol commented Dec 6, 2021

i have few println! inside steps and when i am executing tests information in println! appears before all Cucumber log.

Something like this:

some info 1
some info 2

 Feature: Some feature
   Scenario Outline: Some scenario outline
       Given
       And
   Scenario Outline: Some scenario outline
      Given
       And

Is there a way to output println! below appropriate step ?

Something like this:

 Feature: Some feature
   Scenario Outline: Some scenario outline
       Given
          some info 1
       And
   Scenario Outline: Some scenario outline
      Given
          some info 2
       And
@tyranron tyranron added the question Further information is requested label Dec 6, 2021
@tyranron tyranron added this to the 0.11 milestone Dec 6, 2021
@ilslv
Copy link
Member

ilslv commented Dec 7, 2021

@antonkol unfortunately this is feature isn't supported. The main reason behind it is a concurrent Scenario execution. So to support this feature we somehow need to come up with mechanism to intercept output of the println! macro, somehow understand which step it belongs to from the context of the Step function, store all this data and only when the time is right output it.
Maybe this is possible with custom println! and dbg! macros, but I believe that it's not possible with default ones.

I'll leave this issue open with a rfc tag and give it a thought a bit more.

@ilslv ilslv added rfc and removed question Further information is requested labels Dec 7, 2021
@ilslv ilslv removed this from the 0.11 milestone Dec 7, 2021
@ilslv ilslv added the postponed Postponed due to lack of implementation reasons label Dec 7, 2021
@tyranron
Copy link
Member

tyranron commented Dec 7, 2021

@ilslv may be a clear explanation of how to run tests, so the custom output will appear naturally, will do the job?

Is --concurrency=1 will be enough? Or we should also remove writer::Normalized from pipeline? Could you provide an example? I'll include the one to the Book in #171.

@tyranron tyranron added the question Further information is requested label Dec 7, 2021
@ilslv
Copy link
Member

ilslv commented Dec 8, 2021

@tyranron

Is --concurrency=1 will be enough? Or we should also remove writer::Normalized from pipeline?

To achieve natural output, you'll need to do the following steps:

  1. Create writer::Basic::raw with Coloring::Never to avoid interference with pretty-printed output
writer::Basic::raw(stdout(), writer::Coloring::Never, false)
    .summarized()
  1. You'll need custom Writer like AssertNormalized which implements Normalized for any Writer, but does nothing. This isn't supplied by crate yet, but maybe we should?
  2. Set max_concurrent_scenarios() to 1

Full example:

let res = World::cucumber()
    .max_concurrent_scenarios(1)
    .with_writer(writer::AssertNormalized(
//                       ^^^^^^^^^^^^^^^^ doesn't exist yet. 
        writer::Basic::raw(stdout(), writer::Coloring::Never, false)
            .summarized(),
    ))
    .with_cli(cli)
    .run_and_exit("tests/features/wait");

Output for wait test with dbg! and all steps above

Feature: Basic
  Scenario: 1 sec
[tests/wait.rs:61] world.0 = 1
   ✔> Given 1 sec
[tests/wait.rs:61] world.0 = 2
   ✔  Given 1 sec
[tests/wait.rs:61] world.0 = 3
   ✔  When 1 sec
   ?  Then unknown
      Step skipped: /Users/work/Work/cucumber/tests/features/wait/rule.feature:9:5
...

So even with all those steps we first see output of the dbg! and only then step result.

@tyranron
Copy link
Member

tyranron commented Dec 8, 2021

@ilslv

So even with all those steps we first see output of the dbg! and only then step result.

It's not a problem though, as we have them close to the performed step.

2. You'll need custom Writer like AssertNormalized which implements Normalized for any Writer, but does nothing. This isn't supplied by crate yet, but maybe we should?

Hmmm, I think we should add them, along with ext-helpers, so we have:

let res = World::cucumber()
    .max_concurrent_scenarios(1)
    .with_writer(
        writer::Basic::raw(stdout(), writer::Coloring::Never, false)
            .summarized()
            .assert_normalized(),
    )
    .with_cli(cli) // do we really need this line here? It should work without it.
    .run_and_exit("tests/features/wait");

@tyranron tyranron added this to the 0.11 milestone Dec 8, 2021
@tyranron tyranron added enhancement Improvement of existing features or bugfix and removed rfc postponed Postponed due to lack of implementation reasons labels Dec 8, 2021
@ilslv
Copy link
Member

ilslv commented Dec 8, 2021

@tyranron

.with_cli(cli) // do we really need this line here? It should work without it.

Oh, of corse no, left it by mistake

Hmmm, I think we should add them, along with ext-helpers, so we have:

Ok

@tyranron
Copy link
Member

tyranron commented Dec 8, 2021

Done. Now it's only left to describe in new Book in #171.

@tyranron
Copy link
Member

Now it's only left to describe in new Book in #171.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants