diff --git a/test b/test index 1cf4c247a161..3631f31d5a35 100755 --- a/test +++ b/test @@ -627,6 +627,7 @@ function fmt_pass { license_header \ receiver_name \ commit_title \ + mod_tidy \ ; do echo "'$p' started at $(date)" "${p}"_pass "$@" @@ -684,6 +685,35 @@ function build_pass { GO_BUILD_FLAGS="-v" tools_build } +function mod_tidy_pass { + # Watch for upstream solution: https://github.com/golang/go/issues/27005 + local tmpFileGoMod=$(tempfile -s "_go.mod") + local tmpFileGoSum=$(tempfile -s "_go.sum") + cp "./go.mod" "${tmpFileGoMod}" + cp "./go.sum" "${tmpFileGoSum}" + go mod tidy + + set +e + diff -C 5 "${tmpFileGoMod}" "./go.mod" + local tmpFileGoModInSync="$?" + diff -C 5 "${tmpFileGoSum}" "./go.sum" + local tmpFileGoSumInSync="$?" + set -e + + # Bring back initial state + mv "${tmpFileGoMod}" "./go.mod" + mv "${tmpFileGoSum}" "./go.sum" + + if [ "${tmpFileGoModInSync}" -ne 0 ]; then + echo "./go.mod is not in sync with 'go mod tidy'" + exit 255 + fi + if [ "${tmpFileGoSumInSync}" -ne 0 ]; then + echo "./go.sum is not in sync with 'go mod tidy'" + exit 255 + fi +} + for pass in $PASSES; do echo "Starting '$pass' pass at $(date)" "${pass}"_pass "$@"