Skip to content

Commit 8fcb91f

Browse files
committed
Added vendor back into gitignore, added lots of new unittests, removed img dir
1 parent 0b468b9 commit 8fcb91f

11 files changed

Lines changed: 267 additions & 71 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.lock-wscript
22
build/
3+
vendor/

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ clean:
3535
@@rm -rf $(BASE)/vendor/libgit2/build
3636

3737
unittest:
38-
$(NODE_JS) $(BASE)/test/index.js test
38+
@@$(NODE_JS) $(BASE)/test/index.js test
3939

4040
lint:
41-
$(NODE_JS) $(BASE)/util/hint-check.js
41+
@@$(NODE_JS) $(BASE)/util/hint-check.js

src/oid.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ void Oid::Initialize(Handle<Object> target) {
2525
NODE_SET_PROTOTYPE_METHOD(constructor_template, "mkstr", Mkstr);
2626
NODE_SET_PROTOTYPE_METHOD(constructor_template, "mkraw", Mkraw);
2727
NODE_SET_PROTOTYPE_METHOD(constructor_template, "fmt", Fmt);
28+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "pathFmt", PathFmt);
29+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "allocFmt", AllocFmt);
2830
NODE_SET_PROTOTYPE_METHOD(constructor_template, "toString", ToString);
31+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "cpy", Cpy);
32+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "cmp", Cmp);
2933

3034
target->Set(String::NewSymbol("Oid"), constructor_template->GetFunction());
3135
}
@@ -47,7 +51,7 @@ void Oid::Mkraw(const unsigned char* raw) {
4751
}
4852

4953
char* Oid::Fmt(char* buffer) {
50-
git_oid_fmt(*&buffer, &this->oid);
54+
git_oid_fmt(buffer, &this->oid);
5155
}
5256

5357
void Oid::PathFmt(char* str) {
@@ -113,7 +117,7 @@ Handle<Value> Oid::Fmt(const Arguments& args) {
113117

114118
HandleScope scope;
115119

116-
char buffer[40];
120+
char buffer[32];
117121
oid->Fmt(buffer);
118122
return String::New(buffer);
119123
}

test/index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require.paths.unshift( '../vendor' );
55
try {
66
var reporter = require( '../vendor/nodeunit' ).reporters.default;
77
}
8-
catch(e) {
8+
catch( e ) {
99
var sys = require( 'sys' );
1010
sys.puts( 'Cannot find nodeunit module.' );
1111
sys.puts( 'You can download submodules for this project by doing:' );
@@ -34,16 +34,34 @@ process.chdir( './test' );
3434
reporter.run(
3535
[
3636
// Raw API
37-
'raw-repo.js',
38-
'raw-oid.js',
37+
'raw-blob.js',
3938
'raw-commit.js',
4039
'raw-error.js',
40+
'raw-obj.js',
41+
'raw-oid.js',
4142
'raw-ref.js',
43+
'raw-repo.js',
44+
'raw-revwalk.js',
45+
// Revwalk
46+
// Sig
47+
// Tree
48+
// Tree Entry
49+
// Util
4250

4351
// TODO:
4452
//'raw-revwalk.js',
4553

4654
// Convenience API
4755
'convenience-repo.js'
56+
// Blob
57+
// Commit
58+
// Error
59+
// Obj
60+
// Oid
61+
// Ref
62+
// RevWalk
63+
// Sig
64+
// Tree
65+
// TreeEntry
4866
]
4967
);

test/raw-blob.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var git = require( '../' ).raw,
2+
rimraf = require( '../vendor/rimraf' );
3+
4+
var testRepo = new git.Repo();
5+
6+
// Helper functions
7+
var helper = {
8+
// Test if obj is a true function
9+
testFunction: function( test, obj, label ) {
10+
// The object reports itself as a function
11+
test( typeof obj, 'function', label +' reports as a function.' );
12+
// This ensures the repo is actually a derivative of the Function [[Class]]
13+
test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' );
14+
},
15+
// Test code and handle exception thrown
16+
testException: function( test, fun, label ) {
17+
try {
18+
fun();
19+
test( false, label );
20+
}
21+
catch (ex) {
22+
test( true, label );
23+
}
24+
}
25+
};
26+
27+
// Blob
28+
exports.constructor = function( test ){
29+
test.expect( 3 );
30+
31+
// Test for function
32+
helper.testFunction( test.equals, git.Blob, 'Blob' );
33+
34+
// Ensure we get an instance of Blob
35+
test.ok( new git.Blob( testRepo ) instanceof git.Blob, 'Invocation returns an instance of Blob' );
36+
37+
test.done();
38+
};
39+
40+
// Blob::Lookup
41+
exports.lookup = function( test ) {
42+
var testOid = new git.Oid(),
43+
testBlob = new git.Blob( testRepo );
44+
45+
test.expect( 3 );
46+
47+
// Test for function
48+
helper.testFunction( test.equals, testBlob.lookup, 'Blob::Lookup' );
49+
50+
// Test repo argument existence
51+
helper.testException( test.ok, function() {
52+
testBlob.lookup();
53+
}, 'Throw an exception if no repo Object' );
54+
55+
// Test that both arguments result correctly
56+
//helper.testException( test.ifError, function() {
57+
// testOid.mkstr( "somestr" );
58+
//}, 'No exception is thrown with proper arguments' );
59+
60+
// Test invalid hex id string
61+
//test.equals( -2, testOid.mkstr( '1392DLFJIOS' ), 'Invalid hex id String' );
62+
63+
// Test valid hex id string
64+
//test.equals( 0, testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' ), 'Valid hex id String' );
65+
66+
test.done();
67+
};

test/raw-commit.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ exports.lookup = function( test ) {
7373
}, 'No exception is thrown with proper arguments' );
7474

7575
testRepo.open( path.resolve( '../.git' ), function( err ) {
76-
console.log( new git.Error().strError( err ) );
7776
// Test invalid commit
7877
testOid.mkstr( '100644' );
7978
testCommit.lookup( testRepo, testOid, function( err ) {

test/raw-obj.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var git = require( '../' ).raw,
2+
rimraf = require( '../vendor/rimraf' );
3+
4+
// Helper functions
5+
var helper = {
6+
// Test if obj is a true function
7+
testFunction: function( test, obj, label ) {
8+
// The object reports itself as a function
9+
test( typeof obj, 'function', label +' reports as a function.' );
10+
// This ensures the repo is actually a derivative of the Function [[Class]]
11+
test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' );
12+
},
13+
// Test code and handle exception thrown
14+
testException: function( test, fun, label ) {
15+
try {
16+
fun();
17+
test( false, label );
18+
}
19+
catch (ex) {
20+
test( true, label );
21+
}
22+
}
23+
};
24+
25+
var repo = new git.Repo();
26+
27+
// Obj
28+
exports.constructor = function( test ){
29+
test.expect( 3 );
30+
31+
// Test for function
32+
helper.testFunction( test.equals, git.Object, 'GitObject' );
33+
34+
// Ensure we get an instance of Obj
35+
test.ok( new git.Object() instanceof git.Object, 'Invocation returns an instance of GitObject' );
36+
37+
test.done();
38+
};

test/raw-oid.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,47 @@ exports.mkstr = function( test ) {
6262

6363
test.done();
6464
};
65+
66+
// Oid::Fmt
67+
exports.fmt = function( test ) {
68+
var testOid = new git.Oid();
69+
70+
test.expect( 4 );
71+
72+
// Test for function
73+
helper.testFunction( test.equals, testOid.fmt, 'Oid::Fmt' );
74+
75+
// Test invalid hex id string
76+
testOid.mkstr( 'NNNNN' );
77+
test.equals( 38333, testOid.fmt().substring(0, 5).toUpperCase(), 'Invalid hex id String' );
78+
79+
// Test valid hex id string
80+
testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' );
81+
82+
// Slight hackery to get this to work... should investigate oid fmt
83+
test.equals( '1810DFF58D8A660512D4832E740F692884338CCD', testOid.fmt().substring(0, 40).toUpperCase(), 'Valid hex id String' );
84+
85+
test.done();
86+
};
87+
88+
// Oid::Fmt
89+
exports.toString = function( test ) {
90+
var testOid = new git.Oid();
91+
92+
test.expect( 4 );
93+
94+
// Test for function
95+
helper.testFunction( test.equals, testOid.toString, 'Oid::ToString' );
96+
97+
// Test invalid hex id string
98+
testOid.mkstr( 'NNNNN' );
99+
test.equals( 38333, testOid.toString( 5 ), 'Invalid hex id String' );
100+
101+
// Test valid hex id string
102+
testOid.mkstr( '1810DFF58D8A660512D4832E740F692884338CCD' );
103+
104+
// Slight hackery to get this to work... should investigate oid fmt
105+
test.equals( '1810DFF58D8A660512D4832E740F692884338CCD', testOid.toString( 40 ).toUpperCase(), 'Valid hex id String' );
106+
107+
test.done();
108+
};

test/raw-ref.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
var git = require( '../' ).raw,
2+
rimraf = require( '../vendor/rimraf' );
3+
4+
// Helper functions
5+
var helper = {
6+
// Test if obj is a true function
7+
testFunction: function( test, obj, label ) {
8+
// The object reports itself as a function
9+
test( typeof obj, 'function', label +' reports as a function.' );
10+
// This ensures the repo is actually a derivative of the Function [[Class]]
11+
test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' );
12+
},
13+
// Test code and handle exception thrown
14+
testException: function( test, fun, label ) {
15+
try {
16+
fun();
17+
test( false, label );
18+
}
19+
catch (ex) {
20+
test( true, label );
21+
}
22+
}
23+
};
24+
25+
// Ref
26+
exports.constructor = function( test ){
27+
test.expect( 3 );
28+
29+
// Test for function
30+
helper.testFunction( test.equals, git.Ref, 'Ref' );
31+
32+
// Ensure we get an instance of Ref
33+
test.ok( new git.Ref() instanceof git.Ref, 'Invocation returns an instance of Ref' );
34+
35+
test.done();
36+
};
37+
38+
// Ref::Lookup
39+
exports.lookup = function( test ) {
40+
var testRepo = new git.Repo(),
41+
master = new git.Ref();
42+
43+
test.expect( 5 );
44+
45+
// Test for function
46+
helper.testFunction( test.equals, master.lookup, 'Ref::Lookup' );
47+
48+
// Test repo argument existence
49+
helper.testException( test.ok, function() {
50+
master.lookup();
51+
}, 'Throw an exception if no repo' );
52+
53+
// Test name argument existence
54+
helper.testException( test.ok, function() {
55+
master.lookup( testRepo );
56+
}, 'Throw an exception if no name' );
57+
58+
// Test callback argument existence
59+
helper.testException( test.ok, function() {
60+
master.lookup( testRepo, 'refs/heads/master' );
61+
}, 'Throw an exception if no callback' );
62+
63+
// Cleanup, remove test repo directory - if it exists
64+
rimraf( './test.git', function() {
65+
// // Create bare repo and test for creation
66+
// testRepo.init( './test.git', true, function( err, path, is_bare ) {
67+
// test.equals( 0, err, 'Successfully created bare repository' );
68+
// // Verify repo exists
69+
// testRepo.open( './test.git', function(err, path) {
70+
// test.equals( 0, err, 'Valid repository created' );
71+
// test.equals( true, is_bare, 'Returns valid is_bare value' );
72+
73+
// testRepo.free();
74+
75+
// // Cleanup, remove test repo directory
76+
// rimraf( './test.git', function() {
77+
test.done();
78+
// });
79+
// });
80+
// });
81+
});
82+
};

0 commit comments

Comments
 (0)