Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vim-testbed to run Vader tests on Travis #88

Merged
merged 3 commits into from
Oct 12, 2016

Conversation

prashcr
Copy link
Contributor

@prashcr prashcr commented Oct 11, 2016

In addition to the current vint script currently on Travis, I added infrastructure for automated testing with Vader inside a Docker container with multiple vim builds that are cached on Docker Hub.

Most of what I wrote is copied from https://github.com/tweekmonster/vim-testbed/tree/master/example, except I created a new Docker image based on vim-testbed containing vim v8.0.0000 and v8.0.0027.

It was quite a lot for me to wrap my head around at first as well, but I'm convinced the benefits are worth it. I understand the Makefile and Docker Hub image can be a bit daunting. However, from a tester's perspective, all they need to know is that

  1. tests go in test/
  2. they can modify the vimrc there which is used in tests

As this is quite a lot already for one PR so I only included a very basic Vader test as an example.

Versus our current approach

  • Our current approach limits us to whatever version of vim is installed on Ubuntu 12.04, which happens to be v7.3.429 and is useless for testing a vim 8 plugin. The only alternate solution is to build vim from source for every Travis build, but this is messy and takes minutes.
  • OS-agnostic testing of multiple vim versions
  • Travis builds in seconds, not minutes, allowing for quicker iterations during development
  • Contributors just need to link their Github to Travis and push to their fork to run tests, no need to install vint or vader
  • Eventual Neovim support Add support for installing Neovim Vimjas/vim-testbed#1
    Refactoring #59

@KabbAmine Try running adding your Vader tests to this and let me know how it goes.

@prashcr
Copy link
Contributor Author

prashcr commented Oct 11, 2016

The build is failing at the moment due to vint.

The previous .travis.yml was building successfully because vint was not outputting anything. Peculiarly, without having changed anything vint-related, vint seems to be outputting stuff now, failing the build.

Pretty strange to me and I have no clue why this is occurring but I guess having vint warnings means it's being useful so this should be a good thing.

@prashcr
Copy link
Contributor Author

prashcr commented Oct 11, 2016

Ah, I realize what's wrong. vint is currently linting the vader.vim plugin instead of this plugin, let me fix that.

@prashcr prashcr force-pushed the master branch 3 times, most recently from a6b21f3 to 3245f5d Compare October 11, 2016 05:32
@prashcr
Copy link
Contributor Author

prashcr commented Oct 11, 2016

Should be working now!

@KabbAmine
Copy link
Contributor

Good job 👍 I'll prepare some tests then.

P.S: If this issue is related to this PR, note that you need the -s flag in vint to get style errors as ProhibitImplicitScopeVariable.

@@ -1,8 +1,10 @@
---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yaml-lint complains if there's no document start marker, so I'd put that back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,19 @@
IMAGE ?= prashcr/vim8s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should use a Dockerfile hosted in this repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I would host the dockerfile in the repo and have it auto-build on the docker hub

Copy link
Contributor Author

@prashcr prashcr Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I just changed this. You'll have to link your GitHub and set up an automated build for this repo at hub.docker.com

$(DOCKER) $$vim '+Vader! test/*'; \
done

.PHONY: test-setup test
Copy link
Member

@w0rp w0rp Oct 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a make clean rule in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile doesn't create files anymore. We could still add a make clean for docker containers but that would undermine caching and people could just do that manually if they happened to be running Docker on their own machine. And we don't need clean for Travis anyway.


$(PLUGINS)/vader.vim:
mkdir -p $(PLUGINS)
cd $(PLUGINS) && git clone https://github.com/junegunn/vader.vim.git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reference a particular commit ID so tests won't start failing if Vader updates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@w0rp
Copy link
Member

w0rp commented Oct 11, 2016

I opened issue #89 to list some important tests we should focus on after this gets in.

@w0rp
Copy link
Member

w0rp commented Oct 11, 2016

You'll have a conflict now the style checking branch as been merged. The -s flag has been added to vint.

@prashcr
Copy link
Contributor Author

prashcr commented Oct 11, 2016

Thanks for the feedback, I've incorporated most of the requested changes so far.

I noticed 1 additional thing I'd like to fix, which I'm working on at the moment

  1. Makefile clones vader.vim into test/, which is the only side effect of the Makefile currently. I'll try to move vader.vim installation into the Dockerfile, thereby eliminating the need for make clean and modification of the user's directory.

I also just started considering the process of adding linters, and similar to above, I believe they should also be added to the Dockerfile, consisting of a git clone and ENV PATH of the linter as well as its pre-requisite languages (e.g. Node.js, Ruby)

@w0rp
Copy link
Member

w0rp commented Oct 11, 2016

Cool. See if you can get it to somehow cache installation of pip modules and Vader.vim. Maybe we could create a new image which contains what we need, and use that pre-defined image.

@prashcr
Copy link
Contributor Author

prashcr commented Oct 12, 2016

It caches a particular commit of Vader.vim now, cloning directly inside the container.

Once the automated docker hub build is created, Travis should pass.

Installing linters, pip, npm, etc. should be trivial to add, I'll do that in another commit though, enough rebasing for a day 😅

@prashcr
Copy link
Contributor Author

prashcr commented Oct 12, 2016

Amended again to fix a typo.

@prashcr
Copy link
Contributor Author

prashcr commented Oct 12, 2016

Hmm, there's a problem with my commit. Even though I clone vader.vim into the /home/plugins directory, it simply doesn't exist in the container.

install: |
pip install vim-vint==0.3.9
script: |
vint -s . && make test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way we can run both programs here? If a pull request contains some style issues, then it won't run the other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I can change that to a ||.
However, as a logical OR this means that if only one of them fail, the Travis build will still be a "pass"

Copy link
Contributor Author

@prashcr prashcr Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be some bashism to accomplish returning non-zero if either of them error yet still being able to run both, I'll try and find it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can just run them line after line on Travis, and it will capture the error codes of all programs run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting two env items would be one way to do it. Set a variable different in different environments for Travis, and run one command or the other based on the variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we put them line after line, we will only get the error code of the last line. I've implemented the solution I found and it's working well.

@w0rp
Copy link
Member

w0rp commented Oct 12, 2016

I haven't ever really used Docker, so I'm not sure myself. I'll leave it to you.

@prashcr prashcr force-pushed the master branch 2 times, most recently from a140653 to 6147a4d Compare October 12, 2016 09:07
@prashcr
Copy link
Contributor Author

prashcr commented Oct 12, 2016

Looking good to go now, I did a demo build on a separate branch using the same Dockerfile (hosted on my Docker Hub): https://travis-ci.org/prashcr/ale/builds/167034172

I moved vint from .travis.yml to the Docker container so that the entire process can be run with a make test, and works the same way as it does on Travis as well as locally with Docker.

I'm not 100% if that's the best idea, so let me know.

@@ -1,8 +1,7 @@
---
sudo: required
services:
- docker
language: python
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

travis-yaml still requires a language so I left that there.

@w0rp
Copy link
Member

w0rp commented Oct 12, 2016

It looks like it's not quite running at the moment.

for vim in $$vims; do \
$(DOCKER) $$vim '+Vader! test/*' || EXIT=$$?; \
done; \
$(DOCKER) vint -s /testplugin || EXIT=$$?; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check all of the .vim files in the repo, outside of tests?

Copy link
Contributor Author

@prashcr prashcr Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks the entire repo, because of this line

DOCKER = docker run -a stderr --rm -v $(PWD):/testplugin -v $(PWD)/test:/home "$(IMAGE)"

This part in particular mounts pwd, which is this repo, into the /testplugin directory of the container.

-v $(PWD):/testplugin

I did this because that's how the vim-testbed scripts seemed to work.

@prashcr
Copy link
Contributor Author

prashcr commented Oct 12, 2016

Yep it won't work here at the moment, let me explain.

We have a Dockerfile that describes a Docker image which is basically a built cache of all the pre-requisites (vim, vint, vader, etc.) for our make test script.

           "build"       "run"
Dockerfile -> Docker image -> Container

I use Docker Hub to host the Docker image. The neat feature of Docker Hub is that you can link it to a GitHub repo containing a Dockerfile such that every push to a branch on the GitHub repo triggers a build that creates a new image(e.g. downloads and builds vim, vint, vader, etc.)

The bottom line is that the Travis build consists of just two steps

  • Fetch the image from Docker Hub
  • Run container

Previously, the Makefile pointed to a Docker Hub image that I created, linked to a GitHub repo of my own. (As is still the case with the demo build in my previous comment). As per the suggestion to move the Dockerfile here instead, I pointed the Makefile to the w0rp/ale Docker Hub image, which doesn't exist yet.

In order for the Travis build to work with the Dockerfile in this repo,

  1. You'll have to create a Docker Hub account, link it to your GitHub and create an automated build. Only the GitHub repo owner can set up an automated build on Docker Hub.
  2. Even after that however, the Dockerfile has to be merged into the repo before you can see the build succeed, so it's a bit of a chicken-and-egg problem. I guess we could merge into another branch before master.

@w0rp
Copy link
Member

w0rp commented Oct 12, 2016

I see. I'll have a go at finishing this when I have some time.

@prashcr
Copy link
Contributor Author

prashcr commented Oct 12, 2016

Hmm, one easy solution I can think of is to just build the image in Travis for now. It'll take 2-3 minutes to run but should just work. Then later you can remove the build step and pull from Docker Hub instead if you choose.

@w0rp
Copy link
Member

w0rp commented Oct 12, 2016

Nah, I'll set up the Docker image and such. I'll probably merge this tonight and temporarily break Travis CI builds for a bit until it starts running the tests, after some shouting at it.

@w0rp
Copy link
Member

w0rp commented Oct 12, 2016

Right, time to break things and fix them again.

@w0rp w0rp merged commit e058f9d into dense-analysis:master Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants