Skip to content

Commit 203d9bd

Browse files
committed
Merge pull request #274 from nodegit/test-contribution-infrastructure
Added script to generate missing tests
2 parents 60a9d9f + 9eb9851 commit 203d9bd

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

.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-ignore.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"blob": {
3+
"functions": [
4+
"createFrombuffer",
5+
"isBinary",
6+
"lookup",
7+
"rawcontent",
8+
"rawsize"
9+
]
10+
},
11+
"clone": {
12+
"functions": [
13+
"initOptions"
14+
]
15+
},
16+
"commit": {
17+
"functions": [
18+
"parentCount",
19+
"parentId",
20+
"treeId"
21+
]
22+
},
23+
"diff": {
24+
"functions": [
25+
"getDelta",
26+
"numDeltas"
27+
]
28+
},
29+
"object": {
30+
"functions": [
31+
"type"
32+
]
33+
}
34+
}

generate/missing-tests.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
const missingFileIgnores = require("./missing-tests-ignore");
8+
9+
var output = {};
10+
11+
function findMissingTest(idef) {
12+
var testFilePath = path.join(testFilesPath, idef.filename + ".js");
13+
var result = {};
14+
15+
return fse.readFile(testFilePath, "utf8")
16+
.then(function(file) {
17+
var fieldsResult = [];
18+
var functionsResult = [];
19+
var fieldIgnores = (missingFileIgnores[idef.filename] || {}).fields;
20+
var functionIgnores = (missingFileIgnores[idef.filename] || {}).functions;
21+
22+
fieldIgnores = fieldIgnores || [];
23+
functionIgnores = functionIgnores || [];
24+
file = file || "";
25+
26+
idef.fields.forEach(function(field) {
27+
if (file.indexOf(field.jsFunctionName) < 0
28+
&& fieldIgnores.indexOf(field.jsFunctionName < 0)) {
29+
fieldsResult.push(field.jsFunctionName);
30+
}
31+
});
32+
33+
result.fields = fieldsResult;
34+
35+
idef.functions.forEach(function(fn) {
36+
if (file.indexOf(fn.jsFunctionName) < 0
37+
&& functionIgnores.indexOf(fn.jsFunctionName) < 0) {
38+
functionsResult.push(fn.jsFunctionName);
39+
}
40+
});
41+
42+
result.functions = functionsResult;
43+
},
44+
function() {
45+
result.testFileMissing = false;
46+
result.testFilePath = testFilePath;
47+
}).then(function() {
48+
output[idef.filename] = result;
49+
});
50+
};
51+
52+
var promises = [];
53+
54+
idefs.forEach(function(idef) {
55+
promises.push(findMissingTest(idef));
56+
});
57+
58+
Promise.all(promises)
59+
.then(function() {
60+
fse.writeFileSync(path.join(__dirname, "missing-tests.json"),
61+
JSON.stringify(output, null, 2));
62+
}, function(fail) {
63+
console.log(fail);
64+
});

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)