LoginSignup
5
6

More than 5 years have passed since last update.

Travis CIのVimが古くてテストが通らないからスピリチュアルパワー使う

Last updated at Posted at 2016-05-21

Travis CIのVimが古くてテストが通らないからスピリチュアルパワー使う

Travis CIのテストで任意のバージョンのVimを使う

 Travis CIのテストで任意のバージョンのVimを使う方法。
(またはvim-themisを使用した、Vimプラグインのテスト用.travis.ymlのサンプルとして)

要点まとめ

  • Travis CIがデフォルトで持ってるVimのバージョンが低くてテストが落ちる
    • 解決方法 => VimをGitHubからclone & ビルドして使うようにする

テスト対象

aref-web.vim

aref-web.vim

事件

.travis.yml
language: viml

install:
    - mkdir -p ~/.vim/bundle/repos/github.com
    - mkdir ~/.vim/bundle/repos/github.com/thinca
    - mkdir ~/.vim/bundle/repos/github.com/tyru
    - mkdir ~/Repository
    - git clone https://github.com/thinca/vim-themis ~/.vim/bundle/repos/github.com/thinca/vim-themis
    - git clone https://github.com/tyru/open-browser.vim ~/.vim/bundle/repos/github.com/tyru/open-browser.vim
    - git clone https://github.com/aiya000/aref-web.vim ~/Repository/aref-web.vim

before_script:
    - vim --version

script:
    - ~/.vim/bundle/repos/github.com/thinca/vim-themis/bin/themis ~/Repository/aref-web.vim/test --reporter spec

branches:
    - master

結果

.
.
$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May  4 2012 04:25:35)
Included patches: 1-429
.
.
$ ~/.vim/bundle/repos/github.com/thinca/vim-themis/bin/themis ~/Repository/aref-web.vim/test --reporter spec
aref-web.vim
  [✓] is_supported_source_test
  [✓] get_target_url_test
  [✓] can_use_dump_cmd_test
  [✖] have_openbrowser_vim_test
      function 112()  (~/Repository/aref-web.vim/test/aref_web.vim)
      function <SNR>27_have_openbrowser_vim()  Line:5  (~/build/aiya000/aref-web.vim/autoload/aref_web.vim)

      Vim(return):E121: Undefined variable: v:false

tests 4
passes 3
fails 1

The command "~/.vim/bundle/repos/github.com/thinca/vim-themis/bin/themis ~/Repository/aref-web.vim/test --reporter spec" exited with 1.

Done. Your build exited with 1.

tests 4
passes 3
fails 1

Vim(return):E121: Undefined variable: v:false

「はぁ? ナニソレ、イミワカンナイ」

なぜ

 v:falseとは最近のVimのアップデートで追加された値(変数)で、
Travis CIのUbuntuがデフォルトで備えているVimのバージョンが低いので
対応していないのです。

対策

 Travis CIのスピリチュアルUbuntuパワーを使い、以下の流れでスピリチュアルテストをしてもらいます。

  1. GitHubのVimをcloneする
  2. cloneしたVimをビルドする
  3. テストでそれ使う
  4. ! スピリチュアルやね
.travis.yml
language: viml

install:
    # Prepare environment
    - mkdir -p ~/.vim/bundle/repos/github.com
    - mkdir ~/.vim/bundle/repos/github.com/thinca
    - mkdir ~/.vim/bundle/repos/github.com/tyru
    - mkdir ~/Repository
    # Install needed plugins
    - git clone https://github.com/thinca/vim-themis ~/.vim/bundle/repos/github.com/thinca/vim-themis
    - git clone https://github.com/tyru/open-browser.vim ~/.vim/bundle/repos/github.com/tyru/open-browser.vim
    - git clone https://github.com/aiya000/aref-web.vim ~/Repository/aref-web.vim
    - git clone https://github.com/vim/vim /tmp/vim
    # Build just version vim to ~/bin/vim7.4.1689
    - mkdir ~/bin
    - cd /tmp/vim
    - sudo apt-get install -y gettext libncurses5-dev libacl1-dev libgpm-dev
    - git checkout v7.4.1689
    - ./configure --with-features=huge --enable-fail-if-missing --prefix=$HOME/bin/vim7.4.1689
    - make && make install
    - export THEMIS_VIM=$HOME/bin/vim7.4.1689/bin/vim

before_script:
    - $HOME/bin/vim7.4.1689/bin/vim --version

script:
    - ~/.vim/bundle/repos/github.com/thinca/vim-themis/bin/themis ~/Repository/aref-web.vim/test --reporter spec

branches:
    - master

結果 ( スピリチュアル )

.
.
$ $HOME/bin/vim/bin/vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled May 20 2016 19:16:45)
Included patches: 1-1689
.
.
$ ~/.vim/bundle/repos/github.com/thinca/vim-themis/bin/themis ~/Repository/aref-web.vim/test --reporter spec
aref-web.vim
  [✓] is_supported_source_test
  [✓] get_target_url_test
  [✓] can_use_dump_cmd_test
  [✓] have_openbrowser_vim_test

tests 4
passes 4

The command "~/.vim/bundle/repos/github.com/thinca/vim-themis/bin/themis ~/Repository/aref-web.vim/test --reporter spec" exited with 0.

Done. Your build exited with 0.

Included patches: 1-1689

tests 4
passes 4

Done. Your build exited with 0.

「ハラショー!」

ポイント

  • VimのHEADをビルドするとコワイので、リビジョンを指定してる
    • Vim側のバグが出てたらこっちにも影響してきてコワイからね!
  • ./configureには最小限のオプションを渡している
    • ビルド速い
  • cacheでdirectoriesを指定した

 スピリチュアルやね!

おまけ - cacheの使用

 最終的な.travis.ymlの形はこちらに落ち着きました! ( 結構改良したり、cacheを教えてもらったりした )

.travis.yml
language: generic

sudo: false

install:
    # Prepare environment
    - mkdir -p ~/.vim/bundle/repos/github.com
    - mkdir ~/.vim/bundle/repos/github.com/thinca
    - mkdir ~/.vim/bundle/repos/github.com/tyru
    - mkdir ~/Repository
    # Install needed plugins
    - git clone https://github.com/thinca/vim-themis ~/.vim/bundle/repos/github.com/thinca/vim-themis
    - git clone https://github.com/tyru/open-browser.vim ~/.vim/bundle/repos/github.com/tyru/open-browser.vim
    - git clone https://github.com/aiya000/aref-web.vim ~/Repository/aref-web.vim
    # Build just version vim to ~/vim-7.4.1689
    - ( if [ ! -d ~/vim-7.4.1689/bin ]; then git clone https://github.com/vim/vim /tmp/vim && cd /tmp/vim && git checkout v7.4.1689 && ./configure --prefix=$HOME/vim-7.4.1689 && make && make install; fi )
    - export THEMIS_VIM=$HOME/vim-7.4.1689/bin/vim

cache:
    directories:
        - $HOME/vim-7.4.1689

before_script:
    - $HOME/vim-7.4.1689/bin/vim --version

script:
    - ~/.vim/bundle/repos/github.com/thinca/vim-themis/bin/themis ~/Repository/aref-web.vim/test --reporter spec

branches:
    - master


5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6