Search code examples
bashbehatexit-code

Run 2 Behat profiles with different features into 1 result


I have 2 very different Behat profiles:

simple:
  suites:
    default:
      contexts:
        - rdx\behatvars\BehatVariablesContext
        - SimpleFeatureContext
  extensions:
      rdx\behatvars\BehatVariablesExtension: ~
proxy:
  suites:
    default:
      contexts:
        - ProxyFeatureContext

simple loads one local Context, proxy loads another. simple must have the extension, proxy must not.

Combined, they run tests that should pass entirely. Currently, this is my run-tests script:

vendor/bin/behat --profile=proxy --format-settings='{"paths":false}' features/proxy.feature &&
echo &&
vendor/bin/behat --profile=simple --format-settings='{"paths":false}' features/simple.feature

Not only is it ugly, it doesn't work properly. The && make sure the right result is passed on to the run-tests caller, but they also mean the 2nd tests isn't run if the 1st test fails.

How do I keep both:

  • Both tests must run
  • The exit code must be the last fail (or 1 if any fails)

I don't want to make run-tests more complicated, so this is more a Behat question than Bash. Can I tell Behat to run 2 profiles with separate features and return the combined result?


Solution

  • Something like this, perhaps?

    result=0
    cmds1 || result=$?
    echo
    cmds2 || result=$?
    exit $result
    

    If one of the commands fail, the exit code from the failure is propagated to the caller. (If both fail, the last failure is the one we pass back to the caller.) When a test succeeds, we don't touch the result variable. If both succeed, it remains at zero (success).