Reputation: 3611
On Travis CI
I like to test if a build fails as expected with a certain input, but still want the entire job succeeds. Is there a way to achieve this?
Closest I can think of is allow_failures, but it's not sufficient because a job in question passes if it succeeds, which means there's a bug in my code. False-positive. I want to check true-negative.
Thanks.
Upvotes: 1
Views: 33
Reputation: 4677
To make sure the error value (or return value, or exit value) is 0
when your program exits with not 0
you can do one of two things:
You can do the trivial thing and put !
before the invocation like this:
!test_that_should_fail
This will invert (as an unary !
op would) 0
to 1
and anything non-0
to 0
, ensuring, that the command will fail if it'd succeed.
You can also do an if
-test, described in detail here, like so:
# This will store $? and make the expression's exit value `0`
test_that_should_fail; ERR=$?
if [ "$ERR" = "1" ]; then echo "The test's failed as it should"; fi
if [ "$ERR" = "0" ]; then echo "The test ain't failed, unacceptable"; fi
But tbh I'd rather make my tests internally handle "planned failures".
Upvotes: 1