Skip to content

Commit

Permalink
Make test failures easier to see and understand.
Browse files Browse the repository at this point in the history
  • Loading branch information
monopole committed Feb 13, 2018
1 parent a90a3cf commit 824b51e
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,47 @@ cd "$base_dir" || {

rc=0

go_dirs() {
function go_dirs {
go list -f '{{.Dir}}' ./... | tr '\n' '\0'
}

echo "Running go fmt"
diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l)
rc=$((rc || $?))
function runTest {
local name=$1
local result="SUCCESS"
printf "============== begin %s\n" "$name"
$name
local code=$?
rc=$((rc || $code))
if [ $code -ne 0 ]; then
result="FAILURE"
fi
printf "============== end %s : %s code=%d\n\n\n" "$name" "$result" $code
}

function testGoFmt {
diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l)
}

function testGoImports {
diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l)
}

echo "Running goimports"
diff -u <(echo -n) <(go_dirs | xargs -0 goimports -l)
rc=$((rc || $?))
function testGoVet {
go vet -all ./...
}

echo "Running go vet"
go vet -all ./...
rc=$((rc || $?))
function testGoTest {
go test -v ./...
}

echo "Running go test"
go test -v ./...
rc=$((rc || $?))
function testTutorial {
mdrip --mode test --label test ./cmd/kinflate
}

echo "Testing kinflate demos"
mdrip --mode test --label test ./cmd/kinflate
rc=$((rc || $?))
runTest testGoFmt
runTest testGoImports
runTest testGoVet
runTest testGoTest
runTest testTutorial

exit $rc

0 comments on commit 824b51e

Please sign in to comment.