Merge "Fix wrong @return type hints in Language::tsTo… methods"
[lhc/web/wiklou.git] / tests / parserTests.php
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
27 define( 'MW_PARSER_TEST', true );
28
29 $options = [ 'quick', 'color', 'quiet', 'help', 'show-output',
30 'record', 'run-disabled', 'run-parsoid' ];
31 $optionsWithArgs = [ 'regex', 'filter', 'seed', 'setversion', 'file' ];
32
33 require_once __DIR__ . '/../maintenance/commandLine.inc';
34 require_once __DIR__ . '/TestsAutoLoader.php';
35
36 if ( isset( $options['help'] ) ) {
37 echo <<<ENDS
38 MediaWiki $wgVersion parser test suite
39 Usage: php parserTests.php [options...]
40
41 Options:
42 --quick Suppress diff output of failed tests
43 --quiet Suppress notification of passed tests (shows only failed tests)
44 --show-output Show expected and actual output
45 --color[=yes|no] Override terminal detection and force color output on or off
46 use wgCommandLineDarkBg = true; if your term is dark
47 --regex Only run tests whose descriptions which match given regex
48 --filter Alias for --regex
49 --file=<testfile> Run test cases from a custom file instead of parserTests.txt
50 --record Record tests in database
51 --compare Compare with recorded results, without updating the database.
52 --setversion When using --record, set the version string to use (useful
53 with git-svn so that you can get the exact revision)
54 --keep-uploads Re-use the same upload directory for each test, don't delete it
55 --fuzz Do a fuzz test instead of a normal test
56 --seed <n> Start the fuzz test from the specified seed
57 --help Show this help message
58 --run-disabled run disabled tests
59 --run-parsoid run parsoid tests (normally disabled)
60
61 ENDS;
62 exit( 0 );
63 }
64
65 # Cases of weird db corruption were encountered when running tests on earlyish
66 # versions of SQLite
67 if ( $wgDBtype == 'sqlite' ) {
68 $db = wfGetDB( DB_MASTER );
69 $version = $db->getServerVersion();
70 if ( version_compare( $version, '3.6' ) < 0 ) {
71 die( "Parser tests require SQLite version 3.6 or later, you have $version\n" );
72 }
73 }
74
75 $tester = new ParserTest( $options );
76
77 if ( isset( $options['file'] ) ) {
78 $files = [ $options['file'] ];
79 } else {
80 // Default parser tests and any set from extensions or local config
81 $files = $wgParserTestFiles;
82 }
83
84 # Print out software version to assist with locating regressions
85 $version = SpecialVersion::getVersion( 'nodb' );
86 echo "This is MediaWiki version {$version}.\n\n";
87
88 if ( isset( $options['fuzz'] ) ) {
89 $tester->fuzzTest( $files );
90 } else {
91 $ok = $tester->runTestsFromFiles( $files );
92 exit( $ok ? 0 : 1 );
93 }