2016-05-09 12:41:01 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
2016-05-09 12:49:38 +00:00
|
|
|
from subprocess import check_call, check_output
|
2016-05-09 12:41:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
PACKAGE_NAME = os.environ.get(
|
|
|
|
'CLI_PACKAGE_NAME', 'github.com/codegangsta/cli'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-05-09 12:58:20 +00:00
|
|
|
def main(sysargs=sys.argv[:]):
|
|
|
|
target = 'test'
|
|
|
|
if len(sysargs) > 1:
|
|
|
|
target = sysargs[1]
|
2016-05-09 12:41:01 +00:00
|
|
|
|
2016-05-09 12:58:20 +00:00
|
|
|
{
|
|
|
|
'vet': _vet,
|
|
|
|
'test': _test,
|
|
|
|
'gfmxr': _gfmxr
|
|
|
|
}[target]()
|
2016-05-09 12:49:38 +00:00
|
|
|
|
2016-05-09 12:58:20 +00:00
|
|
|
return 0
|
2016-05-09 12:49:38 +00:00
|
|
|
|
|
|
|
|
2016-05-09 12:58:20 +00:00
|
|
|
def _test():
|
|
|
|
if check_output('go version'.split()).split()[2] < 'go1.2':
|
2016-05-09 12:49:38 +00:00
|
|
|
_run('go test -v ./...'.split())
|
2016-05-09 12:58:20 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
coverprofiles = []
|
|
|
|
for subpackage in ['', 'altsrc']:
|
|
|
|
coverprofile = 'cli.coverprofile'
|
|
|
|
if subpackage != '':
|
|
|
|
coverprofile = '{}.coverprofile'.format(subpackage)
|
|
|
|
|
|
|
|
coverprofiles.append(coverprofile)
|
|
|
|
|
|
|
|
_run('go test -v'.split() + [
|
|
|
|
'-coverprofile={}'.format(coverprofile),
|
|
|
|
'{}/{}'.format(PACKAGE_NAME, subpackage)
|
|
|
|
])
|
|
|
|
|
|
|
|
combined = _combine_coverprofiles(coverprofiles)
|
|
|
|
_run('go tool cover -func={}'.format(combined.name).split())
|
|
|
|
combined.close()
|
2016-05-09 12:41:01 +00:00
|
|
|
|
2016-05-09 12:58:20 +00:00
|
|
|
|
|
|
|
def _gfmxr():
|
2016-05-09 12:41:01 +00:00
|
|
|
_run(['gfmxr', '-c', str(_gfmxr_count()), '-s', 'README.md'])
|
2016-05-09 12:58:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _vet():
|
|
|
|
_run('go vet ./...'.split())
|
2016-05-09 12:41:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _run(command):
|
|
|
|
print('runtests: {}'.format(' '.join(command)), file=sys.stderr)
|
|
|
|
check_call(command)
|
|
|
|
|
|
|
|
|
|
|
|
def _gfmxr_count():
|
|
|
|
with open('README.md') as infile:
|
|
|
|
lines = infile.read().splitlines()
|
|
|
|
return len(filter(_is_go_runnable, lines))
|
|
|
|
|
|
|
|
|
|
|
|
def _is_go_runnable(line):
|
|
|
|
return line.startswith('package main')
|
|
|
|
|
|
|
|
|
|
|
|
def _combine_coverprofiles(coverprofiles):
|
|
|
|
combined = tempfile.NamedTemporaryFile(suffix='.coverprofile')
|
|
|
|
combined.write('mode: set\n')
|
|
|
|
|
|
|
|
for coverprofile in coverprofiles:
|
|
|
|
with open(coverprofile, 'r') as infile:
|
|
|
|
for line in infile.readlines():
|
|
|
|
if not line.startswith('mode: '):
|
|
|
|
combined.write(line)
|
|
|
|
|
|
|
|
combined.flush()
|
|
|
|
return combined
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|