Makefile 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. GO ?= go
  2. GOFMT ?= gofmt "-s"
  3. PACKAGES ?= $(shell $(GO) list ./...)
  4. VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/)
  5. GOFILES := $(shell find . -name "*.go")
  6. TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|binding$$|render$$' | grep -v examples)
  7. TESTTAGS ?= ""
  8. .PHONY: test
  9. test:
  10. echo "mode: count" > coverage.out
  11. for d in $(TESTFOLDER); do \
  12. $(GO) test -tags $(TESTTAGS) -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \
  13. cat tmp.out; \
  14. if grep -q "^--- FAIL" tmp.out; then \
  15. rm tmp.out; \
  16. exit 1; \
  17. elif grep -q "build failed" tmp.out; then \
  18. rm tmp.out; \
  19. exit 1; \
  20. elif grep -q "setup failed" tmp.out; then \
  21. rm tmp.out; \
  22. exit 1; \
  23. fi; \
  24. if [ -f profile.out ]; then \
  25. cat profile.out | grep -v "mode:" >> coverage.out; \
  26. rm profile.out; \
  27. fi; \
  28. done
  29. .PHONY: fmt
  30. fmt:
  31. $(GOFMT) -w $(GOFILES)
  32. .PHONY: fmt-check
  33. fmt-check:
  34. @diff=$$($(GOFMT) -d $(GOFILES)); \
  35. if [ -n "$$diff" ]; then \
  36. echo "Please run 'make fmt' and commit the result:"; \
  37. echo "$${diff}"; \
  38. exit 1; \
  39. fi;
  40. vet:
  41. $(GO) vet $(VETPACKAGES)
  42. .PHONY: lint
  43. lint:
  44. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  45. $(GO) get -u golang.org/x/lint/golint; \
  46. fi
  47. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  48. .PHONY: misspell-check
  49. misspell-check:
  50. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  51. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  52. fi
  53. misspell -error $(GOFILES)
  54. .PHONY: misspell
  55. misspell:
  56. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  57. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  58. fi
  59. misspell -w $(GOFILES)
  60. .PHONY: tools
  61. tools:
  62. go install golang.org/x/lint/golint; \
  63. go install github.com/client9/misspell/cmd/misspell;