Skip to content

Commit

Permalink
💚循環的複雑度のテストを追加いたしましたわ♻️ #65 (#69)
Browse files Browse the repository at this point in the history
* 循環的複雑度のテストを追加

* add CI
  • Loading branch information
jiro4989 authored Jul 10, 2022
1 parent a77582e commit 0d038ca
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ jobs:
- run: go test -cover ./...
- run: ./ojosama README.adoc

cyclomatic-complexity:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.goversion }}
- run: make setup-tools
- run: ./scripts/test_cyclomatic_complexity.sh

coverage:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ bin/ojosama: go.* *.go cmd/* internal/*
.PHONY: test
test:
go test -cover ./...
which gocyclo && ./scripts/test_cyclomatic_complexity.sh

.PHONY: install
install: go.* *.go cmd/* internal/*
go install ./cmd/ojosama

.PHONY: setup-tools
setup-tools:
go install github.com/fzipp/gocyclo/cmd/[email protected]
36 changes: 36 additions & 0 deletions scripts/test_cyclomatic_complexity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -eu

err() {
echo "[ERR] $*" >&2
}

info() {
echo "[INF] $*"
}

script_err() {
err "failed the cyclomatic complexity test"
}

if ! which gocyclo > /dev/null; then
err "please install gocyclo (https://github.com/fzipp/gocyclo)"
script_err
exit 1
fi

gocyclo . | awk '21<=$1' > result.txt
err_count="$(wc -l < result.txt)"
if [[ 0 -lt "$err_count" ]]; then
err "the cyclomatic complexity is 21 or higher. please fix those funcitons"
err "---------------------------------------------------------------------"
cat result.txt >&2
err "---------------------------------------------------------------------"
script_err
rm result.txt
exit 1
fi

rm result.txt
info "passed the cyclomatic complexity test"

0 comments on commit 0d038ca

Please sign in to comment.