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

STDIN in test is bound to the calling terminal STDIN when Data block not specified #294

Open
UnasZole opened this issue Mar 13, 2023 · 2 comments

Comments

@UnasZole
Copy link

Hi,

I just noticed a behaviour on 0.28.1 which seems wrong to me.

Simply put, I'm defining a helper function "readParameter", which requires quite a lot of input before just calling the application under test.
The basic part of that input (parameter name...), I'm passing as actual arguments.
The most structured part (some context information) I pass using a Data block.
The readParameter function then consumes the full STDIN (ie the contents of the data block), typically with stdin=$(cat).

It works fine overall.

In some cases, however, I don't need to pass any context.
If I just pass an empty Data block, like this

It 'does stuff'
    Data
    End
    When call readParameter parameterWithoutContext
    The output should equal 'default'
End

It still works fine.

But if I remove the Data block entirely, like this :

It 'does stuff'
    When call readParameter parameterWithoutContext
    The output should equal 'default'
End

Then, shellspec hangs on the test, until I type ctrl+D in my terminal (and then hangs on the next such test, etc.).
Which implies that the test is actuall waiting on the terminal's STDIN.

Given that shellspec aims at running automated tests anyway, I would not expect the running test to be tied to the terminal's STDIN.
It would be more natural to me if omitting the data block entirely was identical to passing an empty one, ie sending an empty string via STDIN.

Was this behaviour decided on purpose for some use cases I'm missing, or could it be changed/fixed ?

@LukeSavefrogs
Copy link
Contributor

It's not an error. It is how shells work.

If the function (readParameter) expects data to be passed to stdin, then it will hang forever until an End-Of-File character is received (Ctrl+D).

If you need a default if no stdin is passed then it's exactly THAT the problem. The test shows that the function does not work as you intend, so you must handle it in the readParameter code

@UnasZole
Copy link
Author

UnasZole commented Mar 19, 2023

Please read the title of the ticket again. The issue I'm complaining about is not "the call hangs waiting for stdin", which is indeed normal if using the stdin from the terminal.

What I'm saying is that in my opinion, shellspec SHOULD NOT be forwarding the terminal's stdin to the call in the first place.

For a tool designed to build automatable and reproducible test suites, plugging terminal stdin into the processing of individual tests is a weird design choice at best, and a bug at worst (tests results may change if the impatient user presses any key on his terminal while the campaign progresses).

Again, all I'm saying is that when no Data block is specified, the "call" stdin should receive an empty string, and NOT the terminal's stdin.
In other words, no Data block should be equivalent to an empty Data block.

If there really are use cases where it makes sense to forward the calling terminal stdin to the test functions, I'm very curious to read about it.
And even if there are :

  • It may be more reliable to disable that binding by default, and provide a way to enable it explicitly,
  • And most importantly, this behaviour should be explicitly specified and documented.

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

2 participants