jenkins-bot has submitted this change and it was merged.

Change subject: Check that parserTests.txt is in sync with upstream copy.
......................................................................


Check that parserTests.txt is in sync with upstream copy.

Warn (but don't update) when running parserTests.js, because we might
have a good reason for using an unsynchronized copy --- for example, we
might be testing an unmerged patch, or working on a branch.

"npm test" will always update parserTests.txt and then run the tests.

Change-Id: Iaeb674bb3459658e11727130d1046041ae5d078d
---
M js/tests/fetch-parserTests.txt.js
M js/tests/parserTests.js
2 files changed, 54 insertions(+), 7 deletions(-)

Approvals:
  GWicke: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/js/tests/fetch-parserTests.txt.js 
b/js/tests/fetch-parserTests.txt.js
index 2ff1f7f..8e98c72 100644
--- a/js/tests/fetch-parserTests.txt.js
+++ b/js/tests/fetch-parserTests.txt.js
@@ -1,7 +1,20 @@
+/**
+ * Fetch new parserTests.txt from upstream mediawiki/core.
+ */
+
+// UPDATE THESE when upstream mediawiki/core includes new parsoid-relevant 
tests
+// This ensures that our whitelist is in sync.
+// You can use 'sha1sum -b tests/parser/parserTests.txt' to compute this value:
+var expectedSHA1 = "f1af8c010dd69906e27036d787fbdc36f1067c55";
+// git log --pretty=oneline -1 tests/parser/parserTests.txt
+var latestCommit = "df27065fd7278c8c0519e1d400b21e88f383daf3";
+
 var fs = require('fs'),
        path = require('path'),
-       exists = fs.exists || path.exists,
-       https = require('https');
+       https = require('https'),
+       crypto = require('crypto');
+
+var existsSync = fs.existsSync || path.existsSync; // node 0.6 compat
 
 var url = {
        host: 'gerrit.wikimedia.org',
@@ -9,7 +22,17 @@
 };
 var target_name = __dirname+"/parserTests.txt";
 
-var fetch = function(url, target_name) {
+var computeSHA1 = function(target_name) {
+       var contents = fs.readFileSync(target_name);
+       return crypto.createHash('sha1').update(contents).digest('hex').
+               toLowerCase();
+};
+
+var fetch = function(url, target_name, gitCommit) {
+       console.log('Fetching parserTests.txt from mediawiki/core');
+       if (gitCommit) {
+               url.path = url.path.replace(/;hb=[^;]+;/, ';hb='+gitCommit+';');
+       }
        https.get(url, function(result) {
                var out = fs.createWriteStream(target_name);
                result.on('data', function(data) {
@@ -18,6 +41,10 @@
                result.on('end', function() {
                        if (out) {
                                out.end();
+                               if (expectedSHA1 !== computeSHA1(target_name)) {
+                                       console.warn('Parsoid expected 
sha1sum', expectedSHA1,
+                                                                'but got', 
computeSHA1(target_name));
+                               }
                        }
                });
        }).on('error', function(err) {
@@ -25,8 +52,23 @@
        });
 };
 
-exists(target_name, function(exists) {
-       if (!exists) {
-               fetch(url, target_name);
+var checkAndUpdate = function() {
+       if (existsSync(target_name) &&
+               expectedSHA1 === computeSHA1(target_name)) {
+               return; // a-ok!
        }
-});
+       fetch(url, target_name, latestCommit);
+};
+
+if (typeof module === 'object' && require.main !== module) {
+       module.exports = {
+               checkAndUpdate: checkAndUpdate,
+               expectedSHA1: expectedSHA1,
+               computeSHA1: function() {
+                       return existsSync(target_name) ? 
computeSHA1(target_name) :
+                               "<file not present>";
+               }
+       };
+} else {
+       checkAndUpdate();
+}
diff --git a/js/tests/parserTests.js b/js/tests/parserTests.js
index b75fac2..b893689 100755
--- a/js/tests/parserTests.js
+++ b/js/tests/parserTests.js
@@ -292,6 +292,11 @@
  * @returns {Object}
  */
 ParserTests.prototype.getTests = function ( argv ) {
+       // double check that test file is up-to-date with upstream
+       var fetcher = require(__dirname+"/fetch-parserTests.txt.js");
+       if (fetcher.expectedSHA1 !== fetcher.computeSHA1()) {
+               console.warn("WARNING: parserTests.txt not up-to-date with 
upstream.");
+       }
 
        // Startup by loading .txt test file
        var testFile;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaeb674bb3459658e11727130d1046041ae5d078d
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <wikime...@cscott.net>
Gerrit-Reviewer: Cscott <wikime...@cscott.net>
Gerrit-Reviewer: GWicke <gwi...@wikimedia.org>
Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to