Skip to content

Commit

Permalink
Coverage reporting via covimerage (#107)
Browse files Browse the repository at this point in the history
This splits out the tests for cython, since the runtime file gets
reloaded for them, and that resets profiling information.
  • Loading branch information
blueyed authored Jul 21, 2018
1 parent 99991a3 commit c294334
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 57 deletions.
22 changes: 14 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
version: 2

common: &common
working_directory: ~/repo
docker:
- image: blueyed/vim-python-pep8-indent-vims-for-test:2@sha256:a7be5f4d07ed361ce3ca78cedd413d67d583f96ab0a59feb512af89052c50172

jobs:
test:
docker:
- image: blueyed/vim-python-pep8-indent-vims-for-test:1@sha256:8c77867e1fdf673a6df0ecf6628f8e4d80579a0a097ec196109ca0bc145d86c0
<<: *common
steps:
- checkout
- run:
name: Run tests
command: |
Xvfb :99 &
DISPLAY=:99 VIMRUNNER_REUSE_SERVER=1 rspec spec
spec/make-coverage
- run:
name: Report coverage
command: |
covimerage xml
codecov -X search gcov pycov -f coverage.xml
checkqa:
docker:
- image: circleci/python:3.7
<<: *common
steps:
- checkout
- run:
name: Lint
command: |
pip install --user vim-vint
~/.local/bin/vint **/*.vim
vint **/*.vim
workflows:
version: 2
Expand Down
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
plugins = covimerage
data_file = .coverage_covimerage
source = indent/python.vim

[report]
include = indent/python.vim
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
*
!Gemfile
!indent
!spec
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.*.swp
.coverage_covimerage
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
FROM testbed/vim:latest

RUN apk --no-cache add gtk+2.0-dev libx11-dev libxt-dev mcookie xauth xvfb
RUN install_vim -tag master --with-features=normal \
# NOTE: +profile needs huge features.
RUN install_vim -tag master --with-features=huge \
--disable-channel --disable-netbeans --disable-xim \
--enable-gui=gtk2 --with-x -build
RUN ln -s /vim-build/bin/vim-master /usr/bin/gvim
RUN gvim --version

# Install covimerage and vint.
# NOTE: we have py2 already via gtk+2.0-dev.
# NOTE: enum34+pathlib+typing gets installed as workaround for broken vim-vint wheel.
RUN apk --no-cache add py2-pip \
&& pip install --no-cache-dir codecov covimerage==0.0.9 vim-vint enum34 pathlib typing \
&& rm -rf /usr/include /usr/lib/python*/turtle* /usr/lib/python*/tkinter

WORKDIR /vim-python-pep8-indent

ADD Gemfile .
RUN apk --no-cache add coreutils ruby-bundler
RUN bundle install

ADD indent ./indent
ADD spec ./spec

ENTRYPOINT ["rspec", "spec"]
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
test:
VIMRUNNER_REUSE_SERVER=1 xvfb-run bundle exec rspec

test_slow:
VIMRUNNER_REUSE_SERVER=0 bundle exec rspec

test_visible:
VIMRUNNER_REUSE_SERVER=1 bundle exec rspec

# Run tests in dockerized Vims.
DOCKER_REPO:=blueyed/vim-python-pep8-indent-vims-for-test
DOCKER_TAG:=1
DOCKER_TAG:=2
DOCKER_IMAGE:=$(DOCKER_REPO):$(DOCKER_TAG)

docker_image:
Expand All @@ -26,3 +20,6 @@ test_docker:
docker run --rm -ti -e DISPLAY -e VIMRUNNER_REUSE_SERVER=1 \
-v $(CURDIR):/vim-python-pep8-indent $(DOCKER_IMAGE) $(RSPEC_ARGS) \
$(if $(VIMRUNNER_TEST_DISPLAY),,; ret=$$?; kill $$XVFB_PID; exit $$ret)

test_coverage:
spec/make-coverage
33 changes: 33 additions & 0 deletions spec/indent/cython_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "spec_helper"

describe "vim for cython" do
before(:all) {
vim.command "new"
vim.command "set ft=cython"
# vim.command("set indentexpr?").should include "GetPythonPEPIndent("
}
before(:each) {
# Insert two blank lines.
# The first line is a corner case in this plugin that would shadow the
# correct behaviour of other tests. Thus we explicitly jump to the first
# line when we require so.
vim.feedkeys 'i\<CR>\<CR>\<ESC>'
}
after(:all) {
vim.command "bwipe!"
}

describe "when using a cdef function definition" do
it "indents shiftwidth spaces" do
vim.feedkeys 'icdef long_function_name(\<CR>arg'
indent.should == shiftwidth * 2
end
end

describe "when using a cpdef function definition" do
it "indents shiftwidth spaces" do
vim.feedkeys 'icpdef long_function_name(\<CR>arg'
indent.should == shiftwidth * 2
end
end
end
29 changes: 0 additions & 29 deletions spec/indent/indent_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "spec_helper"

shared_examples_for "vim" do

before(:each) {
# clear buffer
vim.normal 'gg"_dG'
Expand Down Expand Up @@ -573,34 +572,6 @@
it_behaves_like "multiline strings"
end

describe "vim for cython" do
before {
vim.command "enew"
vim.command "set ft=cython"
vim.command "runtime indent/python.vim"

# Insert two blank lines.
# The first line is a corner case in this plugin that would shadow the
# correct behaviour of other tests. Thus we explicitly jump to the first
# line when we require so.
vim.feedkeys 'i\<CR>\<CR>\<ESC>'
}

describe "when using a cdef function definition" do
it "indents shiftwidth spaces" do
vim.feedkeys 'icdef long_function_name(\<CR>arg'
indent.should == shiftwidth * 2
end
end

describe "when using a cpdef function definition" do
it "indents shiftwidth spaces" do
vim.feedkeys 'icpdef long_function_name(\<CR>arg'
indent.should == shiftwidth * 2
end
end
end

describe "Handles far away opening parens" do
before { vim.feedkeys '\<ESC>ggdGifrom foo import (' }

Expand Down
25 changes: 25 additions & 0 deletions spec/make-coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

set -ex

rm -f .coverage_covimerage
export PYTHON_PEP8_INDENT_TEST_PROFILE_BASE=/tmp/vim-python-pep8-profile

Xvfb :99 2>/dev/null >&2 &
export DISPLAY=:99

export VIMRUNNER_REUSE_SERVER=1

ret=0
for file in ./spec/indent/*_spec.rb; do
# shellcheck disable=SC2086
bundle exec rspec "$file" $RSPEC_OPTIONS || ret=1

for p in "${PYTHON_PEP8_INDENT_TEST_PROFILE_BASE}".*; do
cat "$p"
covimerage write_coverage --append "$p"
rm "$p"
covimerage report -m
done
done
exit $ret
19 changes: 12 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'vimrunner'
require 'vimrunner/rspec'
require 'vimrunner/server'

# Explicitly enable usage of "should".
RSpec.configure do |config|
Expand All @@ -13,15 +14,19 @@
config.reuse_server = ENV['VIMRUNNER_REUSE_SERVER'] == '1' ? true : false

config.start_vim do
vim = config.reuse_server ? Vimrunner.start_gvim : Vimrunner.start
plugin_path = File.expand_path('../..', __FILE__)

# add_plugin appends the path to the rtp... :(
# vim.add_plugin(plugin_path, 'indent/python.vim')
exe = config.reuse_server ? Vimrunner::Platform.gvim : Vimrunner::Platform.vim
vimrc = File.expand_path("../vimrc", __FILE__)
vim = Vimrunner::Server.new(:executable => exe,
:vimrc => vimrc).start
# More friendly killing.
# Otherwise profiling information might not be written.
def vim.kill
normal(':qall!')
end

plugin_path = File.expand_path('../..', __FILE__)
vim.command "set rtp^=#{plugin_path}"
vim.command "runtime syntax/python.vim"
vim.command "runtime indent/python.vim"
vim.command "set filetype=python"

def shiftwidth
@shiftwidth ||= vim.echo("exists('*shiftwidth') ? shiftwidth() : &sw").to_i
Expand Down
22 changes: 22 additions & 0 deletions spec/vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
" vint: -ProhibitSetNoCompatible
set nocompatible

filetype plugin on
filetype indent on
syntax on

set noswapfile nobackup

" remove default ~/.vim directories to avoid loading plugins
set runtimepath-=~/.vim
set runtimepath-=~/.vim/after

let sfile = expand('<sfile>')
let plugin_path = fnamemodify(sfile, ':p:h:h')
exe 'set runtimepath^='.plugin_path

if !empty($PYTHON_PEP8_INDENT_TEST_PROFILE_BASE)
execute printf('profile start %s.%s',
\ $PYTHON_PEP8_INDENT_TEST_PROFILE_BASE, getpid())
execute 'profile! file '. plugin_path . '/indent/python.vim'
endif

0 comments on commit c294334

Please sign in to comment.