This commit is contained in:
Alain Jobart 2014-04-30 13:43:22 -07:00
Родитель d5970bf4a6
Коммит 166937eb27
2 изменённых файлов: 35 добавлений и 1 удалений

Просмотреть файл

@ -15,8 +15,11 @@ clean:
unit_test:
go test ./go/...
# Run the code coverage tools, compute aggregate.
# If you want to improve in a directory, run:
# go test -coverprofile=coverage.out && go tool cover -html=coverage.out
unit_test_cover:
go test -cover ./go/...
go test -cover ./go/... | misc/parse_cover.py
unit_test_race:
go test -race ./go/...

31
misc/parse_cover.py Executable file
Просмотреть файл

@ -0,0 +1,31 @@
#!/usr/bin/python
# this is a small helper script to parse test coverage and display stats.
import re
import sys
coverage_pattern = re.compile(r"coverage: (\d+).(\d+)% of statements")
no_test_file_count = 0
coverage_count = 0
coverage_sum = 0.0
for line in sys.stdin:
print line,
sys.stdout.flush
if line.find('[no test files]') != -1:
no_test_file_count += 1
continue
m = coverage_pattern.search(line)
if m != None:
coverage_count += 1
coverage_sum += float(m.group(1) + "." + m.group(2))
continue
directories_covered = coverage_count * 100 / (no_test_file_count + coverage_count)
average_coverage = coverage_sum / coverage_count
print "Directory test coverage: %u%%" % directories_covered
print "Average test coverage: %u%%" % int(average_coverage)