Closed DinisCruz closed 9 years ago
You don’t need run
or $output
here.
@test "curl installed" {
curl --version | grep '7\.37\.1’
}
Just run curl --version
directly and pipe its output to grep
with the string you want to match. grep
will return a non-zero exit code if there’s no match, which will result in a failed test.
@sstephenson version works great
for example:
#!/usr/bin/env bats
. ./src/api-git.sh
. ./src/api-veracode.sh
@test "load API ok and call git version" {
result="$(git_version)"
echo $result | grep 'git version'
}
We use double squares and double equality to do string contains:
# Output should be verbose:
[[ "$output" == *"cleaning"* ]]
[[ "$output" == *"$encrypted_filename"* ]]
Hi, I'm using bats to write tests for docker build images, and on the test bellow
I was able to use the
[ $(expr "$output" : ".*curl 7.37.1") -eq 11 ]
to check that the curl version was 7.37.1, but that syntax fells too complexIs there another way?
Maybe something like
[ "$output" == *"curl 7.37.1"* ];
?(which doesn't work)