Permalink
Browse files

Updated tests

Tests for all classes.
Fixes #10
Fixes #15
Fixes #16
  • Loading branch information...
1 parent 3ec27ca commit dd1d1e9b5bce0b90a311fff30c596bcfe1178745 @sa1 sa1 committed Sep 7, 2013
Showing with 114 additions and 33 deletions.
  1. +114 −33 t/winxed/001_load.t
View
@@ -2,15 +2,18 @@
$load "rosella/test.pbc";
$load "./src/git2.pbc";
+$load "./src/parrotgit.pbc";
+$load "./src/Git2/Config.pbc";
$load "./src/Git2/Common.pbc";
+$load "./src/Git2/Commit.pbc";
$load "./src/Git2/Oid.pbc";
$load "./src/Git2/Cache.pbc";
$load "./src/Git2/RefCache.pbc";
$load "./src/Git2/Repository.pbc";
+$load "./src/Git2/RevWalk.pbc";
$load "./src/Git2/Odb.pbc";
-$load "./src/Git2/Cache.pbc";
-$load "./src/Git2/RefCache.pbc";
$load "./src/Git2/AttrCache.pbc";
+$load "./src/Git2/Blob.pbc";
$load "dumper.pbc";
$include_const 'datatypes.pasm';
@@ -21,10 +24,14 @@ namespace Git2 {
class Index;
class Branch;
class Cache;
+ class Config;
+ class Commit;
+ class Oid;
+ class RevWalk;
+ class Blob;
}
class Test_git2_repository_open {
-
function test_new_branch() {
var branch = new Git2.Branch;
self.assert.instance_of(branch, class Git2.Branch);
@@ -50,52 +57,55 @@ class Test_git2_repository_open {
var repo = new Git2.Repository();
- var rc = git_repository_open(repo.ptr, cstring(".git"));
-
- self.assert.equal(rc,0);
+ // TODO: get proper error return value here. Currently error printing is deferred to the C wrapper
+ repo.init_repo(".");
}
function repository_index() {
using Git2.Repository;
using Git2.Index;
- using Git2.Raw.git_repository_open;
- using Git2.Raw.git_repository_index;
- using Git2.Raw.git_repository_free;
- using Git2.Raw.git_index_open_inrepo;
- using Git2.Raw.git_repository_is_bare;
- using Git2.Raw.git_repository_database;
- using Git2.Raw.git_repository_is_empty;
using cstring;
- var repo = new Git2.Repository();
+ var repo = new Git2.Repository();
var git_index = new Git2.Index();
- self.assert.instance_of(git_index, class Git2.Index);
var rc1 = -1;
var rc2 = -1;
+ var bool = -1;
// TODO: make slashes portable
- rc1 = git_repository_open(repo.ptr, cstring("./.git"));
- self.assert.equal(rc1,0);
+ repo.init_repo(".");
- var gindex = git_index.ptr;
- var grepo = repo.ptr;
+ git_index.set_index(repo.ptr);
- // rc2 = git_repository_index(gindex)
- rc2 = git_repository_index(gindex, grepo);
- //self.assert.equal(rc2,0);
+ int ecount = git_index.get_entrycount();
+ self.assert.not_null(ecount);
- var bool = git_repository_is_bare(grepo);
- self.assert.equal(bool,0);
+ git_index.free();
- var empty = git_repository_is_empty(grepo);
- self.assert.equal(empty,0);
+ repo.free();
+ }
- //var odb = git_repository_database(repo.ptr);
- //self.assert.defined(odb);
+ function show_branch(){
+ using Git2.Git.repo_head;
+ using Git2.Raw.git_reference_name;
+ using Git2.Git.branchname;
+ using cstring;
+ var repo = new Git2.Repository();
- // coredumps inside libgit2
- // git_repository_free(repo.ptr);
+ repo.init_repo(".");
+ string str = string(cstring("x"));
+ print(str);
+ repo.free();
+ }
+
+ function config(){
+ using Git2.Config;
+
+ var config = new Git2.Config;
+ config.get_config("./config");
+ int j = config.get_int32("help.autocorrect");
+ self.assert.equal(j, 0);
}
function git_index() {
@@ -104,16 +114,87 @@ class Test_git2_repository_open {
}
function git_oid() {
+ using Git2.Oid;
+
var git_oid = new Git2.Oid();
using Git2.Raw.git_oid_fromstr;
self.assert.instance_of(git_oid, class Git2.Oid);
- var hex = cstring("599955586da1c3ad514f3e65f1081d2012ec862d");
- var rc1 = -1;
- rc1 = git_oid_fromstr(git_oid.ptr, hex);
+ var hex = "599955586da1c3ad514f3e65f1081d2012ec862d";
+ git_oid.oid_from_str(hex);
self.assert.defined(git_oid);
}
+ function git_commit(){
+ using Git2.Commit;
+ using Git2.Repository;
+ using Git2.Oid;
+
+ var repo = new Git2.Repository();
+ repo.init_repo(".");
+
+ var hex = "e1380b1f60babf677921c4a9b5e92acda0b15e18";
+ var git_oid = new Git2.Oid();
+ git_oid.oid_from_str(hex);
+
+ var commit1 = new Git2.Commit();
+ commit1.commit_lookup(repo, git_oid);
+
+ int ctime = commit1.commit_time();
+
+ int parentcount = commit1.parentcount();
+ self.assert.not_null(parentcount);
+
+ repo.free();
+ }
+
+ function rev_walk(){
+ using Git2.RevWalk;
+ using Git2.Repository;
+ using Git2.Oid;
+ using Git2.Commit;
+
+ var repo = new Git2.Repository();
+ repo.init_repo(".");
+
+ var hex = "e1380b1f60babf677921c4a9b5e92acda0b15e18";
+ var git_oid = new Git2.Oid();
+ git_oid.oid_from_str(hex);
+
+ var rev_walk = new RevWalk;
+ rev_walk.init(repo);
+ rev_walk.push(git_oid);
+
+ while(rev_walk.next() == 0){
+ var commit1 = new Git2.Commit();
+ commit1.commit_lookup(repo, rev_walk.oid);
+ int parentcount = commit1.parentcount();
+ self.assert.not_null(parentcount);
+ }
+ rev_walk.free();
+ repo.free();
+ }
+
+ function blob(){
+ using Git2.Repository;
+ using Git2.Oid;
+ using Git2.Blob;
+
+ var repo = new Git2.Repository();
+ repo.init_repo(".");
+
+ var hex = "a556bfd051e6cd09844eda9ccb372f37629f5385";
+ var git_oid = new Git2.Oid();
+ git_oid.oid_from_str(hex);
+
+ var blob = new Blob;
+ blob.lookup(repo, git_oid);
+
+ var size = blob.raw_size();
+ self.assert.not_null(size);
+ repo.free();
+ }
+
}
function main[main]() {
using Rosella.Test.test;

1 comment on commit dd1d1e9

Owner

leto commented on dd1d1e9 Sep 13, 2013

Awesome work! Impressive.

Please sign in to comment.