Jump to content

Module:Convert/tester/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Johnuniq (talk | contribs) at 21:31, 24 September 2013 (info on status). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

This module runs unit tests to compare template output with expected text.

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.

Example:

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 "Module talk:Convert/sandbox/testcases" (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:

{{#invoke:Convert/sandbox/testcases | run_tests }}

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

local tests = [==[

A line without a template, like this line, is ignored.
{{convert/sandbox|1|acre|lk=on}}            1 [[acre]] (0.40 [[hectare|ha]])
{{convert/sandbox|1|m2|acres|lk=on}}        1 [[square metre]] (0.00025 [[acre]]s)
{{convert/sandbox|0.16|/l|2|disp=table}}    align="right"|0.16\n|align="right"|0.61

]==]

local p = require('Module:Convert/tester')
p.tests = tests
return p

The tests variable is a multiline string. Any line without a template is ignored. Processed lines consist of a template, then whitespace, then the wikitext that 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 n).

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

local tests = [==[

{{convert|12|m}}                            12 metres (39 ft)
{{convert/sandbox|12|m}}                    12 metres (39 ft)
{{age|1989|7|23|2003|7|14}}                 13
{{age in days|2007|5|24|2008|4|23}}         335

]==]

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.