r104700 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104699‎ | r104700 | r104701 >
Date:16:33, 30 November 2011
Author:hashar
Status:deferred
Tags:
Comment:
proper argument handling (requires 'optimist' module)

Handle arguments and options properly by using the 'optimist' node module.
Please note wordwrapping in usage does not seem to work on my setup :(

Only --help implemented yet.

Example:

$ node parserTests.js --help
Starting up JS parser tests
Usage: node ./parserTests.js

Options:
--filter, --regex Only run tests whose descriptions which match given regex (option not implemented)
--help, -h Show this help message
--disabled Run disabled tests (default false) (option not implemented) [boolean]
Modified paths:
  • /trunk/extensions/VisualEditor/tests/parser/README (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -20,6 +20,32 @@
2121 colors = require('colors'),
2222 HTML5 = require('html5').HTML5;
2323
 24+// Handle options/arguments with optimist module
 25+var optimist = require('optimist');
 26+
 27+var argv = optimist.usage( 'Usage: $0', {
 28+ 'filter': {
 29+ description: 'Only run tests whose descriptions which match given regex (option not implemented)',
 30+ alias: 'regex',
 31+ },
 32+ 'help': {
 33+ description: 'Show this help message',
 34+ alias: 'h',
 35+ },
 36+ 'disabled': {
 37+ description: 'Run disabled tests (default false) (option not implemented)',
 38+ default: false,
 39+ boolean: true,
 40+ },
 41+ }
 42+ ).argv // keep that
 43+ ;
 44+
 45+if( argv.help ) {
 46+ optimist.showHelp();
 47+ process.exit( 0 );
 48+}
 49+
2450 // @fixme wrap more or this setup in a common module
2551
2652 // Fetch up some of our wacky parser bits...
@@ -74,11 +100,11 @@
75101
76102 var testFileName = '../../../../phase3/tests/parser/parserTests.txt'; // default
77103 var testFileName2 = '../../../../tests/parser/parserTests.txt'; // Fallback. Not everyone fetch at phase3 level
78 -if (process.argv.length > 2) {
 104+
 105+if (argv._[0]) {
79106 // hack :D
80 - testFileName = process.argv[2];
 107+ testFileName = argv._[0] ;
81108 testFileName2 = null;
82 - console.log(testFileName);
83109 }
84110
85111 try {
Index: trunk/extensions/VisualEditor/tests/parser/README
@@ -9,4 +9,5 @@
1010 * jsdom
1111 * diff
1212 * libxmljs (requires native compilation)
 13+* optimist (for argument handling)
1314 * webworker

Status & tagging log