Created
September 26, 2019 23:09
-
-
Save kissgyorgy/5dbe83dc684c7cd18ee4a6e3da425747 to your computer and use it in GitHub Desktop.
Bash: Run go tests with rakyll/gotest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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