Skip to content

Commit 2cb72ce

Browse files
author
John Haley
committed
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.
1 parent 3dd00bf commit 2cb72ce

4 files changed

Lines changed: 56 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/vendor/*.sln
1515

1616
/generate/idefs.json
17+
/generate/missing-tests.json
1718
/binding.gyp
1819

1920
*.log

generate/missing-tests.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const path = require("path");
2+
const idefs = require("./idefs");
3+
const Promise = require("nodegit-promise");
4+
const promisify = require("promisify-node");
5+
const fse = promisify(require("fs-extra"));
6+
const testFilesPath = path.resolve(__dirname, "../test/tests");
7+
8+
var output = {};
9+
10+
function findMissingTest(idef) {
11+
var testFilePath = path.join(testFilesPath, idef.filename + ".js");
12+
var result = {};
13+
14+
return fse.readFile(testFilePath, "utf8")
15+
.then(function(file) {
16+
var fieldsResult = [];
17+
var functionsResult = [];
18+
19+
idef.fields.forEach(function(field) {
20+
if (file.indexOf(field.jsFunctionName) < 0) {
21+
fieldsResult.push(field.jsFunctionName);
22+
}
23+
});
24+
25+
result.fields = fieldsResult;
26+
27+
idef.functions.forEach(function(fn) {
28+
if (file.indexOf(fn.jsFunctionName) < 0) {
29+
functionsResult.push(fn.jsFunctionName);
30+
}
31+
});
32+
33+
result.functions = functionsResult;
34+
},
35+
function() {
36+
result.testFileMissing = false;
37+
result.testFilePath = testFilePath;
38+
}).then(function() {
39+
output[idef.filename] = result;
40+
});
41+
};
42+
43+
var promises = [];
44+
45+
idefs.forEach(function(idef) {
46+
promises.push(findMissingTest(idef));
47+
});
48+
49+
Promise.all(promises)
50+
.then(function() {
51+
fse.writeFileSync(path.join(__dirname, "missing-tests.json"),
52+
JSON.stringify(output, null, 2));
53+
});

generate/setup.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ libgit2.types.forEach(function(type) {
1717
// libgit2's docs aren't complete so we'll add in what they're missing here
1818
Array.prototype.push.apply(libgit2.types, supplement.new.types);
1919

20-
2120
var output = [];
2221
var groupNames = [];
2322
var dependencyLookup = {};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"nan": "~1.3.0",
6666
"node-gyp": "~1.0.2",
6767
"node-pre-gyp": "~0.5.27",
68+
"nodegit-promise": "~1.0.0",
6869
"promise": "~6.0.0",
6970
"promisify-node": "~0.1.2",
7071
"q": "~1.0.1",
@@ -91,6 +92,7 @@
9192
"cov": "istanbul cover node_modules/mocha/bin/_mocha -- test/runner test/tests --report=lcov",
9293
"mocha": "mocha test/runner test/tests",
9394
"test": "npm run lint && npm run cov",
95+
"missing-tests": "node generate/missing-tests",
9496
"publish": "node-pre-gyp package && node-pre-gyp publish",
9597
"generate": "node generate/setup && node generate",
9698
"install": "npm run generate && node install",

0 commit comments

Comments
 (0)