-
Couldn't load subscription status.
- Fork 450
Solved #1: Re-pointed PR 47 #33
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
Conversation
|
I'm really slammed at work this week, but will take a look this weekend if no one else does. |
|
Thanks @rpalo. I wonder if we could guard against a couple of complexities here. We could add something like:
If we wanted further examples (although this could be beyond scope and perhaps in a "defensive BASH" wiki page like this): run bash -e -o pipefail -c "false | wc -l"
# $status is 1
bash -e -c "false | wc -l"
# $status is 0 |
|
Sorry I didn't get to this this weekend; got slammed with another project. Will try to take a look later today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sublimino Raises some good points; probably worth including those.
That said, in most cases tests will be for named functions and scripts, which themselves may contain pipelines. I can see this being useful when your script itself is reading standard input, but I also wonder if echo "foo" | run my-script or run my-script <(echo "foo") may be viable alternatives. (Of course, a failing status isn't returned from a failed process substitution...)
Guess I'm saying it's worth stating why you may want to test a pipeline, why you might want to consider alternatives, etc.
|
@mbland agreed, and here be dragons! I'm happy to those points and some subshell guidance to the examples wiki separately in order to get this merged |
|
What do you think about something like this: You may also find it useful to pipe commands together. To accomplish @test "invoking foo displays 3 lines of output" {
run bash -c "foo | wc -l"
[ "$status" -eq 1 ]
[ "$output" -eq 3 ]
}Keep in mind that the return code of run bash -e -o pipefail -c "foo | wc -l"
# Will fail if foo's exit code is non-zeroHowever, this may be an unwanted result if echo "foo" | run my-scriptI'm new doing pull requests. Is it better that I share ideas here as a comment or just commit another draft? |
|
That looks great @rpalo - fine to discuss here before updating PR too. If you commit those changes to your branch this PR will update and we'll get it merged! 👍 |
|
Great, thanks! Let me know if you see anything else that you'd like me to adjust. |
|
Hi @rpalo, sorry...was really wiped from work, taking longer to recover than anticipated, and fighting off a cold in the process. Will do my best to get to this in the next day or two. (Not that I don't trust @sublimino's judgment, but I owe it some attention, too.) |
|
Oh, don't even stress about it at all. I just wanted to make sure everything was all good. Take care of yourself! |
|
Sorry for the delay. Burning through the backlog now. After thinking through and responding to mbland/go-script-bash#243, I'm thinking the right suggestion is to promote pushing a pipeline into its own function or script as the cleanest solution. I'm also pretty sure that piping input into If we do stick with the recommendations as-is, we'll need test cases. Thoughts? |
|
Actually, I think you're right, putting the piping into a function makes it way easier to handle. I'll take a look at those changes when I get a minute. |
|
Since this has become somewhat stale, we should see what we can salvage via #366 |
The previous PR was to add examples of piping within the
runcommand by @inthecloud247. This repoints the original changes, solving #1 . I'm not sure if this was all that you needed or if you were thinking of something more. Let me know 😄