LoginSignup
9
5

More than 3 years have passed since last update.

Vim の "make test" を読み解く 第 1 回 (make test 概要)

Last updated at Posted at 2019-02-18

Meguro.vim #14 に参加したとき、Vim 本体の主にテスト関連のコードを読んでもくもくしたので記事にすることにしました。Vim 自身のテストに関する記事ってあんまりないような気がしたので。理解できた部分を少しずつ追記していきます。大変に地味な記事になる予感。けど Vim script を使い倒しているはずなので、自分の勉強にもなるかも。面白そうなトピックがあれば教えてください。
OS は Linux で、以下の設定で実行した場合を想定しています。

$ ./configure --with-features=huge --enable-fail-if-missing --prefix=$HOME

目次

まだ未完成で雑多だけどとりあえず目次。
(本記事) Vim の "make test" を読み解く 第 1 回 (make test 概要)
Vim の "make test" を読み解く 第 2 回 (scripttests 概要)
Vim の "make test" を読み解く 第 3 回 (src/testdir/README.txt)
Vim の "make test" を読み解く 第 4 回 (単体 new-style-testing の実行)
Vim の "make test" を読み解く 第 5 回 (runtest.vim)

make test

:help testing を見てみると分かるように、一般的なアプリケーションと同様に Vim にもテストが存在していて、make test で実行することができます。また、src/Makefile には以下のような記述があります。

# 4. "make test"  {{{1
#   This is optional.  This will run Vim scripts on a number of test
#   files, and compare the produced output with the expected output.
#   If all is well, you will get the "ALL DONE" message in the end.  If a
#   test fails you get "TEST FAILURE".  See below (search for "/^test").

日本語訳

このステップは任意です。これはたくさんのテストファイル上で Vim script を実行し、生成された出力と期待される出力を比較します。すべてが正常だった場合、"ALL DONE" というメッセージが最後に表示されます。もしテストが失敗した場合は "TEST FAILURE" が表示されます。("/^test" で検索して) 下のほうを参照してください。

2018/02/18 現在 (tag: v8.1.0946) では、"ALL DONE" は実際には最後ではなく途中に表示されます。これは次の章で説明しますが、もともとあった Vim 本体のテストに対して unit test と libvterm のテストが後から追加されたためではないかと推測します。libvterm に関しては以下のサイトが参考になります。
https://qiita.com/mattn/items/5aed718a65d21ca7855c
libvterm のテストを実行するためには、sudo apt install libtool-bin を実行しておく必要があるようです。

Makefile

make test (もしくは make check) でテストを実行すると、

  1. scripttests
  2. unittests
  3. test_libvterm

の 3 つが実行されることが分かります。

# TESTING
#
# Execute the test scripts and the unittests.
test check: scripttests unittests test_libvterm

先に種明かしをしてしまうと、scripttests は Vim 本体の機能のテスト、unittests は Vim の内部に存在する関数のユニットテスト、test_libvterm は上述の libvterm に関するテストです。

とりあえず、第 1 回はここまで。

読み解きネタ

  • terminal-dumptest
  • test_largefile -> make test には含まれていないことを、第 2 回 で言及
  • new-style-test の単体実行 -> src/testdir/README.txt の内容として 第 3 回 で紹介
  • flaky_tests
9
5
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
9
5