パーサーのテスト

This page is a translated version of the page Parser tests and the translation is 44% complete.
Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎polski • ‎português • ‎português do Brasil • ‎中文 • ‎日本語

それぞれのパーサテストケースは、入力されたウィキテキストと出力HTMLを指定して、期待どおりに動作することを確認します。実際の出力が目的の結果と比較されるため、パーサーテストケース(パーサーテストとも呼ばれます)は、回帰の検出に役立ちます。

The parser test cases reside in tests/parser/parserTests.txt. Extensions should place their tests in a tests/parser/ directory.

They can be run both through the phpunit test suite and through the standalone parserTests.php -- so a parser test failure should trigger a Jenkins test failure.

構文と実行

Version 2 format
Starting with 1.35, parser tests are required to be in the Version 2 format. Specifying version 2 indicates that the tests are ready to be run in "tidy" mode (See T249138).
To indicate your parser tests are run in version 2 format, the first line in your parser test file must be !! Version 2

構文は以下の通りです:

!! Version 2
!! test
Simple paragraph
!! config
wgRestrictDisplayTitle=false
!! input
This is a simple paragraph.
!! result
<p>This is a simple paragraph.
</p>
!! end

The config section can be omitted. If you specify configuration settings there, make sure you don't have any whitespace between your expressions, as whitespace isn't trimmed by the test runner.

In order to create a new article the syntax is:

!! article
Template:Simple template
!! text
A ''simple'' template.
!! endarticle

In order to be sure that the extension tag tag1 is loaded add at the beginning of the file:

!! hooks
tag1
!! endhooks

Extensions that place their tests in tests/parser/ and are using extension.json will automatically have their parser tests run. For extensions using the legacy extension loading system, they can use:

$wgParserTestFiles[] = __DIR__ . "/myParserTests.txt";

To run the parser tests, go to the root directory of your local MediaWiki installation and execute the following from the command line:

php tests/parser/parserTests.php
Prior to MediaWiki 1.28, this file was located at tests/parserTests.php.

To run tests for just one file, use --file=... param. --helpを使って他のパラメータを参照してください。

php tests/parser/parserTests.php --file=extensions/Kartographer/tests/parser/parserTests.txt

関連項目