Skip to content

Commit

Permalink
build: Rework test script to use go.mod files.
Browse files Browse the repository at this point in the history
This reworks the logic in the test run script for determining which
modules to test to use the existence of a go.mod file instead of
attempting to use the result of go list.

The existing logic is to determine the root module via go list and then
test everything that has that as a prefix.  However, that is error prone
because indirect dependencies may depend on older versions of modules
that are no longer in the repo, but naturally still have the prefix that
is specified to test.

Searching for the go.mod files in the repo isn't prone to the
aforementioned issue and is generally more robust because it will always
be recent as of the current state of the repo and it still has the
benefit of dynamically finding all modules in the repo.
  • Loading branch information
davecgh committed Jun 12, 2024
1 parent 55596c2 commit e40baa9
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,27 @@ set -ex
go version

# run tests on all modules
echo "==> test all modules"
ROOTPKG=$(go list)
go test -short -tags rpctest $ROOTPKG/... -- "$@"
MODULES=$(find . -name go.mod -not -path "./playground/*")
for module in $MODULES; do
# determine module name/directory
MODNAME=$(echo $module | sed -E -e 's,/go\.mod$,,' -e 's,^./,,')
if [ -z "$MODNAME" ]; then
MODNAME=.
fi

echo "==> test ${MODNAME}"

# run commands in the module directory as a subshell
(
cd $MODNAME

# run tests if there are any _test files.
tfiles=$(find . -maxdepth 1 -name '*_test.go' 2>/dev/null | xargs)
if [ -n "$tfiles" ]; then
go test -short -tags ./... -- "$@"
fi
)
done

# run linters on all modules
. ./lint.sh
Expand Down

0 comments on commit e40baa9

Please sign in to comment.