Module:Convert/tester/doc

This module runs unit tests to compare template output with expected text. In addition, the module can output the results of expanding templates.

While intended for testing Module:Convert, the tester should be useful with other templates that require many tests using a simple format for the test input.

Testcases example

 * Module:Convert/sandbox/testcases • templates to be tested, with expected outputs
 * Module talk:Convert/sandbox/testcases • view test results

It is not necessary to save the testcases page before viewing test results. For example, Module:Convert/sandbox/testcases could be edited to change the tests. While still editing that page, paste " " (without quotes) into the page title box under "Preview page with this template", then click "Show preview".

The testcases talk page (for example, Module talk:Convert/sandbox/testcases) contains:

The testcases module page (for example, Module:Convert/sandbox/testcases) may contain:

If wanted, the tests can be run using a template different from the one specified in the tests. For example, the following would run the tests from Module:Convert/sandbox/testcases, but would change the name of each template found on that page to " ".

Format
Tests are extracted from a multiline string. Any line that does not start with a template is ignored. Each processed line starts with a template, and is followed by whitespace, then the wikitext which should result from expanding the template.

The expected output must be entered in a single line. If the template outputs multiple lines, those lines must be joined with "\n" (two characters—backslash ).

The templates do not have to be the same, for example, the following tests would work:

In the results, the status column shows "Pass" if the output from the template exactly matches the expected text. If there is no expected text, the template output is shown in the Actual column with a blank status. If the given expected text differs from the template output, the template output is shown in the Actual column with status "Fail", and the number of fails is shown at the top of the page. Searching the page for "Fail" will find each problem. Any "Fail" result is followed by a row showing the nowiki actual and expected wikitext.

Specifying tests
If using a testcases module (as in the above example), the test text is assigned to  before executing.

Alternatively, the test text can be read from any page, or from any section on any page. For example, the following wikitext could be entered in a sandbox: &#61;= Mixed tests == &lt;pre> 12 m                           12 metres (39 ft) align="right"|0.16\n|align="right"|0.61 335 days        335 --- The following line is incorrect to demonstrate a "fail". 12 m                     12 metres (39 ft) The following line demonstrates the result when no expected text is provided.

&lt;/pre>

Given the above, the tests can be run as shown in the following section.

Instead of specifying the tests with a multiline string, it is possible to assign a table to  as shown in the following testcases module.

This example provides the same results as the multiline string at "Mixed tests" above.

Running tests from any page
Entering either of the following lines of wikitext in a sandbox or talk page would run the tests found at the specified location. The first line would show all tests on page "Template talk:Example", while the second would show only those tests on that page that are in the "Mixed tests" section.

As a demonstration, the following line is used to produce the table shown below, including the comment that starts with three dashes.

Making expected results
Function  can be used to create tests in the format expected by. For example, previewing either of the following in a sandbox would show the results from expanding each template found on the specified page.

When using, any expected results in the input are ignored. Instead, the module shows each template and its actual output as plain text which can be copied to make a testcases page. The templates to be processed can be specified by setting  or by specifying a page with an optional section.

If  is included, any non-template lines are included in the result. The output could then be copied and used to replace the page with the tests in order to update the expected text for each template, but without changing non-template lines.

As a demonstration, the following line is used to produce the text shown below.

Using show=all
The  option can be used with   and with.

An example using  is shown in the previous section.

Using  with   allows comment lines to be displayed in the output table—not all lines are shown, only those that start with three dashes. For example, the testcases may include the following. Added 12 January 2014. --- The following tests check the widget option. ...(expected output)...

The table produced by  would show "The following tests check the widget option." as a comment line, but only if  is used. Comments have a distinctive background color, but also show "Cmnt" in the status column so they can be found by searching.

Comparing a module with its sandbox
When viewing a module, the documentation page is displayed; if the module has a sandbox, the documentation includes "Editors can experiment in this module's sandbox" with a link to diff the module and its sandbox.

The tester module provides a  function which can check a series of modules, and compare each with its sandbox. A table is displayed showing whether the content is different, with a diff link.

For example, the following wikitext could be used.

The names "Example" and "Example/data" do not include a colon, so "Module:" is assumed. The command compares Module:Example with Module:Example/sandbox, and Module:Example/data with Module:Example/data/sandbox.

It is also possible for a module to define pairs of page titles in  (a table), and to use the tester module to generate a table for each pair of titles.

As a convenience, certain keywords are defined. If a keyword is recognized, the list of pairs comes from the module rather than the parameters. For example, the following uses the "convert" keyword to get the list of pairs of pages related to Module:Convert.

The following text is a sample showing output that may result from the above.
 * Module:Convert • Module:Convert/sandbox • different ( [//en.wikipedia.org/w/index.php?title=Special%3AComparePages&page1=Module%3AConvert&page2=Module%3AConvert%2Fsandbox diff] )
 * Module:Convert/data • Module:Convert/data/sandbox • same content
 * Module:Convert/text • Module:Convert/text/sandbox • different ( [//en.wikipedia.org/w/index.php?title=Special%3AComparePages&page1=Module%3AConvert%2Ftext&page2=Module%3AConvert%2Ftext%2Fsandbox diff] )
 * Module:Convert/extra • Module:Convert/extra/sandbox • different ( [//en.wikipedia.org/w/index.php?title=Special%3AComparePages&page1=Module%3AConvert%2Fextra&page2=Module%3AConvert%2Fextra%2Fsandbox diff] )

By default, each output line is prefixed with ' ' to give a bulleted list. An alternative prefix can be specified with the  parameter. For example, the following gives an indented bulleted list.