Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Created September 26, 2019 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kissgyorgy/5dbe83dc684c7cd18ee4a6e3da425747 to your computer and use it in GitHub Desktop.
Save kissgyorgy/5dbe83dc684c7cd18ee4a6e3da425747 to your computer and use it in GitHub Desktop.
Bash: Run go tests with rakyll/gotest
# Run gotest with the module name found in go.mod in the current directory
# gotest is: https://github.com/rakyll/gotest
gote () {
# run in a subshell, so errexit will exit the subshell, not the terminal shell
# https://unix.stackexchange.com/questions/207732/local-set-e-for-functions
(
set -eo pipefail
local options
local test_path
local module_name
if [[ $1 == \-* ]]; then
options="$1"
test_path="${2:-./...}"
else
options=""
test_path="${1:-./...}"
fi
module_name=$(head -1 <go.mod | cut -f2 -d" ")
echo "OPTIONS: $options, MODULE NAME: $module_name, TEST PATH: $test_path"
gotest $options $module_name/$test_path
)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment