Commit graph

21 commits

Author SHA1 Message Date
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Subramanya Sastry
0f86da8d4f ParserTests: Update error message to point to the failing test file
Change-Id: Idd5963aedffb2520153a6d99a1661c0471686008
2021-01-22 14:59:21 -06:00
C. Scott Ananian
02ec9de651 Parser tests: Update TestFileReader to the latest reader from Parsoid
This replaces the 'requirements' from parser tests (hooks and
functionhooks) with a more flexible 'options' clause to allow
additional file-level requirements/options to support running parser
tests in multiple modes.  (For example, with the legacy parser or in
one of two parsoid modes.)

Bug: T254181
Depends-On: I636bd1f2c8aee327acbbd1636e2ac76355f1d80e
Change-Id: I58373d135c3a804f4ce9967112c338435f5cd4b6
2020-12-14 18:49:11 -05:00
Arlo Breault
8329352f08 Don't preface test description with comment
This seems to primarily be used in ParserTestPrinter::showTesting()
to print the string,

"Running test $desc... "

Follow up to 585cbcd

Change-Id: I53fc98ae56e3e9faad6ab1ca5a5a778f1c146fd1
2020-09-17 15:51:44 -04:00
C. Scott Ananian
585cbcd77f Use parser test file parser from Parsoid
One (test file) parser to rule them all.  Reduce a little bit of
redundant code between core and Parsoid by using Parsoid's parser test
file parser to run core's parser tests.

This should have no effect on users of TestFileReader::read() *except*
that Parsoid's test file reader is more strict about bogus lines in
the test file, including duplicate test names, and we've removed support
for the old v1 format (hard deprecated in 1.35).

Next step will be to be able to execute parser tests on extensions
using Parsoid's parser as well.

Bug: T254181
Depends-On: I8ab4a8c59ed1b6837dba428f96a8ba0084b7fb68
Change-Id: I5acaf82819ae964895a831be4f28c31c77a09e84
2020-08-17 14:52:08 -04:00
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +10:00
C. Scott Ananian
83a22b7fcd Remove codepaths which ran parser in 'untidy' mode
Disabling tidy has been deprecated since 1.33.  This cleans up the code
paths which still used untidy output.

Bug: T198214
Change-Id: I821ef3b8f59b272d983583d407b2f0794fe1e791
2020-04-13 21:34:04 +00:00
C. Scott Ananian
d4cdfe38fd Deprecate parserTests format v1 (take 2)
Parser tests should be tidy by default; we will
shortly stop running untidy tests.

Previously merged as Id78d04a56f83d8c554cb0a8e395fcaf75a7a9a06, then
reverted because it appears we missed updating a few extensions.

Bug: T174199
Bug: T249194
Depends-On: I09fc7fe087f4b770c81c76a3aab1de22098c2d20
Depends-On: I7d80557ae3b43b8da03cef56430e11a0f5dc5793
Depends-On: I23ccb612c940b98ca9da46a2e0848ccfe70e695d
Depends-On: I714f01d2d57f7290b147bdb47cbf69678b5f5adb
Change-Id: I5627efc4f0aad77bfb9eae1e7465c11ced69325e
2020-04-02 14:01:09 -04:00
DannyS712
7c74e448aa Revert "Deprecate parserTests format v1"
This reverts commit a7242a2eaa.

Reason for revert: Not all extension tests included in gated jobs
have been updated (specifically Scribunto and SyntaxHighlight tests)

Bug: T174199
Bug: T249194
Change-Id: I02997eda14e392e042df02dc8f64912bd4a54320
2020-04-02 08:17:08 +00:00
C. Scott Ananian
a7242a2eaa Deprecate parserTests format v1
Parser tests should be tidy by default; we will
shortly stop running untidy tests.

Bug: T174199
Depends-On: I7c8a08c4e6eff7caf4539a26fae475a4133f9a0c
Depends-On: I9c8acb05fdf2c79f618f0f317d511df77f26ec3b
Depends-On: Ibb23da480ac25cdee2ab24492e6eaebb51851bf9
Depends-On: Ifb13838c32748b1d52612da0cdb0e0a44c6e0689
Depends-On: I663c3919e08688354d68ced6945f6eb40265d2ac
Depends-On: I5f6b82d24754e438a4df9e2b1f6b4c9d6eca1be9
Depends-On: I746ee2b985537dc6bbb8a114e21cd11a683e0f74
Change-Id: Id78d04a56f83d8c554cb0a8e395fcaf75a7a9a06
2020-04-01 21:21:44 +00:00
C. Scott Ananian
f5bf2f23b7 Parser: remove leftover "transparent hook" code
Followup-To: I8384f47bbcde7604efa41b83db0dbc4f429219a8
Change-Id: I6da8cefad8bc70631277f9b7bd5d1af5474259ab
2020-01-28 20:10:20 -05:00
C. Scott Ananian
e7281ada17 Support html+untidy tests and version flag in parserTests file
This is step 1 of deprecating and then removing tests without a "tidy"
section.  We're first adding support for marking test clauses explicitly
as 'untidy'.  Then in a subsequent patch we're going to change the
default for otherwise-unmarked tests from 'untidy' to 'tidy'.

Bug: T174199
Bug: T198214
Change-Id: I1e2cbbd46282cb618178662ceaf8b1c36490d546
2020-01-22 21:24:46 -05:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
C. Scott Ananian
5dd3012d91 Don't infer parsoid-only parser tests based on presence of parsoid option.
For historical reasons, we used a complicated test to try to determine
if a test is "parsoid only" based on the presence of the string "parsoid"
in the parser test options clause.  But really test clauses should be
marked up specifically as html/php or html/parsoid, we don't need to
play hacky games any more.  Remove some unnecessary code and simplify
the test logic.

Change-Id: Ia331e7e12a75aa19aeb96601712f169f2aa75bf9
2018-11-02 16:41:40 -04:00
Fomafix
ce6f7faadd Remove trailing empty lines in PHP
Performed using
find . -name \*.php -exec sed -i -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' {} \;

Change-Id: I5d0627f94c73690cf3a8a453539c22c760c2aa60
2017-01-16 22:06:43 +01:00
umherirrender
34fe90ac52 Remove empty lines at end of functions
It looks like there is something missing after the last statement
Also remove some other empty lines at begin of functions, ifs or loops
while at these files

Change-Id: Ib00b5cfd31ca4dcd0c32ce33754d3c80bae70641
2016-11-05 11:55:10 +01:00
Tim Starling
d831844364 Parser test file editor
Add editTests.php, which provides an interactive interface to the
parser tests, with semi-automated editing.

Change-Id: I1a20d007ba4627d562a16c03849bbad7aec0e516
2016-10-28 16:15:59 +11:00
Tim Starling
3dfede8ada Don't skip tests which lack non-tidy output
Previously some 60 tests which only had tidy output were silently
removed from the test list and were not executed. Perhaps miraculously,
they all pass (if Math is disabled).

Also, throw an error if a test lacks any kind of result section. Fix one
test which accidentally lacked a result section.

Change-Id: Ic840678b851d6fc472b834cde3d8c83359f1c272
2016-09-29 12:07:11 +10:00
Tim Starling
6117fb244f Refactor parser tests
Merge the PHPUnit parser test runner with the old parserTests.inc,
taking the good bits of both. Reviewed, pared down and documented the
setup code. parserTests.php is now a frontend to a fully featured
parser test system, with lots of developer options, whereas PHPUnit
provides a simpler interface with increased isolation between test
cases.

Performance of both frontends is much improved, perhaps 2x faster for
parserTests.php and 10x faster for PHPUnit.

General:

* Split out the pre-Setup.php global variable configuration from
  phpunit.php into a new class called TestSetup, also called it from
  parserTests.php.
* Factored out the setup of TestsAutoLoader into a static method in
  Maintenance.
* In Setup.php improved "caches" debug output.

PHPUnit frontend:

* Delete the entire contents of NewParserTest and replace it with a
  small wrapper around ParserTestRunner. It doesn't inherit from
  MediaWikiTestCase anymore since integrating the setup code was an
  unnecessary complication.
* Rename MediaWikiParserTest to ParserTestTopLevelSuite and made it an
  instantiable TestSuite class instead of just a static method. Got rid
  of the eval(), just construct TestCase objects directly with a
  specified name, it works just as well.
* Introduce ParserTestFileSuite for per-file setup.
* Remove parser-related options from phpunit.php, since we don't
  support them anymore. Note that --filter now works just as well as
  --regex used to.
* Add CoreParserTestSuite, equivalent to ExtensionsParserTestSuite,
  for clarity.
* Make it possible to call MediaWikiTestCase::setupTestDB() more than
  once, as is implied by the documentation.

parserTests.php frontend:

* Made parserTests.php into a Maintenance subclass, moved CLI-specific
  code to it.
* Renamed ParserTest to ParserTestRunner, this is now the generic
  backend.
* Add --upload-dir option which sets up an FSFileBackend, similar
  to the old default behaviour

Test file reading and interpretation:

* Rename TestFileIterator to TestFileReader, and make it read and buffer
  an entire file, instead of iterating.
* The previous code had an associative array representation of test
  specifications. Used this form more widely to pass around test data.
* Remove the idea of !!hooks copying hooks from $wgParser, this is
  unnecessary now that all extensions use ParserFirstCallInit. Resurrect
  an old interpretation of the feature which was accidentally broken: if
  a named hook does not exist, skip all tests in the file.
* Got rid of the "subtest" idea for tidy variants, instead use a
  human-readable description that appears in the output.
* When all tests in a file are filtered or skipped, don't create the
  articles in them. This greatly speeds up execution time when --regex
  matches a small number of tests. It may possibly break extensions, but
  they would have been randomly broken anyway since there is no
  guarantee of test file execution order.
* Remove integrated testing of OutputPage::addCategoryLinks() category
  link formatting, life is complicated enough already. It can go in
  OutputPageTest if that's a thing we really need.

Result recording and display:

* Make TestRecorder into a generic plugin interface for progress output
  etc., which needs to be abstracted for PHPUnit integration.
* Introduce MultiTestRecorder for recorder chaining, instead of using
  a long inheritance chain. All test recorders now directly inherit from
  TestRecorder.
* Move all console-related code to the new ParserTestPrinter.
* Introduce PhpunitTestRecorder, which is the recorder for the PHPUnit
  frontend. Most events are ignored since they are never emitted in the
  PHPUnit frontend, which does not call runTests().
* Put more information into ParserTestResult and use it more often.

Setup and teardown:

* Introduce a new API for setup/teardown where setup functions return a
  ScopedCallback object which automatically performs the corresponding
  teardown when it goes out of scope.
* Rename setUp() to staticSetup(), rewrite. There was a lot of cruft in
  here which was simply copied from Setup.php without review, and had
  nothing to do with parser tests.
* Rename setupGlobals() to perTestSetup(), mostly rewrite. For
  performance, give staticSetup() precedence in cases where they were
  both setting up the same thing.
* In support of merged setup code, allow Hooks::clear() to be called
  from parserTests.php.
* Remove wgFileExtensions -- it is only used by UploadBase which we
  don't call.
* Remove wgUseImageResize -- superseded by MockMediaHandlerFactory which
  I imported from NewParserTest.
* Import MockFileBackend from NewParserTest. But instead of
  customising the configuration globals, I injected services.
* Remove thumbnail deletion from upload teardown. This makes glob
  handling as in the old parserTests.php unnecessary.
* Remove math file from upload teardown, math is actually an extension
  now! Also, the relevant parser tests were removed from the Math
  extension two years ago in favour of unit tests.
* Make addArticle() private, and introduce addArticles() instead, which
  allows setup/teardown to be done once for each batch of articles
  instead of every time.
* Remove $wgNamespaceAliases and $wgNamespaceProtection setup. These were
  copied in from Setup.php in 2010, and are redundant since we do
  actually run Setup.php.
* Use NullLockManager, don't set up a temporary directory just for
  this alone.

Fuzz tests:

* Use the new TestSetup class.
* Updated for ParserTestRunner interface change.
* Remove some obsolete references to fuzz tests from the two frontends
  where they used to reside.

Bug: T41473
Change-Id: Ia8e17008cb9d9b62ce5645e15a41a3b402f4026a
2016-09-12 16:11:42 +10:00
Tim Starling
df29a359f8 Renames preparatory to parser tests refactor
Since in several cases, with an all-in-one commit, git's file rename
detection failed, I split the renames out into their own commit to
make review easier. Some changes here won't make complete sense without
the following commit.

* Moved TestsAutoLoader to tests/common/. It will be joined by a friend.
* Renamed ParserTest to ParserTestRunner, since the former name was
  overly generic.
* Renamed TestFileIterator to TestFileReader. Please see the subsequent
  commit for rationale.
* Moved parserTests.php to tests/parser/. It was the only file left in
  tests/, and it should have been moved to tests/parser years ago,
  analogous to phpunit.php.
* Renamed NewParserTest to ParserIntegrationTest. This was a tricky one,
  apparently the name has to end in "Test" or else the structure test
  will fail. Analogous to ParserMethodsTest etc. Rationale: because it's
  not new anymore.
* Renamed MediaWikiParserTest to ParserTestTopLevelSuite and moved it to
  the suites directory. A more descriptive name. Being in suites/
  shields it from StructureTests, and is correct anyway.

Change-Id: Iddc6eaf815fdd64b3addb8570b4b6303ab99d634
2016-09-12 15:46:15 +10:00
Renamed from tests/parser/TestFileIterator.php (Browse further)