Module talk:Template test case: Difference between revisions

Content deleted Content added
Works: Reply
 
(33 intermediate revisions by 12 users not shown)
Line 1:
{{WikiProject banner shell|
{{WikiProject Templates|module_for_template_maintenance=yes}}
}}
{{Central|Template talk:Test case|Template talk:Testcase table|Template talk:Testcase rows|Template talk:Inline test case|Template talk:Collapsible test case|Template talk:Test case nowiki|Template talk:Nowiki template demo|Module talk:Template test case/data|Module talk:Template test case/config}}
{{Centralized archive banner
| {{Archives |root=Template talk:Testcase table |title=Template talk:Testcase table |search=no}}
}}
{{WikiProject Templates}}
 
== Multiple automatic sandbox versions ==
Can we please extend the automatic addition of a <code>/sandbox</code> variant to all <code>_template<var>i</var></code>s if there is no <code>_template<var>++i</var></code>?
Line 212 ⟶ 213:
::...So that e.g. {{para|_collapsible}} and {{para|collapsible}} are equivalent, meaning the user has the option to pass the exact same arguments as all the other templates in the group. [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 18:44, 15 July 2023 (UTC)
:::Thats fair, I've gone ahead and implemented that [[Special:Diff/1165527145|here]]. Either option should work now. [[User:Aidan9382|Aidan9382]] <sub>([[User talk:Aidan9382|talk]])</sub> 19:04, 15 July 2023 (UTC)
::::This change appears to have caused, or may have caused, an error in some test cases. The one that came to my attention is {{tl|Circular reporting/testcases}}, where some "span title" code is being exposed. My wild guess is that a rendered equals sign in _title may be causing the problem. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 21:15, 16 July 2023 (UTC)
:::::This change right here shouldn't of (and hasn't) caused the issue, since this only effects how args are processed in {{tl|Test case nowiki}}, and the normal {{tl|Test case}}'s behaviour is unchanged. I suspect that specific test case has been broken for a while. I've fixed it [[Special:Diff/1136399202/1165754453|here]] and [[Special:Diff/1165754514|here]], and it should now work fine. [[User:Aidan9382|Aidan9382]] <sub>([[User talk:Aidan9382|talk]])</sub> 06:04, 17 July 2023 (UTC)
::::::Strange. I wonder why that page popped into the error report right after the change, and why this Module shows in [https://en.wikipedia.org/wiki/Special:RecentChangesLinked?hidebots=1&hidecategorization=1&hideWikibase=1&target=Template%3ACircular_reporting%2Ftestcases&limit=1000&days=30&enhanced=1&urlversion=2 Related changes] for the testcases page. It is also odd that this module appears in "Pages transcluded onto the current version of this page" when you edit the testcases page. Maybe it's a coincidence. P.S. I have modified both of the changes, since one of them caused Linter errors in other places. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 12:52, 17 July 2023 (UTC)
:::::::{{tq|It is also odd that this module appears in "Pages transcluded onto the current version of this page" when you edit the testcases page}} - that part makes sense, since {{tl|Test case}} uses this module, as does {{tl|Test case nowiki}} and a couple of the other related templates. As for why it took editing this for it to appear in an error report, even I'm not sure on that one. It definitely didn't change the behaviour, so maybe this change just caused it to purge and appear in the report. Could the report have had a recent change on what it picks up? [[User:Aidan9382|Aidan9382]] <sub>([[User talk:Aidan9382|talk]])</sub> 13:00, 17 July 2023 (UTC)
::::Many, many thanks, {{u|Aidan9382}}, for putting this in place. [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 14:52, 20 July 2023 (UTC)
 
== Extended-confirmed-protected edit request on 17 October 2023 ==
 
{{edit extended-protected|Module:Template test case/config|answered=yes}}
Please, remove the '''n''' of the word '''templaten''' in the line number 29. [[User:Gkiyoshinishimoto|Nishimoto, Gilberto Kiyoshi]] ([[User talk:Gkiyoshinishimoto|talk]]) 16:38, 17 October 2023 (UTC)
:{{done}} [[User:Aidan9382|Aidan9382]] <sub>([[User talk:Aidan9382|talk]])</sub> 16:42, 17 October 2023 (UTC)
 
== Trim input's newlines? ==
 
Many people use {{tl|test case nowiki}} as follows for aesthetics:
<syntaxhighlight lang="wikitext">
{{test case nowiki|<nowiki>
{{wrapper template top}}
{{__TEMPLATENAME}}
{{wrapper template bottom}}
</nowiki>}}
</syntaxhighlight>
This causes an extra newline to be inserted before and after the template's part inside the test case frame. It would be wonderful if this module would trim the input's newlines. [[User:Aaron Liu|<span style="color:#0645ad">Aaron Liu</span>]] ([[User talk:Aaron Liu#top|talk]]) 15:52, 8 August 2024 (UTC)
: Do you mean to trim newlines in a way that would make <syntaxhighlight lang="wikitext">
{{test case nowiki|<nowiki>
{{wrapper template top}}
{{__TEMPLATENAME}}
{{wrapper template bottom}}
</nowiki>}}
</syntaxhighlight>
:equivalent to
: <syntaxhighlight lang="wikitext">
{{test case nowiki|<nowiki>{{wrapper template top}}
{{__TEMPLATENAME}}
{{wrapper template bottom}}</nowiki>}}
</syntaxhighlight>
:? That is, trim newlines which are right next to the outer pair of {{tag|nowiki}} tags. —⁠[[User:Andrybak|andrybak]] ([[User talk:Andrybak|talk]]) 22:47, 8 August 2024 (UTC)
::Yes, thanks. [[User:Aaron Liu|<span style="color:#0645ad">Aaron Liu</span>]] ([[User talk:Aaron Liu#top|talk]]) 23:28, 8 August 2024 (UTC)
 
== Having multiple __TEMPLATENAME__s ==
 
I wanted to gauge interest in possibly extending the Module code to (optionally) support testing nowiki'd code that contains ''multiple'' template name substitutions. The primary use case would be testing templates that are only useful in concert with others, like (for example) {{tlx|archive top}}.
 
It's certainly possible to test that template in isolation, using a {{tlx|Test case nowiki}} transclusion at [[Template:Archive top/testcases]] like:
 
<syntaxhighlight lang="mediawiki">
{{Test case nowiki|<nowiki>
{{__TEMPLATENAME__}}
{{Lorem ipsum}}
{{archive bottom}}
</nowiki>}}
</syntaxhighlight>
 
...That'll get you a perfectly good test of {{tlx|archive top}} vs. {{tlx|archive top/sandbox}}.
 
But it might be useful, at times, to pair the tested {{tlx|archive top}} with a '''corresponding''' {{tlx|archive bottom}}, for when changes being made in tandem are being tested.
 
To meet those needs, the Module might need to support something like the following:
 
<syntaxhighlight lang="mediawiki">
{{Test case nowiki|template1name1=archive top|template1name2=archive bottom|<nowiki>
{{__TEMPLATENAME1__}}
{{Lorem ipsum}}
{{__TEMPLATENAME2__}}
</nowiki>}}
</syntaxhighlight>
 
This would, my thinking goes, permit testing the '''''combination''''' of {{tlx|archive top}} and {{tlx|archive bottom}} against the '''''combination''''' of {{tlx|archive top/sandbox}} and {{tlx|archive bottom/sandbox}} (unless different templates were specified for {{para|template2name1}} and {{para|template2name2}}).
 
As with the citation templates' handling of {{para|author}}, {{para|first}}, {{para|last}}, etc.:
 
# {{para|template1}} would effectively become an alias for {{para|template1name1}} (with the same default of <syntaxhighlight lang="mediawiki" inline>{{#titleparts: {{PAGENAME}}| -1}}</syntaxhighlight>)
# Same for {{para|template2}} and {{para|template2name1}} (again having the same default of <syntaxhighlight lang="mediawiki" inline>{{{template1name1}}}/sandbox</syntaxhighlight>)
# {{para|template3}} == {{para|template3name1}}, etc.
# <code>__TEMPLATENAME__</code> would be interchangeable with <code>__TEMPLATENAME1__</code>.
 
Using only {{para|template1name1}}, {{para|template2name1}}, and <code>__TEMPLATENAME1__</code> would therefore be equivalent to the current syntax, as would using ''only'' <code>__TEMPLATENAME1__</code> and leaving the template-selection parameters at their default values.
 
...Potentially useful? Some flaw I've overlooked in the proposed functionality? Or just not worth the effort, regardless whether or not it would work? [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 18:21, 29 August 2024 (UTC)
 
:I've since decided that the parameter names {{para|template1name1}} and {{para|template1name2}} feel awkward and confusing. They '''should''' be {{para|template1name1}} and {{para|template2name1}}, if anything, but that won't work because {{para|template1}} and {{para|template2}} are existing parameters that have different, incompatible definitions in the code.
:Nevertheless, a call using e.g. {{para|template1name1|archive top}}{{para|template1name2|archive bottom}} just feels confusing. (They're '''not''' different ''names'' for the first template, they're ''different '''templates''''' to be used in the first rendering of the test case.)
:So to avoid that confusion, I think it would be better to make {{para|templatename1}} the new equivalent for {{para|template1}}, instead. The second template to use in rendering the test case would be just {{para|templatename2}}. {{para|template2name1}} would still be equivalent to {{para|template2}}, and {{para|template2name2}} would still be the corresponding equivalent to {{para|templatename2}} for the second rendering of the case. (Though often they'd not be specified, and default to the {{code|/sandbox}} versions of the templates specified for {{para|templatename1}} .. {{para|templatename<var>N</var>}}. The notion of a "{{param|template1}}" parameter would be a deprecated compatibility labeling — the "proper"/"preferred" identifiers would be {{param|templatename1}} ... {{param|templatename<var>N</var>}}. Which, handily, would also exactly correspond to the placeholder strings {{code|__TEMPLATENAME1__}} ... <code>__TEMPLATENAME<var>N</var>__</code> used to insert them into the nowiki'd code.
:The other option would be {{para|case1template1}} ... {{para|case1template<var>N</var>}} for the first rendering, then {{para|case2template1}} ... {{para|case2template<var>N</var>}} for the normally-defaulted-to-<code>/sandbox</code> versions, and so on... But that's a much bigger and more disruptive change that doesn't feel worth the upheaval. (It also changes the meaning of "template1" vs. "template2", compared to their current definition. So, still potentially confusing.) [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 03:47, 7 October 2024 (UTC)
 
== Why visual matches instead of string matches? ==
 
Sorry for what must be a silly question, but why does this tool require visual comparison rather than doing a match and emitting '''TEST FAIL!''' [[User:Johnjbarton|Johnjbarton]] ([[User talk:Johnjbarton|talk]]) 22:19, 6 October 2024 (UTC)
 
:Not sure I follow — a string comparison of the output is precisely what the module's <syntaxhighlight lang="lua" inline>TestCase:templateOutputIsEqual()</syntaxhighlight> function does; the {{tlx|Collapsible test case}} template — or any of the templates, with {{para|_collapsible|yes}} set — will even automatically collapse any testcase where the results are the same. (As well as coloring the top bar of the collapsible box green (same output) vs. yellow (differences detected).)
:However, it's often the case that differences between the main version of a template and its sandbox version are '''intentional'''. (They'll be present whenever development is being done on the sandbox version of the code, for example.) So, characterizing differences as "TEST FAIL!" isn't strictly accurate, as having the same output isn't "success" and having ''different'' output isn't "failure". The point, when there are differences, is to demonstrate/examine how/whether the sandbox version has '''improved''' the output, vs. the live code. (If so, then a request can be made to transfer the sandbox code to the live template. At which point, the differences go away.) [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 23:38, 6 October 2024 (UTC)
:(Template test cases are therefore not like traditional programming [[unit test]]s, where the result of some code is compared to a known expected value, and any deviation represents a failure to perform as expected. Template test cases compare and contrast two versions of the same template, and any differences in output are ''interesting'' as a means of evaluating the code changes that created those differences.) [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 23:51, 6 October 2024 (UTC)
::Thanks! Sorry, I only read up to the Collapsible test cases and stopped, because I was far from wanting to collapse test cases. I did not see that how fails are alerted. [[User:Johnjbarton|Johnjbarton]] ([[User talk:Johnjbarton|talk]]) 00:01, 7 October 2024 (UTC)
 
== Empty testcases ==
 
Maybe could someone give a hint why when using this template on local wiki it is not showing comparison tables as in enwiki? I have migrated same modules and code, but it is not showing anything, just some text: [[:lt:Template:Infolentelė/testcases]] [[User:Zygimantus|Zygimantus]] ([[User talk:Zygimantus|talk]]) 21:02, 13 October 2024 (UTC)
:Click on the triangle next to "Straipsnyje naudojami šablonai:" to see the templates that are being requested. You may need to create one or more of the red templates in order to make that page work. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 00:36, 15 October 2024 (UTC)
::Yes, I thought about that, I have another page: [[:lt:Šablonas:Sąrašas be punktų/testcases]] for that, this one is minimal and does not have redlinks, still no comparison is visible, maybe some kind of unknown gadget or plugin is used? [[User:Zygimantus|Zygimantus]] ([[User talk:Zygimantus|talk]]) 11:00, 15 October 2024 (UTC)
:::I am stuck then. Maybe something in one of the modules or templates is dependent on an English-language name of a page or namespace, but that is a guess. – [[User:Jonesey95|Jonesey95]] ([[User talk:Jonesey95|talk]]) 12:52, 17 October 2024 (UTC)
::::Will try something, it is a pity that no error message or something is visible, maybe then it is related to CSS styles... [[User:Zygimantus|Zygimantus]] ([[User talk:Zygimantus|talk]]) 21:15, 18 October 2024 (UTC)
:::::@[[User:Zygimantus|Zygimantus]] For starters I think you need to configure https://lt.wikipedia.org/wiki/Module:Template_test_case/config for the wiki — in particular, the <code>wrappers</code> table, which the module uses to map names of templates to the functions and arguments they should use.
:::::If you notice, all of the templates related to [[Module:Template test case]] all contain the same code:
:::::<syntaxhighlight lang="mediawiki">{{#invoke:Template test case|main}}</syntaxhighlight>
:::::That's because, when the module sees it's being invoked from e.g. [[Template:Testcase table]], the <code>wrappers</code> table tells it to automatically add <code>_format = 'columns'</code> to the arguments. But on your wiki the module will never be invoked from [[Template:Testcase table]], it'll be invoked from [[lt:Šablonas:Testcase table|Šablonas:Testcase table]], and there's no wrapper mapping for that <s>template</s> page name. That's, at the very least, why your test cases are being formatted as rows instead of columns.
:::::It may not be the ''whole'' issue, but it's definitely '''an''' issue.
:::::You're also missing [[Module:Suppress categories]], which the your [[lt:Šablonas:Suppress categories|Šablonas:Suppress categories]] depends on. (Discovered by editing the testcases page, then selecting "Templates used" in the hamburger menu and looking for redlinks in the resulting list — a handy way to root out broken dependencies. There are a few others.) [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 06:09, 25 October 2024 (UTC)
::::::{{Reply|FeRDNYC}} thanks. I had to translate „Template“ text in that config page. Also I wasn't aware that on local wikis these pages are not the same: [[:lt:Šablonas:Testcase table]] and [[:lt:Template:Testcase table]]. For example, if you click on those links, they will direct to same page, but on Module page it works not like that I suppose. [[User:Zygimantus|Zygimantus]] ([[User talk:Zygimantus|talk]]) 13:06, 25 October 2024 (UTC)
:::::::@[[User:Zygimantus|Zygimantus]] Yeah, the problem is that [[lt:Template:Testcase table]] acts as an '''alias''' for the canonical name — which works fine, going ''in'', because you end up at the same place. But it doesn't work in reverse, so when the module asks "What template am I being called from?", the answer will never be "Template:Testcase table"; that's not what the page is called. [[User:FeRDNYC|FeRDNYC]] ([[User talk:FeRDNYC|talk]]) 16:37, 25 October 2024 (UTC)
 
== Option to invoke a module ==
 
It would be helpful if this module could be test module output. For example instead of {{para|_template=xyz}} we had something like {{para|_module|xyz}} and {{para|_function|def}} which would pass the arguments to <code><nowiki>{{#invoke:xyz|def|...</nowiki></code> and <code><nowiki>{{#invoke:xyz/sandbox|def|...</nowiki></code> and compare the results &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 21:54, 23 January 2025 (UTC)
 
:@[[User:Aidan9382|Aidan9382]]: are you familiar with this module? &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 09:53, 18 February 2025 (UTC)
::From a quick read of the documentation, it seems to be possible to force a module test if you use {{tl|Test case nowiki}}, e.g. <syntaxhighlight lang=wikitext inline>{{Test case nowiki|template=Disambiguation|heading1=[[Module:Disambiguation]]|heading2=[[Module:Disambiguation/sandbox]]|<nowiki>{{#invoke:__TEMPLATENAME__|isDisambiguationPage|Paris}}</nowiki>}}</syntaxhighlight>. The headers it normally provides will form template links instead of module links, so you have to specify the headers manually. A little hacky, but that's at least a way you can do it right now. [[User:Aidan9382|Aidan9382]] <sub>([[User talk:Aidan9382|talk]])</sub> 11:20, 18 February 2025 (UTC)
 
== Similar module with known answer rather than live v. sandbox==
 
This module compares the live result to the production result. I'm interested in comparing the live result, production result, or both to a known good result. For example, I'm testing date-related templates. I have a book with a list of information about dates, such as the Gregorian calendar date, Julian calendar date, [[Julian day]], and day of the week. I'd like to compare the result from a template to what this book says the result should be.
 
Any suggestions? [[User:Jc3s5h|Jc3s5h]] ([[User talk:Jc3s5h|talk]]) 11:53, 18 March 2025 (UTC)
 
== _showcode and templates in parameter values? ==
 
Using another template in the tested template parameters, like this:
{{demo|sep=produces
|<nowiki>{{test case |_showcode=1 |_template=tq |_template2=!tq
|1=parameter {{nobr|with a}} template }}
</nowiki>}}
That is, the inner template is substituted before showing the code. Can this be avoided somehow (without duplicating the whole set of parameters in <code><nowiki>_code=&lt;nowiki>{{__TEMPLATENAME__|...}}&lt;/nowiki></nowiki></code>)? — [[User:Mikhail Ryazanov|Mikhail Ryazanov]] ([[User talk:Mikhail Ryazanov|talk]]) 23:10, 6 June 2025 (UTC)