From b9f33fbe6deac41734fe1768ab3d5fa73fc743e6 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 9 May 2016 08:41:01 -0400 Subject: [PATCH 1/4] Add a vet/test runner script with coverage on by default --- .gitignore | 1 + .travis.yml | 9 +++---- CHANGELOG.md | 1 + runtests | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100755 runtests diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7823778 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.coverprofile diff --git a/.travis.yml b/.travis.yml index 76f38a4..4f7bdd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: go + sudo: false go: @@ -8,16 +9,14 @@ go: - 1.4 - 1.5.4 - 1.6.2 -- tip +- master matrix: allow_failures: - - go: tip + - go: master before_script: - go get github.com/meatballhat/gfmxr/... script: -- go vet ./... -- go test -v ./... -- gfmxr -c $(grep -c 'package main' README.md) -s README.md +- ./runtests diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3d9c1..0403912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - `context.GlobalBoolT` was added as an analogue to `context.GlobalBool` - Support for hiding commands by setting `Hidden: true` -- this will hide the commands in help output +- `./runtests` test runner with coverage tracking by default ### Changed - `Float64Flag`, `IntFlag`, and `DurationFlag` default values are no longer diff --git a/runtests b/runtests new file mode 100755 index 0000000..fe8b013 --- /dev/null +++ b/runtests @@ -0,0 +1,70 @@ +#!/usr/bin/env python +from __future__ import print_function + +import os +import sys +import tempfile + +from subprocess import check_call + + +PACKAGE_NAME = os.environ.get( + 'CLI_PACKAGE_NAME', 'github.com/codegangsta/cli' +) + + +def main(): + _run('go vet ./...'.split()) + + 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() + + _run(['gfmxr', '-c', str(_gfmxr_count()), '-s', 'README.md']) + return 0 + + +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()) From 2df2fa514dddba4672c3b0b585cb72b98d1a8032 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 9 May 2016 08:49:38 -0400 Subject: [PATCH 2/4] Skip coverage bits on < go1.2 --- runtests | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/runtests b/runtests index fe8b013..923a80f 100755 --- a/runtests +++ b/runtests @@ -5,7 +5,7 @@ import os import sys import tempfile -from subprocess import check_call +from subprocess import check_call, check_output PACKAGE_NAME = os.environ.get( @@ -16,22 +16,25 @@ PACKAGE_NAME = os.environ.get( def main(): _run('go vet ./...'.split()) - coverprofiles = [] - for subpackage in ['', 'altsrc']: - coverprofile = 'cli.coverprofile' - if subpackage != '': - coverprofile = '{}.coverprofile'.format(subpackage) + if check_output('go version'.split()).split()[2] >= 'go1.2': + coverprofiles = [] + for subpackage in ['', 'altsrc']: + coverprofile = 'cli.coverprofile' + if subpackage != '': + coverprofile = '{}.coverprofile'.format(subpackage) - coverprofiles.append(coverprofile) + coverprofiles.append(coverprofile) - _run('go test -v'.split() + [ - '-coverprofile={}'.format(coverprofile), - '{}/{}'.format(PACKAGE_NAME, subpackage) - ]) + _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() + combined = _combine_coverprofiles(coverprofiles) + _run('go tool cover -func={}'.format(combined.name).split()) + combined.close() + else: + _run('go test -v ./...'.split()) _run(['gfmxr', '-c', str(_gfmxr_count()), '-s', 'README.md']) return 0 From d94fdb3e84260d33551531fec6722f863016fc2f Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 9 May 2016 08:58:20 -0400 Subject: [PATCH 3/4] Break runtests back into steps for more granular CI feedback --- .travis.yml | 4 +++- runtests | 62 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f7bdd7..b117165 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,4 +19,6 @@ before_script: - go get github.com/meatballhat/gfmxr/... script: -- ./runtests +- ./runtests vet +- ./runtests test +- ./runtests gfmxr diff --git a/runtests b/runtests index 923a80f..c295f0c 100755 --- a/runtests +++ b/runtests @@ -13,33 +13,51 @@ PACKAGE_NAME = os.environ.get( ) -def main(): - _run('go vet ./...'.split()) +def main(sysargs=sys.argv[:]): + target = 'test' + if len(sysargs) > 1: + target = sysargs[1] - if check_output('go version'.split()).split()[2] >= 'go1.2': - coverprofiles = [] - for subpackage in ['', 'altsrc']: - coverprofile = 'cli.coverprofile' - if subpackage != '': - coverprofile = '{}.coverprofile'.format(subpackage) + { + 'vet': _vet, + 'test': _test, + 'gfmxr': _gfmxr + }[target]() - 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() - else: - _run('go test -v ./...'.split()) - - _run(['gfmxr', '-c', str(_gfmxr_count()), '-s', 'README.md']) return 0 +def _test(): + if check_output('go version'.split()).split()[2] < 'go1.2': + _run('go test -v ./...'.split()) + 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() + + +def _gfmxr(): + _run(['gfmxr', '-c', str(_gfmxr_count()), '-s', 'README.md']) + + +def _vet(): + _run('go vet ./...'.split()) + + def _run(command): print('runtests: {}'.format(' '.join(command)), file=sys.stderr) check_call(command) From 5fa09b8e23737d63a6b7c51cde75248743067145 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 9 May 2016 09:00:22 -0400 Subject: [PATCH 4/4] Strip trailing slash for cleanliness --- runtests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtests b/runtests index c295f0c..162e23e 100755 --- a/runtests +++ b/runtests @@ -42,7 +42,7 @@ def _test(): _run('go test -v'.split() + [ '-coverprofile={}'.format(coverprofile), - '{}/{}'.format(PACKAGE_NAME, subpackage) + ('{}/{}'.format(PACKAGE_NAME, subpackage)).rstrip('/') ]) combined = _combine_coverprofiles(coverprofiles)