github.com/KEINOS/go-countline@v1.1.1-0.20221217083629-60710df7606b/makefile (about)

     1  # =============================================================================
     2  #  Makefile for testing
     3  # =============================================================================
     4  #  If you have `make` command installed, you can run the tests as below:
     5  #
     6  #      make test ... Run unit tests, lint check, static analysis and coverage
     7  #                    check.
     8  #      make bench ... Run benchmark. `benchstat` is required to run this. See
     9  #                     the comment in the "bench:" section.
    10  #      make test_docker ... Run unit tests with different versions of Go in a
    11  #                           Docker container.
    12  #  Note:
    13  #    These tests will generate test data under ./cl/testdata directory. It
    14  #    contains GiB size of data, so don't forget to remove them after finish the
    15  #    test/dev.
    16  # =============================================================================
    17  
    18  .SILENT:
    19  
    20  # -----------------------------------------------------------------------------
    21  #  Tests for local run
    22  # -----------------------------------------------------------------------------
    23  test: gen_data unit_test lint coverage
    24  
    25  # gen_data generates test data under ./cl/testdata directory. It contains GiB size
    26  # of data, so don't forget to remove them after finish the test/dev.
    27  gen_data:
    28  	go mod download
    29  	go generate ./...
    30  
    31  # unit_test will run unit tests with race detector and coverage check.
    32  unit_test: gen_data
    33  	go test -cover -race -coverprofile=coverage.out \
    34  		./... \
    35  		github.com/KEINOS/go-countline/cl/_alt \
    36  		github.com/KEINOS/go-countline/cl/_gen \
    37  		github.com/KEINOS/go-countline/_example/countline
    38  
    39  # lint will run lint check and static analysis with golangci-lint.
    40  # For the configuration see: ../.golangci.yml
    41  lint:
    42  	golangci-lint run || exit 1
    43  	golangci-lint run ./cl/_alt || exit 1
    44  	golangci-lint run ./cl/_gen || exit 1
    45  	golangci-lint run ./_example/countline || exit 1
    46  
    47  # coverage will fail if the total coverage is not 100%.
    48  coverage: unit_test
    49  	set -euo pipefail
    50  	go tool cover -func=coverage.out | tail -n 1 | grep 100.0% || (echo "Total coverage is not 100.0%"; exit 1)
    51  
    52  # bench will benchmark with various size of data.
    53  #
    54  # Note: `benchstat` is required to run this.
    55  #   $ go install golang.org/x/perf/cmd/benchstat@latest
    56  bench: gen_data
    57  	set -eu -o pipefail
    58  
    59  	printf "Benchmarking with light weight datas ... "
    60  	go test -benchmem -count 5 -benchtime 10s -bench Benchmark_light ./... > bench.txt
    61  	echo "OK"
    62  
    63  	printf "Benchmarking with heavy sized datas ... "
    64  	go test -benchmem -bench Benchmark_heavy ./... >> bench.txt
    65  	echo "OK"
    66  
    67  	printf "Benchmarking with a giant size data ... "
    68  	go test -benchmem -count 5 -bench Benchmark_giant ./... | tee -a bench.txt
    69  	echo "OK"
    70  
    71  	echo "Benchmark results:"
    72  	benchstat -sort delta bench.txt
    73  
    74  # -----------------------------------------------------------------------------
    75  #  Docker installed only tests for various Go versions
    76  # -----------------------------------------------------------------------------
    77  test_docker: build_docker go1_16 go1_17 go1_18 go1_19 go_latest
    78  
    79  # build_docker will build docker images for testing. It will pre-pull the base
    80  # images for consistency.
    81  build_docker:
    82  	set -eu -o pipefail
    83  	echo "[Building docker images]:"
    84  	printf "pulling ... "
    85  	docker pull --quiet golang:1.16-alpine
    86  	printf "pulling ... "
    87  	docker pull --quiet golang:1.17-alpine
    88  	printf "pulling ... "
    89  	docker pull --quiet golang:1.18-alpine
    90  	printf "pulling ... "
    91  	docker pull --quiet golang:1.19-alpine
    92  	printf "pulling ... "
    93  	docker pull --quiet golang:alpine
    94  	printf "building images ... "
    95  	docker compose --file ./.github/docker-compose.yml build --progress quiet
    96  	echo "OK"
    97  
    98  go1_16: build_docker
    99  	echo "[Unit testing in Go v1.16]:"
   100  	docker compose --file ./.github/docker-compose.yml run v1_16 || exit 1
   101  	echo "ok ... Go v1.16"
   102  
   103  go1_17: build_docker
   104  	echo "[Unit testing in Go v1.17]:"
   105  	docker compose --file ./.github/docker-compose.yml run v1_17 || exit 1
   106  	echo "ok ... Go v1.17"
   107  
   108  go1_18: build_docker
   109  	echo "[Unit testing in Go v1.18]:"
   110  	docker compose --file ./.github/docker-compose.yml run v1_18 || exit 1
   111  	echo "ok ... Go v1.18"
   112  
   113  go1_19: build_docker
   114  	echo "[Unit testing in Go v1.19]:"
   115  	docker compose --file ./.github/docker-compose.yml run v1_19 || exit 1
   116  	echo "ok ... Go v1.19"
   117  
   118  go_latest: build_docker
   119  	echo "[Unit testing in Go latest version]:"
   120  	docker compose --file ./.github/docker-compose.yml run latest || exit 1
   121  	echo "ok ... Go latest version"
   122  
   123  # prune will remove all pruned containers, images and volumes of Docker.
   124  #
   125  # Note: This is for maintenance purpose only. Do not use this unless you know
   126  #       what you are doing.
   127  prune:
   128  	printf "prune container ... "
   129  	docker container prune -f
   130  	printf "prune image ... "
   131  	docker image prune -f
   132  	printf "prune volumes ... "
   133  	docker volume prune -f
   134  	echo "OK"