Skip to content

Commit

Permalink
Merge pull request #8858 from gyuho/aaa
Browse files Browse the repository at this point in the history
test: clean up fmt tests
  • Loading branch information
gyuho committed Nov 29, 2017
2 parents dbd1787 + 27519ff commit 4ad8bd9
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -274,52 +274,54 @@ function release_pass {
mv /tmp/etcd ./bin/etcd-last-release
}

function fmt_pass {
toggle_failpoints disable

echo "Checking gofmt..."
function gofmt_pass {
fmtRes=$(gofmt -l -s -d "${FMT[@]}")
if [ -n "${fmtRes}" ]; then
echo -e "gofmt checking failed:\n${fmtRes}"
exit 255
fi
}

echo "Checking govet..."
function govet_pass {
vetRes=$(go vet "${TEST[@]}")
if [ -n "${vetRes}" ]; then
echo -e "govet checking failed:\n${vetRes}"
exit 255
fi
}

echo "Checking 'go tool vet -all -shadow'..."
function govet_shadow_pass {
fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
fmtpkgs=($fmtpkgs)
vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
if [ -n "${vetRes}" ]; then
echo -e "govet -all -shadow checking failed:\n${vetRes}"
exit 255
fi
}

function shellcheck_pass {
if which shellcheck >/dev/null; then
echo "Checking shellcheck..."
shellcheckResult=$(shellcheck -fgcc build test scripts/* 2>&1 || true)
if [ -n "${shellcheckResult}" ]; then
echo -e "shellcheck checking failed:\n${shellcheckResult}"
exit 255
fi
fi
}

echo "Checking documentation style..."
function markdown_you_pass {
# eschew you
yous=$(find . -name \*.md -exec grep -E --color "[Yy]ou[r]?[ '.,;]" {} + | grep -v /v2/ || true)
if [ ! -z "$yous" ]; then
echo -e "found 'you' in documentation:\n${yous}"
exit 255
fi
}

function markdown_marker_pass {
# TODO: check other markdown files when marker handles headers with '[]'
if which marker >/dev/null; then
echo "Checking marker to find broken links..."
markerResult=$(marker --skip-http --root ./Documentation 2>&1 || true)
if [ -n "${markerResult}" ]; then
echo -e "marker checking failed:\n${markerResult}"
Expand All @@ -328,9 +330,10 @@ function fmt_pass {
else
echo "Skipping marker..."
fi
}

function goword_pass {
if which goword >/dev/null; then
echo "Checking goword..."
# get all go files to process
gofiles=$(find "${FMT[@]}" -iname '*.go' 2>/dev/null)
gofiles_all=($gofiles)
Expand All @@ -352,9 +355,10 @@ function fmt_pass {
else
echo "Skipping goword..."
fi
}

function gosimple_pass {
if which gosimple >/dev/null; then
echo "Checking gosimple..."
gosimpleResult=$(gosimple "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${gosimpleResult}" ]; then
echo -e "gosimple checking failed:\n${gosimpleResult}"
Expand All @@ -363,9 +367,10 @@ function fmt_pass {
else
echo "Skipping gosimple..."
fi
}

function unused_pass {
if which unused >/dev/null; then
echo "Checking unused..."
unusedResult=$(unused "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${unusedResult}" ]; then
echo -e "unused checking failed:\n${unusedResult}"
Expand All @@ -374,9 +379,10 @@ function fmt_pass {
else
echo "Skipping unused..."
fi
}

function staticcheck_pass {
if which staticcheck >/dev/null; then
echo "Checking staticcheck..."
staticcheckResult=$(staticcheck "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${staticcheckResult}" ]; then
# TODO: resolve these after go1.8 migration
Expand All @@ -393,9 +399,10 @@ function fmt_pass {
else
echo "Skipping staticcheck..."
fi
}

function ineffassign_pass {
if which ineffassign >/dev/null; then
echo "Checking ineffassign..."
ineffassignResult=$(ineffassign "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${ineffassignResult}" ]; then
echo -e "ineffassign checking failed:\n${ineffassignResult}"
Expand All @@ -404,9 +411,10 @@ function fmt_pass {
else
echo "Skipping ineffassign..."
fi
}

function nakedret_pass {
if which nakedret >/dev/null; then
echo "Checking nakedret..."
nakedretResult=$(nakedret "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
if [ -n "${nakedretResult}" ]; then
echo -e "nakedret checking failed:\n${nakedretResult}"
Expand All @@ -415,8 +423,9 @@ function fmt_pass {
else
echo "Skipping nakedret..."
fi
}

echo "Checking for license header..."
function license_header_pass {
licRes=""
files=$(find . -type f -iname '*.go' ! -path './cmd/*' ! -path './gopath.proto/*')
for file in $files; do
Expand All @@ -428,8 +437,9 @@ function fmt_pass {
echo -e "license header checking failed:\n${licRes}"
exit 255
fi
}

echo "Checking receiver names..."
function receiver_name_pass {
recvs=$(grep 'func ([^*]' {*,*/*,*/*/*}.go | grep -Ev "(generated|pb/)" | tr ':' ' ' | \
awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\.]*go//g" | sort | uniq | \
grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ')
Expand All @@ -441,8 +451,9 @@ function fmt_pass {
done
exit 255
fi
}

echo "Checking commit titles..."
function commit_title_pass {
git log --oneline "$(git merge-base HEAD master)"...HEAD | while read -r l; do
commitMsg=$(echo "$l" | cut -f2- -d' ')
if [[ "$commitMsg" == Merge* ]]; then
Expand All @@ -466,6 +477,31 @@ function fmt_pass {
done
}

function fmt_pass {
toggle_failpoints disable

for p in gofmt \
govet \
govet_shadow \
shellcheck \
markdown_you \
markdown_marker \
goword \
gosimple \
unused \
staticcheck \
ineffassign \
nakedret \
license_header \
receiver_name \
commit_title \
; do
echo "Starting '$p' pass at $(date)"
"${p}"_pass "$@"
echo "Finished '$p' pass at $(date)"
done
}

function bom_pass {
if ! which license-bill-of-materials >/dev/null; then
return
Expand Down

0 comments on commit 4ad8bd9

Please sign in to comment.