Module talk:OSM
Appearance
Error with no linktext
@Polyglot: Nice module! This is a really interesting idea. I just noticed that the module will produce an error if you don't supply frame.args.linktext
and the page also has a Wikidata entry. Should there be a default display value instead of a red error message? (Also, maybe "display" or something would be a more elegant parameter name than "linktext"?) Best — Mr. Stradivarius ♪ talk ♪ 06:27, 5 August 2015 (UTC)
- I just saw the error appearing myself. Yesterday all tests were fine, because the Module was only present on nl.WP. I'll have to find a better way to simulate a page with no link to a wikidata entry.
- Oops, you're talking about something else. I considered the linktext parameter as mandatory. This means it can't be used in templates for references though. I guess I'll have some more coding to do... Maybe simply text? I'll add a parameter to have it return simply text without link as well. --Polyglot (talk) 08:59, 5 August 2015 (UTC)
- @Polyglot: If
linktext
is really compulsory, then you could output a more informative error message, e.g.:
- @Polyglot: If
if not frame.args.linktext then
error('No "linktext" argument provided', 2)
end
- Or if you would rather that the error didn't show up in Category:Pages with script errors then you could do the same thing with wikitext:
if not frame.args.linktext then
return '<strong class="wikitext">No "linktext" argument provided</strong>'
end
- Or alternatively you could make the subpage name the default display text:
local display = frame.args.linktext or mw.title.getCurrentTitle().subpageText
- Whichever you think works the best. :) — Mr. Stradivarius ♪ talk ♪ 09:14, 5 August 2015 (UTC)
- Also, I like "linktext" better than "text", although I think "display" is better than both. (That's just my personal preference, though.) — Mr. Stradivarius ♪ talk ♪ 09:24, 5 August 2015 (UTC)
- @Mr. Stradivarius: I'll start changing it to display. You seem to be the goto guy if it comes to Lua scripts! :-) I was wondering. I copied the code to test the scripts from Module:Wikidata on nl.WP, but it has an incredible amount of duplication, which makes it error prone to work with. Isn't there a more elegant way to accomplish testing? I would have written more tests if it were more practical to do so. I'm a big believer in TDD. --Polyglot (talk) 10:16, 5 August 2015 (UTC)
Unit testing
@Mr. Stradivarius: I tried to create a module to ease unit testing, but it doesn't get transcluded. Do you see a way to make that work?--Polyglot (talk) 12:48, 5 August 2015 (UTC)
- @Polyglot: Where are you trying to transclude it? We usually put the test cases at "/testcases" (so Module:OSM/testcases in this case) and then run the tests on the talk page (so Module talk:OSM/testcases. We already have a couple of unit test modules to make things easier - my favourite is Module:ScribuntoUnit. The other main one is Module:UnitTests. See Module:Dts/testcases and Module talk:Dts/testcases for a recent example that I wrote. — Mr. Stradivarius ♪ talk ♪ 13:45, 5 August 2015 (UTC)