Skip to content

Instantly share code, notes, and snippets.

@codenamev
Created September 8, 2017 15:22
Show Gist options
  • Save codenamev/892814eec102aedce75911f318a4dbd6 to your computer and use it in GitHub Desktop.
Save codenamev/892814eec102aedce75911f318a4dbd6 to your computer and use it in GitHub Desktop.
Pass/Fail command wrapper
#!/usr/bin/env bash
#
# Usage: set any of the following environment variables to get run before
# tests or after success/failure
#
# PASS_FAIL_INIT_COMMAND - is run before tests run
# PASS_COMMAND - is run after tests if they all pass
# FAIL_COMMAND - is run after tests if there are any failrues
set -e
init_command="$PASS_FAIL_INIT_COMMAND"
pass_command="$PASS_COMMAND"
fail_command="$FAIL_COMMAND"
if [ -n "$init_command" ]; then
$init_command
fi
if [ -z "$pass_command" ]; then
pass_command="exit 1"
fi
if [ -z "$fail_command" ]; then
fail_command="exit 1"
fi
$@ && $pass_command || $fail_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment