Merge "Added some extra tests for ORMRow class"
[lhc/web/wiklou.git] / maintenance / jsparse.php
1 <?php
2 /**
3 * Maintenance script to do test JavaScript validity parses using jsmin+'s parser
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @ingroup Maintenance
21 */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class JSParseHelper extends Maintenance {
26 var $errs = 0;
27
28 public function __construct() {
29 parent::__construct();
30 $this->mDescription = "Runs parsing/syntax checks on JavaScript files";
31 $this->addArg( 'file(s)', 'JavaScript file to test', false );
32 }
33
34 public function execute() {
35 if ( $this->hasArg() ) {
36 $files = $this->mArgs;
37 } else {
38 $this->maybeHelp( true ); // @fixme this is a lame API :)
39 exit( 1 ); // it should exit from the above first...
40 }
41
42 $parser = new JSParser();
43 foreach ( $files as $filename ) {
44 wfSuppressWarnings();
45 $js = file_get_contents( $filename );
46 wfRestoreWarnings();
47 if ($js === false) {
48 $this->output( "$filename ERROR: could not read file\n" );
49 $this->errs++;
50 continue;
51 }
52
53 try {
54 $parser->parse( $js, $filename, 1 );
55 } catch (Exception $e) {
56 $this->errs++;
57 $this->output( "$filename ERROR: " . $e->getMessage() . "\n" );
58 continue;
59 }
60
61 $this->output( "$filename OK\n" );
62 }
63
64 if ($this->errs > 0) {
65 exit(1);
66 }
67 }
68 }
69
70 $maintClass = "JSParseHelper";
71 require_once( RUN_MAINTENANCE_IF_MAIN );