parserTests.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * MediaWiki parser test suite
  4. *
  5. * Copyright © 2004 Brion Vibber <brion@pobox.com>
  6. * https://www.mediawiki.org/
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. * http://www.gnu.org/copyleft/gpl.html
  22. *
  23. * @file
  24. * @ingroup Testing
  25. */
  26. define( 'MW_PARSER_TEST', true );
  27. $options = [ 'quick', 'color', 'quiet', 'help', 'show-output',
  28. 'record', 'run-disabled', 'run-parsoid' ];
  29. $optionsWithArgs = [ 'regex', 'filter', 'seed', 'setversion', 'file' ];
  30. require_once __DIR__ . '/../maintenance/commandLine.inc';
  31. require_once __DIR__ . '/TestsAutoLoader.php';
  32. if ( isset( $options['help'] ) ) {
  33. echo <<<ENDS
  34. MediaWiki $wgVersion parser test suite
  35. Usage: php parserTests.php [options...]
  36. Options:
  37. --quick Suppress diff output of failed tests
  38. --quiet Suppress notification of passed tests (shows only failed tests)
  39. --show-output Show expected and actual output
  40. --color[=yes|no] Override terminal detection and force color output on or off
  41. use wgCommandLineDarkBg = true; if your term is dark
  42. --regex Only run tests whose descriptions which match given regex
  43. --filter Alias for --regex
  44. --file=<testfile> Run test cases from a custom file instead of parserTests.txt
  45. --record Record tests in database
  46. --compare Compare with recorded results, without updating the database.
  47. --setversion When using --record, set the version string to use (useful
  48. with git-svn so that you can get the exact revision)
  49. --keep-uploads Re-use the same upload directory for each test, don't delete it
  50. --fuzz Do a fuzz test instead of a normal test
  51. --seed <n> Start the fuzz test from the specified seed
  52. --help Show this help message
  53. --run-disabled run disabled tests
  54. --run-parsoid run parsoid tests (normally disabled)
  55. ENDS;
  56. exit( 0 );
  57. }
  58. # Cases of weird db corruption were encountered when running tests on earlyish
  59. # versions of SQLite
  60. if ( $wgDBtype == 'sqlite' ) {
  61. $db = wfGetDB( DB_MASTER );
  62. $version = $db->getServerVersion();
  63. if ( version_compare( $version, '3.6' ) < 0 ) {
  64. die( "Parser tests require SQLite version 3.6 or later, you have $version\n" );
  65. }
  66. }
  67. $tester = new ParserTest( $options );
  68. if ( isset( $options['file'] ) ) {
  69. $files = [ $options['file'] ];
  70. } else {
  71. // Default parser tests and any set from extensions or local config
  72. $files = $wgParserTestFiles;
  73. }
  74. # Print out software version to assist with locating regressions
  75. $version = SpecialVersion::getVersion( 'nodb' );
  76. echo "This is MediaWiki version {$version}.\n\n";
  77. if ( isset( $options['fuzz'] ) ) {
  78. $tester->fuzzTest( $files );
  79. } else {
  80. $ok = $tester->runTestsFromFiles( $files );
  81. exit( $ok ? 0 : 1 );
  82. }