github.com/yaoapp/kun@v0.9.0/Makefile (about)

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