Merge "resourceloader: Move batch fetch logic out of mw.loader.work()"
[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', 'dwdiff', 'mark-ws' ];
31 $optionsWithArgs = [ 'regex', 'filter', 'seed', 'setversion', 'file', 'norm' ];
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 --run-disabled run disabled tests
58 --run-parsoid run parsoid tests (normally disabled)
59 --dwdiff Use dwdiff to display diff output
60 --mark-ws Mark whitespace in diffs by replacing it with symbols
61 --norm=<funcs> Apply a comma-separated list of normalization functions to
62 both the expected and actual output in order to resolve
63 irrelevant differences. The accepted normalization functions
64 are: removeTbody to remove <tbody> tags; and trimWhitespace
65 to trim whitespace from the start and end of text nodes.
66 --use-tidy-config Use the wiki's Tidy configuration instead of known-good
67 defaults.
68 --help Show this help message
69
70 ENDS;
71 exit( 0 );
72 }
73
74 # Cases of weird db corruption were encountered when running tests on earlyish
75 # versions of SQLite
76 if ( $wgDBtype == 'sqlite' ) {
77 $db = wfGetDB( DB_MASTER );
78 $version = $db->getServerVersion();
79 if ( version_compare( $version, '3.6' ) < 0 ) {
80 die( "Parser tests require SQLite version 3.6 or later, you have $version\n" );
81 }
82 }
83
84 $tester = new ParserTest( $options );
85
86 if ( isset( $options['file'] ) ) {
87 $files = [ $options['file'] ];
88 } else {
89 // Default parser tests and any set from extensions or local config
90 $files = $wgParserTestFiles;
91 }
92
93 # Print out software version to assist with locating regressions
94 $version = SpecialVersion::getVersion( 'nodb' );
95 echo "This is MediaWiki version {$version}.\n\n";
96
97 if ( isset( $options['fuzz'] ) ) {
98 $tester->fuzzTest( $files );
99 } else {
100 $ok = $tester->runTestsFromFiles( $files );
101 exit( $ok ? 0 : 1 );
102 }