Module talk:Template test case: Difference between revisions

Content deleted Content added
 
(15 intermediate revisions by 6 users not shown)
Line 292:
 
...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? ==
Line 301 ⟶ 306:
:(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)