Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Commit

Permalink
Changed tests to use nodeunit instead
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed May 25, 2011
1 parent 16010d3 commit 45fa80e
Show file tree
Hide file tree
Showing 28 changed files with 629 additions and 597 deletions.
2 changes: 1 addition & 1 deletion lib/git/blob.js
Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions lib/git/commit.js
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -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"
Expand All @@ -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 changes: 18 additions & 14 deletions test/test_actor.js
@@ -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();
}
});

Expand Down
68 changes: 0 additions & 68 deletions test/test_all.js

This file was deleted.

28 changes: 16 additions & 12 deletions test/test_blame.js
@@ -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) {
Expand All @@ -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) {
Expand All @@ -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();
})
});
}
Expand Down
34 changes: 19 additions & 15 deletions test/test_blame_tree.js
@@ -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();
});
}
});
Expand Down

0 comments on commit 45fa80e

Please sign in to comment.