-
Notifications
You must be signed in to change notification settings - Fork 515
Pipe does not work in the test #10
Comments
I hit the same thing, pipes don't appear to work, even if quoted. If you're expecting a 0 exit code, you can forgo the
Or, in my case, something slightly trickier -- testing for the absence of a string. BATS seems to be very good at catching errors in the pipe, despite my best efforts to exit 0. e.g., this doesn't work:
Workaround -- negate the exit code:
|
I ran into a similar problem, but my workaround was to do the following:
obviously, it makes it very difficult to test for the exact return value |
I've been dabbling with this and discovered another way to do your code:
That seems to do the trick and also feels a little better since it isolates the execution of the grep, which is really what you're testing at that point. |
You're misunderstanding how bats works. "run" is not special syntax—it is just another command.
You don't need the
|
If you need to test against the output of a pipe, capture it yourself instead of trying to use 'run'. @test "Test if GitHub is in the global ssh_known_hosts file" { |
heya... bats is rad. cool project. Finally figured out a way to get this to work as expected... wrap it in a @test "linux: running 64-bit kernel" {
run bash -c "uname -a | grep -o x86_64 | wc -m"
echo "output: "$output
echo "status: "$status
[ "$status" -eq 0 ]
[ "$output" -ne 0 ]
} I also have debug messages here that only show if the test fails. works well. |
Add Appveyor configuration, update Travis CI configuration, fix macOS bug
To use |
@test "Use grep in BATS tests" {
run grep -q "$item_to_find" <(command_to_run)
[ "$status" -eq 0 ]
} |
Hello,
after seeing the screencast by @drnic i'm trying out bats in test-kitchen. But 'im having trouble with the most basic test
With | grep github -> failure
Without | grep github -> succes but this doesn't test what i want it to test
Running by hand exit value is 0
The text was updated successfully, but these errors were encountered: