Marcoil has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/119076

Change subject: parserTests: Add option --first to stop testing after the first 
unexpected result
......................................................................

parserTests: Add option --first to stop testing after the first
unexpected result

Change-Id: Ia6c6affd9ea6d1620312b6ab727457326caed1f8
---
M tests/parserTests.js
1 file changed, 34 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/76/119076/1

diff --git a/tests/parserTests.js b/tests/parserTests.js
index b82a2dd..3195dee 100755
--- a/tests/parserTests.js
+++ b/tests/parserTests.js
@@ -252,6 +252,11 @@
                        description: 'Print output in JUnit XML format.',
                        'default': false,
                        'boolean': true
+               },
+               'first': {
+                       description: 'Stop after the first unexpected result',
+                       'default': false,
+                       'boolean': true
                }
        },{
                // override defaults for standard options
@@ -839,7 +844,7 @@
                        this.env.conf.wiki.removeExtensionTag( extensions[i] );
                }
 
-               setImmediate( endCb );
+               setImmediate(endCb, err);
        }.bind( this );
 
        var testTasks = [];
@@ -937,10 +942,10 @@
 ParserTests.prototype.processParsedHTML = function( item, options, mode, doc, 
cb ) {
        item.time.end = Date.now();
        // Check the result vs. the expected result.
-       this.checkHTML( item, DU.serializeChildren(doc), options, mode );
+       var checkPassed = this.checkHTML( item, DU.serializeChildren(doc), 
options, mode );
 
        // Now schedule the next test, if any
-       setImmediate( cb );
+       setImmediate( cb, !checkPassed );
 };
 
 /**
@@ -952,7 +957,8 @@
  * @param {Function} cb
  */
 ParserTests.prototype.processSerializedWT = function ( item, options, mode, 
wikitext, cb ) {
-       var self = this;
+       var self = this,
+               checkPassed;
        item.time.end = Date.now();
 
        if ( mode === 'selser' ) {
@@ -966,10 +972,10 @@
                                        item.resultWT = item.wikitext;
                                }
                                // Check the result vs. the expected result.
-                               self.checkWikitext( item, wikitext, options, 
mode );
+                               var checkPassed = self.checkWikitext( item, 
wikitext, options, mode );
 
                                // Now schedule the next test, if any
-                               setImmediate( cb );
+                               setImmediate( cb, !checkPassed );
                        } );
                        // Async processing
                        return;
@@ -977,10 +983,10 @@
        }
        // Sync processing
        // Check the result vs. the expected result.
-       self.checkWikitext( item, wikitext, options, mode );
+       checkPassed = self.checkWikitext( item, wikitext, options, mode );
 
        // Now schedule the next test, if any
-       setImmediate( cb );
+       setImmediate( cb, !checkPassed );
 
 };
 
@@ -1017,7 +1023,7 @@
                        if ( !booleanOption( options.quiet ) ) {
                                console.log( 'EXPECTED FAIL'.red + ': ' + 
extTitle.yellow );
                        }
-                       return;
+                       return true;
                }
        }
 
@@ -1063,6 +1069,8 @@
                // it anyway, just in case.
                this.env.log("error", error);
        }
+
+       return false;
 };
 
 /**
@@ -1091,7 +1099,7 @@
                console.log( 'UNEXPECTED PASS'.green.inverse +
                                         (isWhitelist ? ' (whitelist)' : '') +
                                         ':' + extTitle.yellow);
-               return;
+               return false;
        }
        if( !quiet ) {
                var outStr = 'EXPECTED PASS';
@@ -1108,6 +1116,7 @@
                        console.log( 'Even better, the non-selser wt2wt test 
failed!'.red + '');
                }
        }
+       return true;
 };
 
 /**
@@ -1206,6 +1215,8 @@
        var tb = testBlackList[title];
        var expectFail = ( tb ? tb.modes : [] ).indexOf( mode ) >= 0;
        var fail = ( expected.normal !== actual.normal );
+       // Return whether the test was as expected, independent of pass/fail
+       var asExpected;
 
        if ( fail &&
             booleanOption( options.whitelist ) &&
@@ -1222,7 +1233,7 @@
 
        // don't report selser fails when nothing was changed or it's a dup
        if ( mode === 'selser' && ( item.changes === 0 || item.duplicateChange 
) ) {
-               return;
+               return true;
        }
 
        if ( typeof pre === 'function' ) {
@@ -1230,14 +1241,16 @@
        }
 
        if ( fail ) {
-               reportFailure( title, comments, iopts, options, actual, 
expected, expectFail, quick, mode, null, item );
+               asExpected = reportFailure( title, comments, iopts, options, 
actual, expected, expectFail, quick, mode, null, item );
        } else {
-               reportSuccess( title, options, mode, !expectFail, whitelist, 
item );
+               asExpected = reportSuccess( title, options, mode, !expectFail, 
whitelist, item );
        }
 
        if ( typeof post === 'function' ) {
                post( mode );
        }
+
+       return asExpected;
 }
 
 /**
@@ -1268,7 +1281,7 @@
        var expected = { normal: normalizedExpected, raw: item.html };
        var actual = { normal: normalizedOut, raw: out, input: input };
 
-       options.reportResult( item.title, item.time, item.comments, 
item.options || null, expected, actual, options, mode, item );
+       return options.reportResult( item.title, item.time, item.comments, 
item.options || null, expected, actual, options, mode, item );
 };
 
 /**
@@ -1294,7 +1307,7 @@
        var expected = { isWT: true, normal: normalizedExpected, raw: 
item.wikitext };
        var actual = { isWT: true, normal: normalizedOut, raw: out, input: 
input };
 
-       options.reportResult( item.title, item.time, item.comments, 
item.options || null, expected, actual, options, mode, item );
+       return options.reportResult( item.title, item.time, item.comments, 
item.options || null, expected, actual, options, mode, item );
 };
 
 /**
@@ -1628,12 +1641,14 @@
 /**
  * @method
  */
-ParserTests.prototype.processCase = function ( i, options ) {
+ParserTests.prototype.processCase = function ( i, options, err ) {
        var ix, item, cases = this.cases, targetModes = options.modes;
 
        var nextCallback = this.processCase.bind( this, i + 1, options );
 
-       if ( i < this.cases.length ) {
+       var earlyExit = options.first && (typeof err !== 'undefined') && err;
+       if (i < this.cases.length &&
+            !earlyExit) {
                item = this.cases[i];
                if (typeof item === 'string') {
                        // this is a comment line in the file, ignore it.
@@ -1971,6 +1986,8 @@
                args = [ reportFailureXML, reportSuccessXML ].concat( args, 
pre, post );
                printResult.apply( this, args );
 
+               // In xml, test all cases always
+               return true;
        };
 
        return {

-- 
To view, visit https://gerrit.wikimedia.org/r/119076
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6c6affd9ea6d1620312b6ab727457326caed1f8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Marcoil <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to