1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#! /bin/zsh
Red="\033[0;31m"
Green='\033[0;32m'
Color_Off='\033[0m'
# use richgo if it is availalbe
[[ -x "$(which richgo)" ]] && BIN='richgo' || BIN='go'
# ensure ripgrep installed
if ! [ -x "$(which rg)" ]; then
echo -e "${Red} please install ripgrep: ${Color_Off}\n brew install ripgrep"
return 1
fi
if [ -z "$1" ]; then
echo "must specify a test target or path"
return 1
fi
PACKAGE_STR="${1//[$\^]/}"
SEARCH_STR=$(echo $PACKAGE_STR | cut -d '/' -f-1)
FILTER=""
IFS=$'\n'
PACKAGE_DIRS=($(rg --files | rg $PACKAGE_STR | xargs dirname | sort | uniq | sed 's|^|./|g' | sed 's|$|/...|g'))
DIRS=("${PACKAGE_DIRS[@]}")
FILE_DIRS=()
# if we didn't find any files with the name of the filter then we must be looking for a test name
if [[ ${#PACKAGE_DIRS[@]} = 0 ]]; then
FILE_DIRS=($(rg -l "$SEARCH_STR" | xargs dirname | sort | uniq | sed 's|^|./|g' | sed 's|$|/...|g'))
DIRS=("${PACKAGE_DIRS[@]}" "${FILE_DIRS[@]}")
fi
# if we have files generated from finding the symbol in a test then filter the tests
if [[ ${#FILE_DIRS[@]} -ge 1 ]]; then
FILTER="-run $1 "
fi
shift
OTHER_ARGS="$(printf '%s ' ${@[*]})"
DIR_STR=$(printf '%s ' ${DIRS[*]})
CMD="$(printf '%s test %s %s %s' $BIN ${DIR_STR} $FILTER $OTHER_ARGS)"
echo -e "${Green} Running Cmd:\n ${CMD} ${Color_Off}\n"
eval "$CMD"
|