LoginSignup
9
8

More than 5 years have passed since last update.

PHP extensionのmake testに関するTIPS

Last updated at Posted at 2016-04-11

PHP extensionを書いているとmake testすることが多いと思うんですが、デフォルトの挙動のままだとテスト完了時に下記のように「PHP QAチームにレポートするかい?」と言われて困惑したりします。

$ make test
(略)
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it.  You can then email it to qa-reports@lists.php.net later.

実は、make変数でこの挙動を変えることができます。

NO_INTERACTION=1

上記のレポートを送る機能を無効化します。

TEST_PHP_DETAILED=1

各テストの詳細を表示します。下記のような情報が得られますが、イマイチ役に立たない気がします。

=================
TEST /Users/hnw/src/github.com/hnw/php-timecop/tests/002.phpt
TEST 1/1 [tests/002.phpt]
CONTENT_LENGTH  =
CONTENT_TYPE    =
PATH_TRANSLATED = /Users/hnw/src/github.com/hnw/php-timecop/tests/002.php
QUERY_STRING    =
REDIRECT_STATUS = 1
REQUEST_METHOD  = GET
SCRIPT_FILENAME = /Users/hnw/src/github.com/hnw/php-timecop/tests/002.php
HTTP_COOKIE     =
COMMAND /Users/hnw/.phpenv/versions/7.0.5-debug/bin/php  -n -c '/Users/hnw/src/github.com/hnw/php-timecop/tmp-php.ini'  -d "output_handler=" -d "open_basedir=" -d "safe_mode=0" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=1" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "memory_limit=128M" -d "log_errors_max_len=0" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "extension_dir=/Users/hnw/src/github.com/hnw/php-timecop/modules/" -d "extension=timecop.so" -d "session.auto_start=0" -d "tidy.clean_output=0" -d "zlib.output_compression=Off" -d "mbstring.func_overload=0" -f "/Users/hnw/src/github.com/hnw/php-timecop/tests/002.php"  2>&1
PASS Check for timecop_freeze [tests/002.phpt]
=====================================================================

TESTS=--show-diff

TESTS変数経由で、実際のテストランナーであるrun-tests.phpのコマンドラインオプションを指定できます。--show-diffを指定すると、次のように失敗したテストについてdiffが表示されて便利です。

TEST 1/1 [tests/002.phpt]
========DIFF========
001+ int(123)
001- int(246)
========DONE========
FAIL Check for timecop_freeze [tests/002.phpt]

他にどんなオプションがあるかはrun-tests.php --helpから調べられます。

TESTS=tests/002.phpt

TESTSの内容はすべてテストランナーのコマンドライン引数として渡されます。このように、実施したいテストを明示的に指定することもできます。

まとめ

そんなわけで、こんな感じでテストを実施するとextension開発時に便利かと思います。

$ make test NO_INTERACTION=1 TESTS=--show-diff

特定のテストが稀に落ちるので繰り返し確認したい、という場合は次のようにすれば良いでしょう。

$ make test NO_INTERACTION=1 TESTS='--show-diff tests/002.phpt tests/004.phpt'
9
8
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
8