Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed tests to use nodeunit instead

  • Loading branch information...
commit 45fa80e4db9a2dc57a8e19b6d70542d39198f820 1 parent 16010d3
Christian Amor Kvalheim authored
2  lib/git/blob.js
View
@@ -60,7 +60,7 @@ var lazy_reader = function(repo, id, type, variable) {
//
// Returns array of commit and array of lines
Blob.blame = function(repo, commit, file, callback) {
- var Commit = require('git/commit').Commit;
+ var Commit = require('./commit').Commit;
repo.git.blame({'p':true}, commit, '--', file, function(err, data) {
if(err) return callback(err, data);
12 lib/git/commit.js
View
@@ -117,18 +117,22 @@ var actor = function(line) {
}
// Convert commit text to list of commits
-Commit.list_from_string = function(repo, text) {
+Commit.list_from_string = function(repo, text) {
// Split up the result
var lines = text.split("\n");
+
+ // require('util').debug("-------------------------------------------------- lines")
+ // require('util').debug(require('util').inspect(lines))
+ // require('util').debug("-------------------------------------------------- text end")
+
var linesshift = function() {
- var l = lines.shift();
- // console.log(l);
- return l;
+ return lines.shift();
};
var commits = [];
// Parse all commit messages
while(lines.length > 0) {
var id = linesshift().split(/ /).pop();
+ if(lines.length == 0) break;
var tree = new Tree(repo, linesshift().split(/ /).pop());
// Let's get the parents
4 package.json
View
@@ -1,6 +1,6 @@
{ "name" : "git"
, "description" : "A node.js library for git"
-, "version" : "0.1.1"
+, "version" : "0.1.2"
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>"
, "contributors" : []
, "repository" : { "type" : "git"
@@ -14,7 +14,7 @@
, "directories" : { "lib" : "./lib/git" }
, "engines" : { "node" : ">=0.4.0" }
, "dependencies": { "compress" : ">=0.1.6" }
-, "devDependencies":{ "async_testing" : ">=0.3.2" }
+, "devDependencies":{ "nodeunit" : ">=0.5.1" }
, "licenses" : [ { "type" : "Apache License, Version 2.0"
, "url" : "http://www.apache.org/licenses/LICENSE-2.0" } ]
}
32 test/test_actor.js
View
@@ -1,35 +1,39 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Actor = require('git').Actor;
-
-var suite = exports.suite = new TestSuite("actor tests");
+ Actor = require('../lib/git').Actor;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Should create actor from string seperating name and email":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should create actor from string seperating name and email":function(assert) {
var actor = Actor.from_string("Tom Werner <tom@example.com>");
assert.equal("Tom Werner", actor.name);
assert.equal("tom@example.com", actor.email);
- finished();
+ assert.done();
},
- "Should create actor from string only containing name":function(assert, finished) {
+ "Should create actor from string only containing name":function(assert) {
var actor = Actor.from_string("Tom Werner");
assert.equal("Tom Werner", actor.name);
assert.equal(null, actor.email);
- finished();
+ assert.done();
},
- "Should correctly return name when calling toString()":function(assert, finished) {
+ "Should correctly return name when calling toString()":function(assert) {
var actor = Actor.from_string("Tom Werner <tom@example.com>");
assert.equal(actor.name, actor.toString());
- finished();
+ assert.done();
}
});
68 test/test_all.js
View
@@ -1,68 +0,0 @@
-require.paths.unshift("./lib", "./spec/lib", "./test");
-
-module.exports = {};
-
-var sys = require('sys');
-
-// patch
-var async_testing = require('async_testing');
-var TestSuite = async_testing.TestSuite = function (name) {
- this.name = name;
- this.obj = {};
-};
-TestSuite.prototype.addTests = function (obj) {
- this.obj = obj;
- for(key in obj) {
- if (!obj.hasOwnProperty(key)) continue;
- obj[key] = (function(fun) {
- return function (test) {
- return fun(test, test.finish);
- };
- })(obj[key]);
- }
-};
-
-TestSuite.prototype.runTests = function (callback) {
- module.exports[this.name] = function () {
- async_testing.runSuite(this.obj, {name:this.name, onSuitDone:callback});
- };
-};
-
-
-// Diff tests
-require('diff/test_diff').suite.runTests(function() {});
-
-// Set max listeners
-process.setMaxListeners(100);
-
-// Run all tests
-require('test_head').suite.runTests(function() {});
-require('test_diff').suite.runTests(function() {});
-require('test_file_index').suite.runTests(function() {});
-require('test_commit').suite.runTests(function() {});
-require('test_actor').suite.runTests(function() {});
-require('test_blame').suite.runTests(function() {});
-require('test_blame_tree').suite.runTests(function() {});
-require('test_blob').suite.runTests(function() {});
-require('test_commit_stats').suite.runTests(function() {});
-require('test_commit_write').suite.runTests(function() {});
-require('test_config').suite.runTests(function() {});
-require('test_git').suite.runTests(function() {});
-require('test_index_status').suite.runTests(function() {});
-require('test_merge').suite.runTests(function() {});
-require('test_raw').suite.runTests(function() {});
-require('test_remote').suite.runTests(function() {});
-require('test_repo').suite.runTests(function() {});
-require('test_git_basic').suite.runTests(function() {});
-require('test_git_alt').suite.runTests(function() {});
-// require('test_git_index').suite.runTests(function() {});
-require('test_git_iv2').suite.runTests(function() {});
-require('test_submodule').suite.runTests(function() {});
-require('test_tag').suite.runTests(function() {});
-require('test_tree').suite.runTests(function() {});
-
-
-if (module == require.main) {
- return require('async_testing').run(__filename, process.ARGV);
-}
-
28 test/test_blame.js
View
@@ -1,18 +1,22 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Actor = require('git').Actor;
-
-var suite = exports.suite = new TestSuite("blame tests");
+ Actor = require('../lib/git').Actor;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Should correctly provide simple blame":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly provide simple blame":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
var commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
repo.blame('History.txt', commit, function(err, blame) {
@@ -24,12 +28,12 @@ suite.addTests({
assert.equal(3, line.lineno);
assert.equal(3, line.oldlineno);
assert.equal('634396b2f541a9f2d58b00be1a07f0c358b999b3', line.commit.id);
- finished();
+ assert.done();
})
});
},
- "Should correctly provide deep blame":function(assert, finished) {
+ "Should correctly provide deep blame":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
var commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
repo.blame('lib/grit.rb', commit, function(err, blame) {
@@ -42,7 +46,7 @@ suite.addTests({
assert.equal(25, line.lineno);
assert.equal(16, line.oldlineno);
assert.equal('46291865ba0f6e0c9818b11be799fe2db6964d56', line.commit.id);
- finished();
+ assert.done();
})
});
}
34 test/test_blame_tree.js
View
@@ -1,43 +1,47 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Actor = require('git').Actor,
- Git = require('git').Git;
-
-var suite = exports.suite = new TestSuite("blame tree tests");
+ Actor = require('../lib/git').Actor,
+ Git = require('../lib/git').Git;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Should correctly retrieve blame tree":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly retrieve blame tree":function(assert) {
var git = new Git("./test/dot_git");
var commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
git.blame_tree(commit, function(err, tree) {
assert.equal('7bcc0ee821cdd133d8a53e8e7173a334fef448aa', tree['History.txt']);
- finished();
+ assert.done();
});
},
- "Should correctly retrieve blame tree path":function(assert, finished) {
+ "Should correctly retrieve blame tree path":function(assert) {
var git = new Git("./test/dot_git");
var commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
git.blame_tree(commit, 'lib', function(err, tree) {
assert.equal('5a0943123f6872e75a9b1dd0b6519dd42a186fda', tree['lib/grit.rb']);
assert.equal('2d3acf90f35989df8f262dc50beadc4ee3ae1560', tree['lib/grit']);
- finished();
+ assert.done();
});
},
- "Should correctly retrieve blame tree for multiple paths":function(assert, finished) {
+ "Should correctly retrieve blame tree for multiple paths":function(assert) {
var git = new Git("./test/dot_git");
var commit = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
git.blame_tree(commit, 'lib/grit', function(err, tree) {
assert.equal('22825175e37f22c9418d756ca69b574d75602994', tree['lib/grit/diff.rb']);
- finished();
+ assert.done();
});
}
});
54 test/test_blob.js
View
@@ -1,30 +1,34 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Blob = require('git').Blob,
- Commit = require('git').Commit;
-
-var suite = exports.suite = new TestSuite("blob tests");
+ Blob = require('../lib/git').Blob,
+ Commit = require('../lib/git').Commit;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
// blob
- "Should not locate blob":function(assert, finished) {
+ "Should not locate blob":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.blob("blahblah", function(err, blob) {
assert.ok(blob instanceof Blob);
- finished();
+ assert.done();
});
});
},
- "Should correctly return blob contents":function(assert, finished) {
+ "Should correctly return blob contents":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.cat_file = function(type, ref, callback) {
@@ -33,11 +37,11 @@ suite.addTests({
var blob = new Blob(repo, 'abc');
assert.equal("Hello world", blob.data);
- finished();
+ assert.done();
});
},
- "Should correctly cache data":function(assert, finished) {
+ "Should correctly cache data":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var times_called = 0;
@@ -51,12 +55,12 @@ suite.addTests({
var blob = new Blob(repo, 'abc');
assert.equal("Hello world", blob.data);
assert.equal("Hello world", blob.data);
- finished();
+ assert.done();
});
},
// size
- "Should correctly return the file size":function(assert, finished) {
+ "Should correctly return the file size":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.cat_file = function(type, ref, callback) {
@@ -65,34 +69,34 @@ suite.addTests({
var blob = new Blob(repo, 'abc');
assert.equal(11, blob.size);
- finished();
+ assert.done();
});
},
// data
// mime_type
- "Should correctly return mime_type for known types":function(assert, finished) {
+ "Should correctly return mime_type for known types":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var blob = new Blob(repo, null, 'abc', 'foo.png');
assert.equal('image/png', blob.mime_type);
- finished();
+ assert.done();
});
},
- "Should correctly return text plain for unknown types":function(assert, finished) {
+ "Should correctly return text plain for unknown types":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var blob = new Blob(repo, 'abc');
assert.equal('text/plain', blob.mime_type);
- finished();
+ assert.done();
});
},
// blame
- "Should correctly grab the blame":function(assert, finished) {
+ "Should correctly grab the blame":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.blame = function(type, ref, callback) {
@@ -116,17 +120,17 @@ suite.addTests({
assert.equal('tom@mojombo.com', commit.committer.email);
assert.deepEqual(new Date(1191997100 * 1000), commit.committed_date);
assert.equal('initial grit setup', commit.message);
- finished();
+ assert.done();
});
});
},
- "Should correctly return the base name":function(assert, finished) {
+ "Should correctly return the base name":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var blob = new Blob(repo, null, null, 'foo/bar.rb');
assert.equal('bar.rb', blob.basename);
- finished();
+ assert.done();
});
}
});
74 test/test_commit.js
View
@@ -1,20 +1,24 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Commit = require('git').Commit,
- Blob = require('git').Blob;
-
-var suite = exports.suite = new TestSuite("commit tests");
+ Commit = require('../lib/git').Commit,
+ Blob = require('../lib/git').Blob;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
// __bake__
- "Test commit bake":function(assert, finished) {
+ "Test commit bake":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.rev_list = function(a, b, callback) {
callback(null, fixture('rev_list_single'));
@@ -23,34 +27,34 @@ suite.addTests({
var commit = new Commit(repo, '4c8124ffcf4039d292442eeccabdeca5af5c5017')
assert.equal("Tom Preston-Werner", commit.author.name);
assert.equal("tom@mojombo.com", commit.author.email);
- finished();
+ assert.done();
});
},
// short_name
- "Test abbreviation of id":function(assert, finished) {
+ "Test abbreviation of id":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f', function(err, commit) {
commit.id_abbrev(function(err, id_abbrev) {
assert.equal("80f136f", id_abbrev);
- finished();
+ assert.done();
})
});
});
},
// count
- "Test commit count":function(assert, finished) {
+ "Test commit count":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
Commit.count(repo, 'master', function(err, count) {
assert.equal(107, count);
- finished();
+ assert.done();
})
});
},
// diff
- "Test correct execution of diff":function(assert, finished) {
+ "Test correct execution of diff":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.diff = function(a, b, c, callback) {
var args = Array.prototype.slice.call(arguments, 1);
@@ -78,12 +82,12 @@ suite.addTests({
assert.equal(null, diffs[5].a_blob);
assert.equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id);
assert.equal(true, diffs[5].new_file);
- finished();
+ assert.done();
});
});
},
- "Test diff with two commits":function(assert, finished) {
+ "Test diff with two commits":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.diff = function(a, b, c, callback) {
var args = Array.prototype.slice.call(arguments, 1);
@@ -101,12 +105,12 @@ suite.addTests({
Commit.diff(repo, '59ddc32', '13d27d5', function(err, diffs) {
assert.equal(3, diffs.length);
assert.deepEqual(["lib/grit/commit.rb", "test/fixtures/show_empty_commit", "test/test_commit.rb"], diffs.map(function(diff) { return diff.a_path; }));
- finished();
+ assert.done();
});
});
},
- "Test diff with files":function(assert, finished) {
+ "Test diff with files":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.call_git = function(a, b, c, d, e, callback) {
var args = Array.prototype.slice.call(arguments, 1);
@@ -120,12 +124,12 @@ suite.addTests({
Commit.diff(repo, '59ddc32', ["lib"], function(err, diffs) {
assert.equal(1, diffs.length);
assert.deepEqual('lib/grit/diff.rb', diffs[0].a_path);
- finished();
+ assert.done();
});
});
},
- "Test diff with two commits and files":function(assert, finished) {
+ "Test diff with two commits and files":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.diff = function(a, b, c, d, e, callback) {
assert.equal(true, a['full_index']);
@@ -140,13 +144,13 @@ suite.addTests({
Commit.diff(repo, '59ddc32', '13d27d5', ["lib"], function(err, diffs) {
assert.equal(1, diffs.length);
assert.deepEqual('lib/grit/commit.rb', diffs[0].a_path);
- finished();
+ assert.done();
});
});
},
// diffs
- "Test diffs":function(assert, finished) {
+ "Test diffs":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.diff = function() {
var args = Array.prototype.slice.call(arguments, 0);
@@ -174,12 +178,12 @@ suite.addTests({
assert.equal('f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_blob.id);
assert.equal(true, diffs[5].new_file);
- finished();
+ assert.done();
});
});
},
- "Test diffs on initial import":function(assert, finished) {
+ "Test diffs on initial import":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.show = function(options, sha, callback) {
assert.deepEqual({full_index:true, pretty:'raw'}, options);
@@ -205,12 +209,12 @@ suite.addTests({
assert.equal(null, diffs[5].a_blob);
assert.equal('32cec87d1e78946a827ddf6a8776be4d81dcf1d1', diffs[5].b_blob.id);
assert.equal(true, diffs[5].new_file);
- finished();
+ assert.done();
});
});
},
- "Test diffs on initial import with empty commit":function(assert, finished) {
+ "Test diffs on initial import with empty commit":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.show = function(options, sha, callback) {
assert.deepEqual({full_index:true, pretty:'raw'}, options);
@@ -222,12 +226,12 @@ suite.addTests({
var commit = new Commit(repo, '634396b2f541a9f2d58b00be1a07f0c358b999b3');
commit.diffs(function(err, diffs) {
assert.deepEqual([], diffs);
- finished();
+ assert.done();
});
});
},
- "Test diffs with mode only change":function(assert, finished) {
+ "Test diffs with mode only change":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.git.diff = function(options, sha, callback) {
var args = Array.prototype.slice.call(arguments, 0);
@@ -241,23 +245,23 @@ suite.addTests({
assert.equal(23, diffs.length);
assert.equal('100644', diffs[0].a_mode);
assert.equal('100755', diffs[0].b_mode);
- finished();
+ assert.done();
});
});
},
// to String
- "Test toString() override for the commit":function(assert, finished) {
+ "Test toString() override for the commit":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
// Fetch the diff
var commit = new Commit(repo, 'abc');
assert.equal("abc", commit.toString());
- finished();
+ assert.done();
});
},
// to patch
- "Test create patch from commit":function(assert, finished) {
+ "Test create patch from commit":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
// Fetch the diff
var commit = new Commit(repo, '80f136f500dfdb8c3e8abf4ae716f875f0a1b57f');
@@ -271,7 +275,7 @@ suite.addTests({
assert.ok(patch.indexOf('@@ -1,17 +1,17 @@') != -1);
assert.ok(patch.indexOf('+# recurse(t)') != -1);
assert.ok(patch.indexOf('1.7.') != -1);
- finished();
+ assert.done();
});
});
},
32 test/test_commit_stats.js
View
@@ -1,20 +1,24 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Blob = require('git').Blob,
- Commit = require('git').Commit,
- GitFileOperations = require('git').GitFileOperations;
-
-var suite = exports.suite = new TestSuite("commit stats tests");
+ Blob = require('../lib/git').Blob,
+ Commit = require('../lib/git').Commit,
+ GitFileOperations = require('../lib/git').GitFileOperations;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Should correctly retrieve commit stats":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly retrieve commit stats":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var back_exists = GitFileOperations.fs_exist;
@@ -38,12 +42,12 @@ suite.addTests({
assert.equal(3, Object.keys(stats).length);
// Reset the overriden function
GitFileOperations.fs_exist = back_exists;
- finished();
+ assert.done();
})
});
},
- "Should correctly match the content":function(assert, finished) {
+ "Should correctly match the content":function(assert) {
// Open the first repo
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var back_exists = GitFileOperations.fs_exist;
@@ -72,7 +76,7 @@ suite.addTests({
assert.equal('{"id":"a49b96b339c525d7fd455e0ad4f6fe7b550c9543","files":[["examples/ex_add_commit.rb",13,0,13],["examples/ex_index.rb",1,1,2]],"additions":14,"deletions":1,"total":15}', JSON.stringify(stats['a49b96b339c525d7fd455e0ad4f6fe7b550c9543']));
// Reset the overriden function
GitFileOperations.fs_exist = back_exists;
- finished();
+ assert.done();
})
});
}
30 test/test_commit_write.js
View
@@ -1,19 +1,23 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Commit = require('git').Commit,
- Blob = require('git').Blob;
-
-var suite = exports.suite = new TestSuite("commit write tests");
+ Commit = require('../lib/git').Commit,
+ Blob = require('../lib/git').Blob;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Should correctly fetch commit index":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly fetch commit index":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.commit = function() {
var args = Array.prototype.slice.call(arguments, 0);
@@ -24,12 +28,12 @@ suite.addTests({
repo.commit_index('my message', function(err, results) {
assert.ok(results.indexOf('Created commit') != -1)
- finished();
+ assert.done();
})
});
},
- "Should correctly commit all":function(assert, finished) {
+ "Should correctly commit all":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.commit = function() {
var args = Array.prototype.slice.call(arguments, 0);
@@ -40,7 +44,7 @@ suite.addTests({
repo.commit_all('my message', function(err, results) {
assert.ok(results.indexOf('Created commit') != -1)
- finished();
+ assert.done();
})
});
}
30 test/test_config.js
View
@@ -1,19 +1,23 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Commit = require('git').Commit,
- Blob = require('git').Blob;
-
-var suite = exports.suite = new TestSuite("config tests");
+ Commit = require('../lib/git').Commit,
+ Blob = require('../lib/git').Blob;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Should correctly return an assoc array":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly return an assoc array":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.config = function() {
var args = Array.prototype.slice.call(arguments, 0);
@@ -27,12 +31,12 @@ suite.addTests({
assert.equal(null, config.fetch("unknown"));
assert.equal("false", config.fetch("core.bare"));
assert.equal("default", config.fetch("unknown", "default"));
- finished();
+ assert.done();
});
});
},
- "Should correctly set value":function(assert, finished) {
+ "Should correctly set value":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.config = function() {
var args = Array.prototype.slice.call(arguments, 0);
@@ -56,7 +60,7 @@ suite.addTests({
repo.config(function(err, config) {
config.set("unknown", "default", function(err, result) {
assert.ok(!err);
- finished();
+ assert.done();
})
});
});
26 test/test_diff.js
View
@@ -1,19 +1,23 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- Diff = require('git').Diff,
- Blob = require('git').Blob;
-
-var suite = exports.suite = new TestSuite("diff tests");
+ Diff = require('../lib/git').Diff,
+ Blob = require('../lib/git').Blob;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Test list from string new mode":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Test list from string new mode":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var output = fixture('diff_new_mode');
@@ -22,7 +26,7 @@ suite.addTests({
assert.equal(2, diffs.length)
assert.equal(10, diffs[0].diff.split(/\n/).length)
assert.equal(null, diffs.pop().diff)
- finished();
+ assert.done();
});
});
}
48 test/test_file_index.js
View
@@ -1,62 +1,66 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
fs = require('fs'),
- FileIndex = require('git').FileIndex;
-
-var suite = exports.suite = new TestSuite("file index tests");
+ FileIndex = require('../lib/git').FileIndex;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
}
-suite.addTests({
- "Count all entries":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Count all entries":function(assert) {
new FileIndex("./test/dot_git", function(err, file_index) {
file_index.count_all(function(err, count) {
assert.equal(107, count);
- finished();
+ assert.done();
})
});
},
- "Count for a given sha":function(assert, finished) {
+ "Count for a given sha":function(assert) {
var commit = "c12f398c2f3c4068ca5e01d736b1c9ae994b2138";
new FileIndex("./test/dot_git", function(err, file_index) {
file_index.count(commit, function(err, count) {
assert.equal(20, count);
- finished();
+ assert.done();
})
});
},
- "Retrieve all files for a commit":function(assert, finished) {
+ "Retrieve all files for a commit":function(assert) {
var commit = "c12f398c2f3c4068ca5e01d736b1c9ae994b2138";
new FileIndex("./test/dot_git", function(err, file_index) {
file_index.files(commit, function(err, files) {
assert.equal(4, files.length);
assert.equal("lib/grit/blob.rb", files[0]);
- finished();
+ assert.done();
})
});
},
- "Retrieve all commits for a given file":function(assert, finished) {
+ "Retrieve all commits for a given file":function(assert) {
var commit = "c12f398c2f3c4068ca5e01d736b1c9ae994b2138";
new FileIndex("./test/dot_git", function(err, file_index) {
file_index.commits_for('lib/grit/blob.rb', function(err, commits) {
assert.ok(commits.indexOf("3e0955045cb189a7112015c26132152a94f637bf") != -1);
assert.equal(8, commits.length)
- finished();
+ assert.done();
})
});
},
- "Retrieve array of last commits":function(assert, finished) {
+ "Retrieve array of last commits":function(assert) {
var commit = "c12f398c2f3c4068ca5e01d736b1c9ae994b2138";
new FileIndex("./test/dot_git", function(err, file_index) {
@@ -64,12 +68,12 @@ suite.addTests({
assert.equal('74fd66519e983a0f29e16a342a6059dbffe36020', commits_by_file['lib/grit/git.rb']);
assert.equal(commit, commits_by_file['lib/grit/commit.rb']);
assert.equal(null, commits_by_file['lib/grit/actor.rb']);
- finished();
+ assert.done();
})
});
},
- "Retrieve array of last commits based on regexp pattern":function(assert, finished) {
+ "Retrieve array of last commits based on regexp pattern":function(assert) {
var commit = "c12f398c2f3c4068ca5e01d736b1c9ae994b2138";
new FileIndex("./test/dot_git", function(err, file_index) {
@@ -77,18 +81,18 @@ suite.addTests({
assert.equal(10, Object.keys(commits_by_file).length);
assert.equal(commit, commits_by_file['lib/grit/commit.rb']);
assert.equal(null, commits_by_file['lib/grit/actor.rb']);
- finished();
+ assert.done();
})
});
},
- "Retrieve last commits containing a directory in array":function(assert, finished) {
+ "Retrieve last commits containing a directory in array":function(assert) {
var commit = "c12f398c2f3c4068ca5e01d736b1c9ae994b2138";
new FileIndex("./test/dot_git", function(err, file_index) {
file_index.last_commits(commit, ['lib/grit.rb', 'lib/grit/'], function(err, commits_by_file) {
assert.equal(commit, commits_by_file['lib/grit/']);
- finished();
+ assert.done();
})
});
}
42 test/test_git.js
View
@@ -1,42 +1,46 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Git = require('git').Git;
-
-var suite = exports.suite = new TestSuite("node-git tests");
+var testCase = require('nodeunit').testCase,
+ Git = require('../lib/git').Git;
/**
Test basic node-git functionality
**/
-suite.addTests({
- "Should correctly call native git method":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly call native git method":function(assert) {
var git = new Git("./test/grit");
git.git('version', function(err, result) {
assert.ok(!err);
assert.ok(result.match(/^git version [\w\.]*/));
- finished();
+ assert.done();
});
},
- "Should fail to call wrong native method":function(assert, finished) {
+ "Should fail to call wrong native method":function(assert) {
var git = new Git("./test/grit");
git.git('bad', function(err, result) {
assert.ok(err);
assert.ok(err.indexOf("git: 'bad' is not a git command") != -1);
- finished();
+ assert.done();
})
},
- "Should fail to call wrong native function with skip timeout":function(assert, finished) {
+ "Should fail to call wrong native function with skip timeout":function(assert) {
var git = new Git("./test/grit");
git.git('bad', {timeout:false}, function(err, result) {
assert.ok(err);
assert.ok(err.indexOf("git: 'bad' is not a git command") != -1);
- finished();
+ assert.done();
})
},
- "Should correctly transform options":function(assert, finished) {
+ "Should correctly transform options":function(assert) {
var git = new Git("./test/grit");
assert.deepEqual(["-s"], git.transform_options({s:true}));
assert.deepEqual([], git.transform_options({s:false}));
@@ -46,10 +50,10 @@ suite.addTests({
assert.deepEqual(["--max-count='5'"], git.transform_options({max_count:5}));
assert.deepEqual(["-s", "-t"], git.transform_options({s:true, t:true}));
- finished();
+ assert.done();
},
- "Should correctly escape calls to the git shell":function(assert, finished) {
+ "Should correctly escape calls to the git shell":function(assert) {
var git = new Git("./test/grit");
git.exec = function(call, options, callback) {
assert.equal(Git.git_binary + " --git-dir='./test/grit' foo --bar='bazz\\'er'", call)
@@ -65,12 +69,12 @@ suite.addTests({
};
git.git('bar', {x:"quu'x"}, function(err, result) {
- finished();
+ assert.done();
});
});
},
- "Should correctly escape standalone argument":function(assert, finished) {
+ "Should correctly escape standalone argument":function(assert) {
var git = new Git("./test/grit");
git.exec = function(call, options, callback) {
assert.equal(Git.git_binary + " --git-dir='./test/grit' foo 'bar\\'s'", call)
@@ -86,7 +90,7 @@ suite.addTests({
};
git.git('foo', {}, "bar", "; echo 'noooo'", function(err, result) {
- finished();
+ assert.done();
});
});
}
28 test/test_git_alt.js
View
@@ -1,10 +1,6 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
- BinaryParser = require('git').BinaryParser;
-
-var suite = exports.suite = new TestSuite("node-git alt tests");
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
+ BinaryParser = require('../lib/git').BinaryParser;
var to_bin = function(sha1o) {
var sha1 = '';
@@ -17,8 +13,16 @@ var to_bin = function(sha1o) {
/**
Test basic node-git functionality
**/
-suite.addTests({
- "Should correctly execute basic":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly execute basic":function(assert) {
// Sha's
var commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a';
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
@@ -55,13 +59,13 @@ suite.addTests({
repo2.commits(function(err, commits) {
assert.equal(10, commits.length);
- finished();
+ assert.done();
})
});
});
},
- "Should correctly work with clone of clone":function(assert, finished) {
+ "Should correctly work with clone of clone":function(assert) {
// Sha's
var commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a';
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
@@ -101,7 +105,7 @@ suite.addTests({
repo3.commits(function(err, commits) {
assert.equal(10, commits.length);
- finished();
+ assert.done();
})
});
});
142 test/test_git_basic.js
View
@@ -1,14 +1,10 @@
-
-TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
- Repo = require('git').Repo,
- Git = require('git').Git,
+var testCase = require('nodeunit').testCase,
+ Repo = require('../lib/git').Repo,
+ Git = require('../lib/git').Git,
fs = require('fs'),
- Commit = require('git').Commit,
- Blob = require('git').Blob,
- GitFileOperations = require('git').GitFileOperations;
-
-var suite = exports.suite = new TestSuite("git basic tests");
+ Commit = require('../lib/git').Commit,
+ Blob = require('../lib/git').Blob,
+ GitFileOperations = require('../lib/git').GitFileOperations;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
@@ -19,8 +15,16 @@ var chomp = function chomp(raw_text) {
return raw_text.replace(/(\n|\r)+$/, '');
}
-suite.addTests({
- "Should correctly init gitdir":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly init gitdir":function(assert) {
var tmp_path = '/tmp/gitdir';
GitFileOperations.fs_rmdir_r(tmp_path, function(err, result) {
// Create a temp directory
@@ -30,12 +34,12 @@ suite.addTests({
git.init({}, function(err, git) {
var stat = fs.statSync(tmp_path + "/config");
assert.equal(true, stat.isFile());
- finished();
+ assert.done();
});
})
},
- "Should correctly merge logs":function(assert, finished) {
+ "Should correctly merge logs":function(assert) {
var c1 = '420eac97a826bfac8724b6b0eef35c20922124b7';
var c2 = '30e367cef2203eba2b341dc9050993b06fd1e108';
var git = new Git("./test/dot_git");
@@ -43,19 +47,19 @@ suite.addTests({
git.rev_list({pretty:'raw', max_count:10}, 'master', function(err, rev_output) {
assert.ok(rev_output.match("commit " + c1));
assert.ok(rev_output.match("commit " + c2));
- finished();
+ assert.done();
})
},
- "Should correctly honor max count":function(assert, finished) {
+ "Should correctly honor max count":function(assert) {
var git = new Git("./test/dot_git");
git.rev_list({max_count:10}, 'master', function(err, rev_output) {
assert.equal(10, rev_output.split(/\n/).length);
- finished();
+ assert.done();
})
},
- "Should correctly retrieve the diff between two commits":function(assert, finished) {
+ "Should correctly retrieve the diff between two commits":function(assert) {
var commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
var commit2 = '420eac97a826bfac8724b6b0eef35c20922124b7';
@@ -63,22 +67,22 @@ suite.addTests({
git.diff(commit1, commit2, function(err, out) {
assert.equal(null, err);
assert.ok(out.match('index 6afcf64..9e78ddf 100644'));
- finished();
+ assert.done();
});
},
- "Should correctly perform single diff":function(assert, finished) {
+ "Should correctly perform single diff":function(assert) {
var commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
var git = new Git("./test/dot_git");
git.diff(commit1, null, function(err, out) {
assert.equal(null, err);
assert.ok(out.match('index ad42ff5..aa50f09 100644'));
- finished();
+ assert.done();
})
},
- "Should correctly perform full diff":function(assert, finished) {
+ "Should correctly perform full diff":function(assert) {
var commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560';
var commit2 = '420eac97a826bfac8724b6b0eef35c20922124b7';
@@ -86,11 +90,11 @@ suite.addTests({
git.diff(commit1, commit2, {full_index:true}, function(err, out) {
assert.equal(null, err);
assert.ok(out.match('index 6afcf64c80da8253fa47228eb09bc0eea217e5d1..9e78ddfaabf79f8314cc9a53a2f59775aee06bd7'));
- finished();
+ assert.done();
})
},
- "Should correctly perform add diff":function(assert, finished) {
+ "Should correctly perform add diff":function(assert) {
var commit1 = 'c9cf68fc61bd2634e90a4f6a12d88744e6297c4e';
var commit2 = '7a8d32cb18a0ba2ff8bf86cadacc3fd2816da219';
@@ -100,11 +104,11 @@ suite.addTests({
assert.ok(out.indexOf('--- /dev/null\n+++ b/test/test_tag.rb') != -1);
assert.ok(out.indexOf('diff --git a/test/test_tag.rb b/test/test_tag.rb') != -1);
assert.ok(out.indexOf('index 0000000..2e3b0cb') != -1);
- finished();
+ assert.done();
})
},
- "Should correctly perform remove diff":function(assert, finished) {
+ "Should correctly perform remove diff":function(assert) {
var commit1 = 'c9cf68fc61bd2634e90a4f6a12d88744e6297c4e';
var commit2 = '7a8d32cb18a0ba2ff8bf86cadacc3fd2816da219';
@@ -114,87 +118,87 @@ suite.addTests({
assert.ok(out.indexOf('--- a/test/fixtures/diff_2\n+++ /dev/null') != -1);
assert.ok(out.indexOf('diff --git a/test/fixtures/diff_2 b/test/fixtures/diff_2') != -1);
assert.ok(out.indexOf('index 0000000..2e3b0cb') != -1);
- finished();
+ assert.done();
});
},
- "Should correctly cat file contents from commit":function(assert, finished) {
+ "Should correctly cat file contents from commit":function(assert) {
var commit_sha = '5e3ee1198672257164ce3fe31dea3e40848e68d5';
var git = new Git("./test/dot_git");
git.cat_file("p", commit_sha, function(err, out) {
assert.equal(null, err);
assert.equal(fixture('cat_file_commit_ruby'), out);
- finished();
+ assert.done();
});
},
- "Should correctly cat file contents from tree":function(assert, finished) {
+ "Should correctly cat file contents from tree":function(assert) {
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
var git = new Git("./test/dot_git");
git.cat_file("p", tree_sha, function(err, out) {
assert.equal(null, err);
assert.equal(fixture('cat_file_tree_ruby', true), out);
- finished();
+ assert.done();
});
},
- "Should correctly cat file contents from blob":function(assert, finished) {
+ "Should correctly cat file contents from blob":function(assert) {
var blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce';
var git = new Git("./test/dot_git");
git.cat_file("p", blob_sha, function(err, out) {
assert.equal(null, err);
assert.equal(fixture('cat_file_blob_ruby'), out);
- finished();
+ assert.done();
});
},
- "Should correctly cat file size":function(assert, finished) {
+ "Should correctly cat file size":function(assert) {
var blob_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
var git = new Git("./test/dot_git");
git.cat_file("s", blob_sha, function(err, out) {
assert.equal(null, err);
assert.equal('252', out);
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree":function(assert, finished) {
+ "Should correctly execute ls_tree":function(assert) {
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
var git = new Git("./test/dot_git");
git.ls_tree(tree_sha, function(err, out) {
assert.equal(null, err);
assert.equal(fixture('cat_file_tree_ruby', true), out);
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree with blobs":function(assert, finished) {
+ "Should correctly execute ls_tree with blobs":function(assert) {
var blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce';
var git = new Git("./test/dot_git");
git.ls_tree(blob_sha, function(err, out) {
assert.equal(null, err);
assert.equal(null, out);
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree with treeish":function(assert, finished) {
+ "Should correctly execute ls_tree with treeish":function(assert) {
var git = new Git("./test/dot_git");
git.ls_tree('testing', function(err, out) {
assert.equal(null, err);
assert.equal(fixture('cat_file_tree_ruby', true), out);
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree with ls_tree_paths":function(assert, finished) {
+ "Should correctly execute ls_tree with ls_tree_paths":function(assert) {
var git = new Git("./test/dot_git");
var paths = ['History.txt', 'lib'];
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
@@ -202,11 +206,11 @@ suite.addTests({
git.ls_tree(tree_sha, paths, function(err, out) {
assert.equal(null, err);
assert.equal(fixture('ls_tree_paths_ruby', true), out);
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree with ls_tree_paths multi single":function(assert, finished) {
+ "Should correctly execute ls_tree with ls_tree_paths multi single":function(assert) {
var git = new Git("./test/dot_git");
var paths = ['lib/grit.rb'];
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
@@ -214,11 +218,11 @@ suite.addTests({
git.ls_tree(tree_sha, paths, function(err, out) {
assert.equal(null, err);
assert.equal("100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1\tlib/grit.rb", out);
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree with recursive":function(assert, finished) {
+ "Should correctly execute ls_tree with recursive":function(assert) {
// this is the tree associated with @commit_sha, which we use in
// the next test
var git = new Git("./test/dot_git");
@@ -227,103 +231,103 @@ suite.addTests({
git.ls_tree(tree_sha, null, {r:true}, function(err, out) {
assert.equal(null, err);
assert.equal(fixture('ls_tree_recursive'), out);
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree with recursive and a commit":function(assert, finished) {
+ "Should correctly execute ls_tree with recursive and a commit":function(assert) {
var git = new Git("./test/dot_git");
var commit_sha = '5e3ee1198672257164ce3fe31dea3e40848e68d5';
git.ls_tree(commit_sha, null, {r:true}, function(err, out) {
assert.equal(null, err);
assert.equal(fixture('ls_tree_recursive'), out);
- finished();
+ assert.done();
});
},
- "Should correctly execute rev_list pretty":function(assert, finished) {
+ "Should correctly execute rev_list pretty":function(assert) {
var git = new Git("./test/dot_git");
git.rev_list({pretty:'raw'}, 'master', function(err, out) {
assert.equal(fixture('rev_list_all'), out);
- finished();
+ assert.done();
});
},
- "Should correctly execute rev_list raw since":function(assert, finished) {
+ "Should correctly execute rev_list raw since":function(assert) {
var git = new Git("./test/dot_git");
git.rev_list({since:new Date(1204644738*1000)}, 'master', function(err, out) {
assert.ok(out.match(fixture('rev_list_since')));
- finished();
+ assert.done();
});
},
- "Should correctly execute rev_list raw":function(assert, finished) {
+ "Should correctly execute rev_list raw":function(assert) {
var git = new Git("./test/dot_git");
git.rev_list({pretty:'raw'}, 'f1964ad1919180dd1d9eae9d21a1a1f68ac60e77', function(err, out) {
assert.ok(out.match('f1964ad1919180dd1d9eae9d21a1a1f68ac60e77'))
assert.equal(656, out.split(/\n/).length)
- finished();
+ assert.done();
});
},
- "Should correctly execute rev_list":function(assert, finished) {
+ "Should correctly execute rev_list":function(assert) {
var git = new Git("./test/dot_git");
git.rev_list({}, 'master', function(err, out) {
var lines = out.split('\n');
var lines2 = fixture('rev_list_lines').split('\n');
for(var i = 0; i < lines.length; i++) { assert.equal(lines[i], lines2[i]) }
- finished();
+ assert.done();
});
},
- "Should correctly execute rev_list range":function(assert, finished) {
+ "Should correctly execute rev_list range":function(assert) {
var git = new Git("./test/dot_git");
git.rev_list({}, '30e367cef2203eba2b341dc9050993b06fd1e108..3fa4e130fa18c92e3030d4accb5d3e0cadd40157', function(err, out) {
assert.equal(fixture('rev_list_range', true), out)
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree_paths multi":function(assert, finished) {
+ "Should correctly execute ls_tree_paths multi":function(assert) {
var git = new Git("./test/dot_git");
var paths = ['History.txt', 'lib/grit.rb'];
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
git.ls_tree(tree_sha, paths, {}, function(err, out) {
assert.equal(fixture('ls_tree_paths_ruby_deep', true), out)
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree_path":function(assert, finished) {
+ "Should correctly execute ls_tree_path":function(assert) {
var git = new Git("./test/dot_git");
var paths = ['lib/'];
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
git.ls_tree(tree_sha, paths, function(err, out) {
assert.equal('100644 blob 6afcf64c80da8253fa47228eb09bc0eea217e5d1\tlib/grit.rb\n040000 tree 6244414d0229fb2bd58bc426a2afb5ba66773498\tlib/grit', out)
- finished();
+ assert.done();
});
},
- "Should correctly execute ls_tree_path deep":function(assert, finished) {
+ "Should correctly execute ls_tree_path deep":function(assert) {
var git = new Git("./test/dot_git");
var paths = ['lib/grit/']
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
git.ls_tree(tree_sha, paths, function(err, out) {
assert.equal(fixture('ls_tree_subdir', true), out)
- finished();
+ assert.done();
});
},
- "Should correctly retrieve file type":function(assert, finished) {
+ "Should correctly retrieve file type":function(assert) {
var git = new Git("./test/dot_git");
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
var blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce';
@@ -341,15 +345,15 @@ suite.addTests({
assert.equal('commit', result)
})
- finished();
+ assert.done();
},
- "Should correctly execute ls_tree and return no sha found tree":function(assert, finished) {
+ "Should correctly execute ls_tree and return no sha found tree":function(assert) {
var git = new Git("./test/dot_git");
git.ls_tree('6afcf64c80da8253fa47228eb09bc0eea217e5d0', function(err, out) {
assert.equal('no such sha found', err)
- finished();
+ assert.done();
});
},
40 test/test_git_index.js
View
@@ -1,14 +1,10 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
+var testCase = require('nodeunit').testCase,
fs = require('fs'),
exec = require('child_process').exec,
- Repo = require('git').Repo,
- BinaryParser = require('git').BinaryParser,
- Actor = require('git').Actor,
- Blob = require('git').Blob;
-
-var suite = exports.suite = new TestSuite("node-git index tests");
+ Repo = require('../lib/git').Repo,
+ BinaryParser = require('../lib/git').BinaryParser,
+ Actor = require('../lib/git').Actor,
+ Blob = require('../lib/git').Blob;
var to_bin = function(sha1o) {
var sha1 = '';
@@ -51,8 +47,16 @@ var destroy_directory = function(directory, callback) {
/**
Test basic node-git functionality
**/
-suite.addTests({
- // "Sould correctly add files":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ // "Sould correctly add files":function(assert) {
// var base_repo = "./test/dot_git_iv2"
//
// create_tmp_directory(base_repo, function(err, target_path) {
@@ -75,7 +79,7 @@ suite.addTests({
// assert.equal('f80c3b68482d5e1c8d24c9b8139340f0d0a928d0', c.id)
// // Destory directory and cleanup
// destroy_directory(target_path, function(err, result) {
- // finished();
+ // assert.done();
// });
// });
// });
@@ -86,7 +90,7 @@ suite.addTests({
// });
// },
//
- // "Should correctly add path file":function(assert, finished) {
+ // "Should correctly add path file":function(assert) {
// var base_repo = "./test/dot_git_iv2"
//
// create_tmp_directory(base_repo, function(err, target_path) {
@@ -113,7 +117,7 @@ suite.addTests({
// assert.equal('77aa887449c28a922a660b2bb749e4127f7664e5', c.id)
// // Destroy directory and cleanup
// destroy_directory(target_path, function(err, result) {
- // finished();
+ // assert.done();
// });
// });
// });
@@ -124,7 +128,7 @@ suite.addTests({
// });
// },
//
- // "Should correctly add correct order for commited files":function(assert, finished) {
+ // "Should correctly add correct order for commited files":function(assert) {
// var base_repo = "./test/dot_git_iv2"
//
// create_tmp_directory(base_repo, function(err, target_path) {
@@ -152,7 +156,7 @@ suite.addTests({
// assert.equal('lib', entries[1]);
// // Destroy directory and cleanup
// destroy_directory(target_path, function(err, result) {
- // finished();
+ // assert.done();
// });
// });
// });
@@ -163,7 +167,7 @@ suite.addTests({
// });
// },
//
- // "Should correctly modify file":function(assert, finished) {
+ // "Should correctly modify file":function(assert) {
// var base_repo = "./test/dot_git_iv2"
//
// create_tmp_directory(base_repo, function(err, target_path) {
@@ -188,7 +192,7 @@ suite.addTests({
// assert.equal('e45d6b418e34951ddaa3e78e4fc4d3d92a46d3d1', b.id);
// // Destroy directory and cleanup
// destroy_directory(target_path, function(err, result) {
- // finished();
+ // assert.done();
// });
// });
// });
32 test/test_git_iv2.js
View
@@ -1,14 +1,10 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
+var testCase = require('nodeunit').testCase,
fs = require('fs'),
exec = require('child_process').exec,
- Repo = require('git').Repo,
- BinaryParser = require('git').BinaryParser,
- Actor = require('git').Actor,
- Blob = require('git').Blob;
-
-var suite = exports.suite = new TestSuite("node-git iv2 tests");
+ Repo = require('../lib/git').Repo,
+ BinaryParser = require('../lib/git').BinaryParser,
+ Actor = require('../lib/git').Actor,
+ Blob = require('../lib/git').Blob;
var to_bin = function(sha1o) {
var sha1 = '';
@@ -51,8 +47,16 @@ var destroy_directory = function(directory, callback) {
/**
Test basic node-git functionality
**/
-suite.addTests({
- "Should correctly execute basic test":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly execute basic test":function(assert) {
var commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a';
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
var blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce';
@@ -64,13 +68,13 @@ suite.addTests({
repo.commits(function(err, commits) {
assert.equal(10, commits.length);
- finished();
+ assert.done();
});
})
});
},
- "Should correctly test objects":function(assert, finished) {
+ "Should correctly test objects":function(assert) {
var commit_sha = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a';
var tree_sha = 'cd7422af5a2e0fff3e94d6fb1a8fff03b2841881';
var blob_sha = '4232d073306f01cf0b895864e5a5cfad7dd76fce';
@@ -84,7 +88,7 @@ suite.addTests({
assert.equal(7, tree.entries.length);
var blob = rgit.get_object_by_sha1(blob_sha);
assert.ok(blob.content.indexOf('First public release') != -1);
- finished();
+ assert.done();
});
}
});
44 test/test_head.js
View
@@ -1,11 +1,7 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
+var testCase = require('nodeunit').testCase,
fs = require('fs'),
- Repo = require('git').Repo,
- Merge = require('git').Merge;
-
-var suite = exports.suite = new TestSuite("head tests");
+ Repo = require('../lib/git').Repo,
+ Merge = require('../lib/git').Merge;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
@@ -14,36 +10,44 @@ var fixture = function(name, trim) {
/**
Test basic node-git functionality
**/
-suite.addTests({
- "Should correctly fetch master":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly fetch master":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.commit('master', function(err, head) {
assert.equal('ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a', head.id);
- finished();
+ assert.done();
})
});
},
- "Should correctly fetch submaster":function(assert, finished) {
+ "Should correctly fetch submaster":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.commit('test/master', function(err, head) {
assert.equal('2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.id);
- finished();
+ assert.done();
})
});
},
// heads with slashes
- "Should correctly fetch heads with slashes":function(assert, finished) {
+ "Should correctly fetch heads with slashes":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.heads(function(err, heads) {
assert.equal('test/chacon', heads[3].name);
- finished();
+ assert.done();
})
});
},
- "Should correctly test is_head function":function(assert, finished) {
+ "Should correctly test is_head function":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.is_head('master', function(err, result) {
assert.equal(true, result);
@@ -53,28 +57,28 @@ suite.addTests({
repo.is_head('masterblah', function(err, result) {
assert.equal(false, result);
- finished();
+ assert.done();
})
})
})
});
},
- "Should correctly test head count":function(assert, finished) {
+ "Should correctly test head count":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.heads(function(err, heads) {
assert.equal(5, heads.length);
- finished();
+ assert.done();
})
});
},
- "Should correctly include non-pack":function(assert, finished) {
+ "Should correctly include non-pack":function(assert) {
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {
repo.heads(function(err, heads) {
var names = heads.map(function(head) { return head.name; });
assert.ok(names.indexOf('nonpack') != -1)
- finished();
+ assert.done();
})
});
}
38 test/test_index_status.js
View
@@ -1,10 +1,6 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
+var testCase = require('nodeunit').testCase,
fs = require('fs'),
- Repo = require('git').Repo;
-
-var suite = exports.suite = new TestSuite("index status tests");
+ Repo = require('../lib/git').Repo;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
@@ -13,8 +9,16 @@ var fixture = function(name, trim) {
/**
Test basic node-git functionality
**/
-suite.addTests({
- "Should correctly add a file":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly add a file":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.add = function(a, b, c) {
var args = Array.prototype.slice.call(arguments, 0);
@@ -29,12 +33,12 @@ suite.addTests({
repo.add('file1', 'file2', function(err, result) {
assert.ok(!err)
assert.ok(!result)
- finished();
+ assert.done();
})
});
},
- "Should correctly add an array":function(assert, finished) {
+ "Should correctly add an array":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.add = function(a, b, c) {
var args = Array.prototype.slice.call(arguments, 0);
@@ -49,12 +53,12 @@ suite.addTests({
repo.add(['file1', 'file2'], function(err, result) {
assert.ok(!err)
assert.ok(!result)
- finished();
+ assert.done();
})
});
},
- "Should correctly remove a file":function(assert, finished) {
+ "Should correctly remove a file":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.remove = function(a, b, c) {
var args = Array.prototype.slice.call(arguments, 0);
@@ -69,12 +73,12 @@ suite.addTests({
repo.remove('file1', 'file2', function(err, result) {
assert.ok(!err)
assert.ok(!result)
- finished();
+ assert.done();
})
});
},
- "Should correctly remove an array":function(assert, finished) {
+ "Should correctly remove an array":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.remove = function(a, b, c) {
var args = Array.prototype.slice.call(arguments, 0);
@@ -89,12 +93,12 @@ suite.addTests({
repo.remove(['file1', 'file2'], function(err, result) {
assert.ok(!err)
assert.ok(!result)
- finished();
+ assert.done();
})
});
},
- "Should correctly execute status":function(assert, finished) {
+ "Should correctly execute status":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
repo.git.diff_index = function(a, b) {
var args = Array.prototype.slice.call(arguments, 0);
@@ -123,7 +127,7 @@ suite.addTests({
assert.equal('71e930d551c413a123f43e35c632ea6ba3e3705e', stat.sha_repo);
assert.equal('100644', stat.mode_repo);
assert.equal('M', stat.type);
- finished();
+ assert.done();
});
});
}
24 test/test_merge.js
View
@@ -1,11 +1,7 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
+var testCase = require('nodeunit').testCase,
fs = require('fs'),
- Repo = require('git').Repo,
- Merge = require('git').Merge;
-
-var suite = exports.suite = new TestSuite("merge tests");
+ Repo = require('../lib/git').Repo,
+ Merge = require('../lib/git').Merge;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
@@ -14,15 +10,23 @@ var fixture = function(name, trim) {
/**
Test basic node-git functionality
**/
-suite.addTests({
- "Should correctly create merge from string":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly create merge from string":function(assert) {
new Repo("./test/grit", {is_bare:true}, function(err, repo) {
var merge_text = fixture("merge_result");
var merge = new Merge(merge_text);
assert.equal(3, merge.sections);
assert.equal(1, merge.conflicts);
- finished();
+ assert.done();
});
}
});
24 test/test_raw.js
View
@@ -1,11 +1,7 @@
-
-var TestSuite = require('async_testing').TestSuite,
- sys = require('sys'),
+var testCase = require('nodeunit').testCase,
fs = require('fs'),
- Repo = require('git').Repo,
- Merge = require('git').Merge;
-
-var suite = exports.suite = new TestSuite("raw tests");
+ Repo = require('../lib/git').Repo,
+ Merge = require('../lib/git').Merge;
var fixture = function(name, trim) {
return trim ? fs.readFileSync("./test/fixtures/" + name, 'ascii').trim() : fs.readFileSync("./test/fixtures/" + name, 'ascii');
@@ -14,14 +10,22 @@ var fixture = function(name, trim) {
/**
Test basic node-git functionality
**/
-suite.addTests({
- "Should correctly parse the raw object":function(assert, finished) {
+module.exports = testCase({
+ setUp: function(callback) {
+ callback();
+ },
+
+ tearDown: function(callback) {
+ callback();
+ },
+
+ "Should correctly parse the raw object":function(assert) {
var tag_sha = 'f0055fda16c18fd8b27986dbf038c735b82198d7';
new Repo("./test/dot_git", {is_bare:true}, function(err, repo) {