Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (91 loc) · 3.32 KB
/
Copy pathMakefile
File metadata and controls
101 lines (91 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
.PHONY: clean
TARGET_DIR = ./dist
GO_COV_MERGE = ${GOPATH}/bin/gocovmerge
GO_GOJUNIT = ${GOPATH}/bin/go-junit-report
GO_COBERTURA = ${GOPATH}/bin/gocover-cobertura
PKGS_COMMA_SEP = go list -f '{{ join .Deps "\n" }}{{"\n"}}{{.ImportPath}}' . | grep github.com/ovh/cds | grep -v vendor | tr '\n' ',' | sed 's/,$$//'
TEST_PKGS = $(shell go list ./...)
TEST_CMD = go test -tags skipkeychaintests -v -timeout 600s -coverprofile=profile.coverprofile
$(GO_COV_MERGE):
go get -u github.com/wadey/gocovmerge
$(GO_GOJUNIT):
go get -u github.com/jstemmer/go-junit-report
$(GO_COBERTURA):
go get -u github.com/richardlt/gocover-cobertura
$(TARGET_DIR):
@mkdir -p $(TARGET_DIR)
clean:
@rm -rf $(TARGET_DIR)
@for TST in `find ./ -name "tests.log"`; do \
rm $$TST; \
done;
@for profile in `find ./ -name "*.coverprofile"`; do \
rm $$profile; \
done;
test: clean
$(info $(TEST_PKGS))
@for PKG in $(TEST_PKGS); do \
echo "Running tests in package $$PKG"; \
cd ${GOPATH}/src/$$PKG; \
TEMP=`$(PKGS_COMMA_SEP)`; \
if [ ! -z "$$TEMP" ]; then \
$(TEST_CMD) -coverpkg $$TEMP > ${GOPATH}/src/$$PKG/tests.log; \
else \
$(TEST_CMD) > ${GOPATH}/src/$$PKG/tests.log; \
fi; \
done; \
echo "Lancement du coverage"
$(MAKE) test-coverage
$(MAKE) test-xunit-report
test-coverage: $(GO_COV_MERGE) $(TARGET_DIR) $(GO_COBERTURA)
@echo "Generating unit tests coverage..."
@$(GO_COV_MERGE) `find ./ -name "*.coverprofile"` > $(TARGET_DIR)/cover.out
@$(GO_COBERTURA) < $(TARGET_DIR)/cover.out > $(TARGET_DIR)/coverage.xml
@go tool cover -html=$(TARGET_DIR)/cover.out -o=$(TARGET_DIR)/cover.html
# <testsuite name="github.com/ovh/cds/engine/api" tests="133" errors="0" failures="2" skip="0">
test-xunit-report: $(GO_GOJUNIT) $(TARGET_DIR)
@echo "Generating xUnit Report..."
@for TST in `find . -name "tests.log"`; do \
if [ -s $$TST ]; then \
FAILED=`grep -E '(FAIL)+\s([a-z\.\/]*)\s\[build failed\]' $$TST | wc -l`; \
if [ $$FAILED -gt 0 ]; then \
echo "Build Failed \t\t\t($$TST)"; \
echo "Build Failed \t\t\t($$TST)" >> $(TARGET_DIR)/fail; \
else \
NO_TESTS=`grep -E '\?+\s+([a-z\.\/]*)\s\[no test files\]' $$TST | wc -l`; \
if [ $$NO_TESTS -gt 0 ]; then \
echo "No tests found \t\t\t($$TST)"; \
else \
if [ "$$TST" = "./tests.log" ]; then \
PACKAGE=cli; \
else \
PACKAGE=cli_`echo $$TST | sed 's|./||' | sed 's|/|_|g' | sed 's|_tests.log||'`; \
fi; \
XUNIT_OUT=$(TARGET_DIR)/$$PACKAGE.xml; \
echo "Generating xUnit report from \t$$TST.xml to $$XUNIT_OUT"; \
cat $$TST | $(GO_GOJUNIT) > $$XUNIT_OUT; \
TESTS_LOG_OUT=$(TARGET_DIR)/$$PACKAGE.log; \
echo "Copy tests log from \t$$TST.xml to $$TESTS_LOG_OUT"; \
cp $$TST $$TESTS_LOG_OUT; \
fi; \
fi; \
else \
echo "Ignoring empty file \t\t$$TST"; \
fi; \
done; \
xutools pretty --show-failures ./dist/*.xml > $(TARGET_DIR)/report; \
xutools sort-duration ./dist/*.xml > $(TARGET_DIR)/duration; \
if [ -e $(TARGET_DIR)/report ]; then \
echo "Report:"; \
cat $(TARGET_DIR)/report; \
fi; \
if [ -e $(TARGET_DIR)/duration ]; then \
echo "Max duration:"; \
cat $(TARGET_DIR)/duration; \
fi; \
if [ -e $(TARGET_DIR)/fail ]; then \
echo "#########################"; \
echo "ERROR: Test compilation failure"; \
cat $(TARGET_DIR)/fail; \
exit 1; \
fi;