diff options
author | C. Scott Ananian <cscott@cscott.net> | 2023-02-09 14:42:49 -0500 |
---|---|---|
committer | C. Scott Ananian <cananian@wikimedia.org> | 2023-02-22 16:17:52 +0000 |
commit | ec1fdacc42a708da0d11c8757eccdd680e1e8302 (patch) | |
tree | a7a8f0c8f05d966b840511a9d36f2fd18c31c4f1 | |
parent | 338acfa785733dea1ce0802c71fcf744d7ce5046 (diff) | |
download | mediawikicore-ec1fdacc42a708da0d11c8757eccdd680e1e8302.tar.gz mediawikicore-ec1fdacc42a708da0d11c8757eccdd680e1e8302.zip |
ParserTestRunner: Move 'showflags' handling inside ::addParserOutputInfo()
This is just a clean up refactor to keep the option handling code in one
place, and to allow Parsoid to share it when running in integrated mode.
But in the process we tweaked a few other things for consistency:
* The 'pst' option now can add all of the parser output metadata flags
(not just 'showflags')
* The 'ill' and 'cat' options append to, instead of replacing, the
parser output.
* A new 'nohtml' option was added to allow suppressing the HTML in
cases where replacing, rather than appending to, the HTML is
desired.
* 'showflags' doesn't emit an 'extra' newline at the start of its output
any more.
The appropriate changes to parser tests were performed to accomodate
these tweaks.
Code search for uses of these options (uses in parsoid and core can be
ignored; uses of 'pst' are largely unchanged):
https://codesearch.wmcloud.org/search/?q=%28%5E%7C%20%29%28pst%7Cill%7Ccat%7Cshowflags%29%28%20%7C%24%29&i=nope&files=%5Etests%2Fparser%2F.*%5C.txt&excludeFiles=&repos=
Depends-On: I5c22f456a3ae5ea25b59c4246d68965099c465cc
Depends-On: If307de5d683829beb552663c72288d065827cfb6
Change-Id: I61a67a0e6928463e3872be9a42ff6992c6754662
-rw-r--r-- | RELEASE-NOTES-1.40 | 4 | ||||
-rw-r--r-- | tests/parser/ParserTestRunner.php | 54 | ||||
-rw-r--r-- | tests/parser/interlanguageLinks.txt | 3 | ||||
-rw-r--r-- | tests/parser/magicWords.txt | 6 | ||||
-rw-r--r-- | tests/parser/parserTests.txt | 6 |
5 files changed, 40 insertions, 33 deletions
diff --git a/RELEASE-NOTES-1.40 b/RELEASE-NOTES-1.40 index 8159197f0b1d..3ee00722ed58 100644 --- a/RELEASE-NOTES-1.40 +++ b/RELEASE-NOTES-1.40 @@ -409,6 +409,10 @@ because of Phabricator reports. Parser::replaceTableOfContentsMarker() function. * Skins can now choose which Codex theme should be loaded by setting the SkinCodexThemes attribute in their skin.json file. +* The parser test framework has been updated, and the 'pst', 'ill', 'cat' + and 'showflags' options have slight differences in their output. These + options are not much used outside core, but third parties may need to + update parser tests. * … == Compatibility == diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 0e3f195f89af..2d5b63b93a99 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -1333,6 +1333,7 @@ class ParserTestRunner { if ( isset( $opts['pst'] ) ) { $out = $parser->preSaveTransform( $wikitext, $title, $options->getUserIdentity(), $options ); $output = $parser->getOutput(); + $this->addParserOutputInfo( $out, $output, $opts, $title ); } elseif ( isset( $opts['msg'] ) ) { $out = $parser->transformMsg( $wikitext, $options, $title ); } elseif ( isset( $opts['section'] ) ) { @@ -1363,32 +1364,14 @@ class ParserTestRunner { 'unwrap' => !isset( $opts['wrap'] ), ] ); $out = preg_replace( '/\s+$/', '', $out ); + if ( isset( $opts['nohtml'] ) ) { + $out = ''; + } $this->addParserOutputInfo( $out, $output, $opts, $title ); } } - if ( isset( $output ) && isset( $opts['showflags'] ) ) { - $actualFlags = []; - foreach ( ParserOutputFlags::cases() as $name ) { - if ( $output->getOutputFlag( $name ) ) { - $actualFlags[] = $name; - } - } - sort( $actualFlags ); - $out .= "\nflags=" . implode( ', ', $actualFlags ); - # In 1.21 we deprecated the use of arbitrary keys for - # ParserOutput::setFlag() by extensions; if we find anyone - # still doing that complain about it. - $oldFlags = array_diff_key( - TestingAccessWrapper::newFromObject( $output )->mFlags, - array_fill_keys( ParserOutputFlags::cases(), true ) - ); - if ( $oldFlags ) { - wfDeprecated( 'Arbitrary flags in ParserOutput', '1.39' ); - } - } - ScopedCallback::consume( $teardownGuard ); $expected = $test->legacyHtml; @@ -1431,9 +1414,11 @@ class ParserTestRunner { } if ( isset( $opts['ill'] ) ) { - $out = implode( ' ', $output->getLanguageLinks() ); + if ( $out !== '' ) { + $out .= "\n"; + } + $out .= implode( ' ', $output->getLanguageLinks() ); } elseif ( isset( $opts['cat'] ) ) { - $out = ''; foreach ( $output->getCategories() as $name => $sortkey ) { if ( $out !== '' ) { $out .= "\n"; @@ -1464,6 +1449,29 @@ class ParserTestRunner { ( $output->getPageProperty( $prop ) ?? '' ); } } + if ( isset( $opts['showflags'] ) ) { + $actualFlags = []; + foreach ( ParserOutputFlags::cases() as $name ) { + if ( $output->getOutputFlag( $name ) ) { + $actualFlags[] = $name; + } + } + sort( $actualFlags ); + if ( $out !== '' ) { + $out .= "\n"; + } + $out .= "flags=" . implode( ', ', $actualFlags ); + # In 1.21 we deprecated the use of arbitrary keys for + # ParserOutput::setFlag() by extensions; if we find anyone + # still doing that complain about it. + $oldFlags = array_diff_key( + TestingAccessWrapper::newFromObject( $output )->mFlags, + array_fill_keys( ParserOutputFlags::cases(), true ) + ); + if ( $oldFlags ) { + wfDeprecated( 'Arbitrary flags in ParserOutput', '1.39' ); + } + } } /** diff --git a/tests/parser/interlanguageLinks.txt b/tests/parser/interlanguageLinks.txt index 982d58eb79ec..5757ec5aba5e 100644 --- a/tests/parser/interlanguageLinks.txt +++ b/tests/parser/interlanguageLinks.txt @@ -236,6 +236,9 @@ ill [[ko:]] !! html/php +<p><br /> +<a href="/wiki/Ko:" title="Ko:">ko:</a> +</p> es: !! html/parsoid <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/"/> diff --git a/tests/parser/magicWords.txt b/tests/parser/magicWords.txt index 89f6bbee2cd7..34a25a37c8ea 100644 --- a/tests/parser/magicWords.txt +++ b/tests/parser/magicWords.txt @@ -720,7 +720,6 @@ showflags !! wikitext {{REVISIONTIMESTAMP:This page does not exist}} !! html/php - flags= !! html/parsoid+integrated <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"REVISIONTIMESTAMP:This page does not exist","function":"revisiontimestamp"},"params":{},"i":0}}]}'></span> @@ -751,7 +750,6 @@ showflags !! wikitext {{REVISIONUSER}} !! html/php - flags=vary-user !! html/parsoid+integrated <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"REVISIONUSER","function":"revisionuser"},"params":{},"i":0}}]}'></span> @@ -766,7 +764,6 @@ showflags !! wikitext {{REVISIONUSER:{{PAGENAME}}}} !! html/php - flags=vary-user !! html/parsoid+integrated <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"REVISIONUSER:{{PAGENAME}}","function":"revisionuser"},"params":{},"i":0}}]}'></span> @@ -780,7 +777,6 @@ showflags !! wikitext {{REVISIONUSER:This page does not exist}} !! html/php - flags= !! html/parsoid+integrated <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"REVISIONUSER:This page does not exist","function":"revisionuser"},"params":{},"i":0}}]}'></span> @@ -794,7 +790,6 @@ showflags !! wikitext {{REVISIONUSER}} !! html/php - flags=vary-user !! html/parsoid+integrated <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"REVISIONUSER","function":"revisionuser"},"params":{},"i":0}}]}'></span> @@ -824,7 +819,6 @@ showflags !! wikitext {{REVISIONID:{{PAGENAME}}}} !! html/php - flags=vary-revision-id !! html/parsoid+integrated <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"REVISIONID:{{PAGENAME}}","function":"revisionid"},"params":{},"i":0}}]}'></span> diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 45c2b46347f9..6bad87bd36b1 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -7887,7 +7887,6 @@ T307691: show-toc flag: no sections showflags !! wikitext !! html/php - flags= !! end @@ -7899,7 +7898,6 @@ showflags !! wikitext __FORCETOC__ !! html/php - flags= !! end @@ -7911,7 +7909,6 @@ showflags !! wikitext __TOC__ !! html/php - flags= !! end @@ -7922,7 +7919,6 @@ showflags !! wikitext __NOTOC__ !! html/php - flags= !! end @@ -14262,6 +14258,8 @@ cat !! wikitext This uses {{=}} and {{Template:=}}. !! html/php +<p>This uses = and =. +</p> !! end !!test |