From 2cb72ceaffa9ff9fd6e3758b3091b0c27407cd5e Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 12 Nov 2014 11:06:04 -0700 Subject: [PATCH 1/2] Added script to generate missing tests This script will basically search for a file of the same name in the test/tests directory and then string search in that file for field and function names. Simple but effective for what we're doing. --- .gitignore | 1 + generate/missing-tests.js | 53 +++++++++++++++++++++++++++++++++++++++ generate/setup.js | 1 - package.json | 2 ++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 generate/missing-tests.js diff --git a/.gitignore b/.gitignore index 6778ac723..afac9533a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /vendor/*.sln /generate/idefs.json +/generate/missing-tests.json /binding.gyp *.log diff --git a/generate/missing-tests.js b/generate/missing-tests.js new file mode 100644 index 000000000..56eaff024 --- /dev/null +++ b/generate/missing-tests.js @@ -0,0 +1,53 @@ +const path = require("path"); +const idefs = require("./idefs"); +const Promise = require("nodegit-promise"); +const promisify = require("promisify-node"); +const fse = promisify(require("fs-extra")); +const testFilesPath = path.resolve(__dirname, "../test/tests"); + +var output = {}; + +function findMissingTest(idef) { + var testFilePath = path.join(testFilesPath, idef.filename + ".js"); + var result = {}; + + return fse.readFile(testFilePath, "utf8") + .then(function(file) { + var fieldsResult = []; + var functionsResult = []; + + idef.fields.forEach(function(field) { + if (file.indexOf(field.jsFunctionName) < 0) { + fieldsResult.push(field.jsFunctionName); + } + }); + + result.fields = fieldsResult; + + idef.functions.forEach(function(fn) { + if (file.indexOf(fn.jsFunctionName) < 0) { + functionsResult.push(fn.jsFunctionName); + } + }); + + result.functions = functionsResult; + }, + function() { + result.testFileMissing = false; + result.testFilePath = testFilePath; + }).then(function() { + output[idef.filename] = result; + }); +}; + +var promises = []; + +idefs.forEach(function(idef) { + promises.push(findMissingTest(idef)); +}); + +Promise.all(promises) +.then(function() { + fse.writeFileSync(path.join(__dirname, "missing-tests.json"), + JSON.stringify(output, null, 2)); +}); diff --git a/generate/setup.js b/generate/setup.js index 99304d836..50a82ccd7 100644 --- a/generate/setup.js +++ b/generate/setup.js @@ -17,7 +17,6 @@ libgit2.types.forEach(function(type) { // libgit2's docs aren't complete so we'll add in what they're missing here Array.prototype.push.apply(libgit2.types, supplement.new.types); - var output = []; var groupNames = []; var dependencyLookup = {}; diff --git a/package.json b/package.json index 395d8ca87..34abef0d8 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "nan": "~1.3.0", "node-gyp": "~1.0.2", "node-pre-gyp": "~0.5.27", + "nodegit-promise": "~1.0.0", "promise": "~6.0.0", "promisify-node": "~0.1.2", "q": "~1.0.1", @@ -91,6 +92,7 @@ "cov": "istanbul cover node_modules/mocha/bin/_mocha -- test/runner test/tests --report=lcov", "mocha": "mocha test/runner test/tests", "test": "npm run lint && npm run cov", + "missing-tests": "node generate/missing-tests", "publish": "node-pre-gyp package && node-pre-gyp publish", "generate": "node generate/setup && node generate", "install": "npm run generate && node install", From 9eb98514605a2e8251f9ea4adaef83a685839da4 Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 12 Nov 2014 17:23:38 -0700 Subject: [PATCH 2/2] Added an ignore file for things that are false-positives for missing tests --- generate/missing-tests-ignore.json | 34 ++++++++++++++++++++++++++++++ generate/missing-tests.js | 15 +++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 generate/missing-tests-ignore.json diff --git a/generate/missing-tests-ignore.json b/generate/missing-tests-ignore.json new file mode 100644 index 000000000..eac03aba8 --- /dev/null +++ b/generate/missing-tests-ignore.json @@ -0,0 +1,34 @@ +{ + "blob": { + "functions": [ + "createFrombuffer", + "isBinary", + "lookup", + "rawcontent", + "rawsize" + ] + }, + "clone": { + "functions": [ + "initOptions" + ] + }, + "commit": { + "functions": [ + "parentCount", + "parentId", + "treeId" + ] + }, + "diff": { + "functions": [ + "getDelta", + "numDeltas" + ] + }, + "object": { + "functions": [ + "type" + ] + } +} diff --git a/generate/missing-tests.js b/generate/missing-tests.js index 56eaff024..339f1a217 100644 --- a/generate/missing-tests.js +++ b/generate/missing-tests.js @@ -4,6 +4,7 @@ const Promise = require("nodegit-promise"); const promisify = require("promisify-node"); const fse = promisify(require("fs-extra")); const testFilesPath = path.resolve(__dirname, "../test/tests"); +const missingFileIgnores = require("./missing-tests-ignore"); var output = {}; @@ -15,9 +16,16 @@ function findMissingTest(idef) { .then(function(file) { var fieldsResult = []; var functionsResult = []; + var fieldIgnores = (missingFileIgnores[idef.filename] || {}).fields; + var functionIgnores = (missingFileIgnores[idef.filename] || {}).functions; + + fieldIgnores = fieldIgnores || []; + functionIgnores = functionIgnores || []; + file = file || ""; idef.fields.forEach(function(field) { - if (file.indexOf(field.jsFunctionName) < 0) { + if (file.indexOf(field.jsFunctionName) < 0 + && fieldIgnores.indexOf(field.jsFunctionName < 0)) { fieldsResult.push(field.jsFunctionName); } }); @@ -25,7 +33,8 @@ function findMissingTest(idef) { result.fields = fieldsResult; idef.functions.forEach(function(fn) { - if (file.indexOf(fn.jsFunctionName) < 0) { + if (file.indexOf(fn.jsFunctionName) < 0 + && functionIgnores.indexOf(fn.jsFunctionName) < 0) { functionsResult.push(fn.jsFunctionName); } }); @@ -50,4 +59,6 @@ Promise.all(promises) .then(function() { fse.writeFileSync(path.join(__dirname, "missing-tests.json"), JSON.stringify(output, null, 2)); +}, function(fail) { + console.log(fail); });