diff --git a/.travis.yml b/.travis.yml index 2d987e3..154db75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,8 @@ install: script: - docker-compose up --exit-code-from tests after_success: + - ls /tmp/taskwiki-coverage + - mv /tmp/taskwiki-coverage/.coverage.* . || echo ok + - coverage combine + - coverage report - coveralls diff --git a/Dockerfile b/Dockerfile index 6e6a1aa..7e42766 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,10 +28,10 @@ RUN cd /root/.vim/bundle; git clone https://github.com/vimwiki/vimwiki.git RUN cd /root/.vim/bundle/vimwiki/; git checkout dev # Setup taskwiki -RUN pip3 install nose pytest pytest-cov coveralls coverage vimrunner +RUN pip3 install nose pytest coveralls coverage vimrunner ADD requirements.txt requirements.txt RUN pip3 install -r requirements.txt RUN mkdir /root/.vim/bundle/taskwiki WORKDIR /root/.vim/bundle/taskwiki -CMD ["sh", "-c", "python3 -m pytest -vv --cov tests/"] +CMD ["sh", "-c", "python3 -m pytest -vv tests/"] diff --git a/Makefile b/Makefile index 940a697..06c6d54 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,3 @@ test: + - mkdir -p /tmp/taskwiki-coverage - docker-compose up diff --git a/ftplugin/vimwiki/taskwiki.vim b/ftplugin/vimwiki/taskwiki.vim index b3d7ea1..28174ad 100644 --- a/ftplugin/vimwiki/taskwiki.vim +++ b/ftplugin/vimwiki/taskwiki.vim @@ -27,6 +27,11 @@ endif " Determine the plugin path let s:plugin_path = escape(expand(':p:h:h:h'), '\') +" Run the measure parts first, if desired +if exists("g:taskwiki_measure_coverage") + execute 'py3file ' . s:plugin_path . '/knowledge/testcoverage.py' +endif + " Execute the main body of taskwiki source execute g:taskwiki_pyfile . s:plugin_path . '/taskwiki/main.py' diff --git a/taskwiki/testcoverage.py b/taskwiki/testcoverage.py new file mode 100644 index 0000000..37242af --- /dev/null +++ b/taskwiki/testcoverage.py @@ -0,0 +1,20 @@ +import os +import atexit +import coverage + +class CoverageSaver(object): + + def __init__(self, cov): + self.cov = cov + + def __call__(self): + self.cov.stop() + self.cov.save() + + +coverage_path = '/tmp/taskwiki-coverage/.coverage.{0}'.format(os.getpid()) +cov = coverage.coverage(data_file=coverage_path) +cov.start() + +saver = CoverageSaver(cov) +atexit.register(saver) diff --git a/tests/base.py b/tests/base.py index 78afd1b..3e310ea 100644 --- a/tests/base.py +++ b/tests/base.py @@ -70,6 +70,7 @@ class IntegrationTest(object): self.command('let g:taskwiki_data_location="{0}"'.format(self.dir)) self.command('let g:taskwiki_taskrc_location="{0}"'.format(self.taskrc_path)) self.command("let g:vimwiki_list = [{'syntax': 'mediawiki', 'ext': '.txt','path': '%s'}]" % self.dir) + self.command('let g:taskwiki_measure_coverage="yes"') def setup(self): self.generate_data()