-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (56 loc) · 2.83 KB
/
Makefile
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
.DEFAULT_GOAL := help
.PHONY: help
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
DOCKER_TEST_COMMAND=docker run --rm -v $(PWD):/gaddag golang:1.14 sh -c "cd /gaddag; go mod download;
COLOR_TEST_OUTPUT=sed ''/^ok/s//$$(printf "\033[32mPASS\033[0m")/'' | sed ''/FAIL/s//$$(printf "\033[31mFAIL\033[0m")/''
TEE_COMMAND=tee -a /tmp/results.tmp
_MAKE=$(MAKE) --no-print-directory
# -----------------------------------------------------------------------------
# Tests
# -----------------------------------------------------------------------------
unit: ## Run unit tests in Docker.
@echo -e ${GREEN}UNIT TESTS${NC}
@${DOCKER_TEST_COMMAND} go test ./... -cover" | ${COLOR_TEST_OUTPUT}
golden-update: ## Update golden files.
@echo -e ${GREEN}GOLDENFILES UPDATE${NC}
@find . -name "*.golden" -type f -delete
@${DOCKER_TEST_COMMAND} go test ./... -update" | ${COLOR_TEST_OUTPUT}
bench: ## Run benchmark tests in Docker.
@echo -e ${GREEN}BENCHMARK TESTS${NC}
@${DOCKER_TEST_COMMAND} go test ./... -bench=. -run=^a"
game-bench: ## Run example game benchmark tests in Docker.
@echo -e ${GREEN}BENCHMARK TESTS - GAME ONLY${NC}
@${DOCKER_TEST_COMMAND} go test ./... -benchtime=50x -bench=Benchmark_Game -run=^a"
# -----------------------------------------------------------------------------
# Run example game
# -----------------------------------------------------------------------------
_game-run-X:
@${DOCKER_TEST_COMMAND} cd exampleGame; go run main.go -times=$(NUM) -winshot -loglevel=info" | ${TEE_COMMAND}
game-run: ## Run example game
@rm -f $(PWD)/exampleGame/img/*.png
@${DOCKER_TEST_COMMAND} cd exampleGame; go run main.go -screenshot -loglevel=panic"
game-10: ## Run 10 example games
@${_MAKE} _game-run-X NUM=10
game-100: ## Run 100 example games
@${_MAKE} _game-run-X NUM=100
game-run-X: ## Run X example games. Pass NUM=XXX
@${_MAKE} _game-run-X
@${_MAKE} game-get-average
@${_MAKE} game-get-average-player
game-clean: ## Clean after example game
@rm -f $(PWD)/exampleGame/img/*.png
@rm /tmp/results.tmp
# -----------------------------------------------------------------------------
# Get statistics
# -----------------------------------------------------------------------------
game-get-average: ## Get average points from log file
@cat /tmp/results.tmp | awk '{ sum += $$7 } END { if (NR > 0) print "Average winning points: " sum / NR }'
game-get-average-player: ## Get average player winner
@cat /tmp/results.tmp | awk '{ sum += $$5 } END { if (NR > 0) print "Average winning player: " sum / NR }'
# -----------------------------------------------------------------------------
# Other
# -----------------------------------------------------------------------------
help: ## Show this help.
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'