Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ jobs:
run: go build -v ./...
- name: Test
run: go test -v -race ./...
- name: Coverage
if: matrix.go == '1.27.x'
run: make cover-check
- name: Upload coverage profile
if: matrix.go == '1.27.x'
uses: actions/upload-artifact@v4
with:
name: coverage
path: cover.lib.out
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
*.h264
.idea/
examples/playfromdisk/playfromdisk
examples/savetodisk/savetodisk
examples/savetodisk/savetodisk
cover.out
cover.lib.out
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
COVERPROFILE ?= cover.out
COVERPROFILE_LIB ?= cover.lib.out
COVER_THRESHOLD ?= 90

.PHONY: all build test lint fmt vet coverprofile cover cover-html cover-check clean

all: build test lint

build:
go build ./...

test:
go test -race ./...

lint:
golangci-lint run

fmt:
go fmt ./...

vet:
go vet ./...

# Run the full test suite with coverage. -coverpkg=./... is required so that the
# integrationtests package is credited with the library code it exercises. The
# examples are main packages with no tests so they are stripped from the profile
# the reports are built from.
coverprofile:
go test -covermode=atomic -coverpkg=./... -coverprofile=$(COVERPROFILE) ./...
grep -v '/examples/' $(COVERPROFILE) > $(COVERPROFILE_LIB)

cover: coverprofile
@go tool cover -func=$(COVERPROFILE_LIB)

cover-html: coverprofile
go tool cover -html=$(COVERPROFILE_LIB)

cover-check: coverprofile
@total=$$(go tool cover -func=$(COVERPROFILE_LIB) | awk '/^total:/ {print $$NF}' | tr -d '%'); \
echo "total coverage: $$total% (threshold: $(COVER_THRESHOLD)%)"; \
awk -v t="$$total" -v min=$(COVER_THRESHOLD) 'BEGIN { if (t+0 < min+0) { printf "coverage %s%% is below threshold %s%%\n", t, min; exit 1 } }'

clean:
rm -f $(COVERPROFILE) $(COVERPROFILE_LIB)
Loading