Add a test for revwalk
This commit is contained in:
@@ -67,6 +67,7 @@ static int load(ErlNifEnv *env, void **priv, ERL_NIF_TERM load_info)
|
|||||||
atoms.toposort = enif_make_atom(env, "sort_topo");
|
atoms.toposort = enif_make_atom(env, "sort_topo");
|
||||||
atoms.timesort = enif_make_atom(env, "sort_time");
|
atoms.timesort = enif_make_atom(env, "sort_time");
|
||||||
atoms.reversesort = enif_make_atom(env, "sort_reverse");
|
atoms.reversesort = enif_make_atom(env, "sort_reverse");
|
||||||
|
atoms.iterover = enif_make_atom(env, "iterover");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ typedef struct {
|
|||||||
ERL_NIF_TERM toposort;
|
ERL_NIF_TERM toposort;
|
||||||
ERL_NIF_TERM timesort;
|
ERL_NIF_TERM timesort;
|
||||||
ERL_NIF_TERM reversesort;
|
ERL_NIF_TERM reversesort;
|
||||||
|
ERL_NIF_TERM iterover;
|
||||||
} geef_atoms;
|
} geef_atoms;
|
||||||
|
|
||||||
extern geef_atoms atoms;
|
extern geef_atoms atoms;
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ geef_revwalk_push(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
|||||||
ERL_NIF_TERM
|
ERL_NIF_TERM
|
||||||
geef_revwalk_next(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
geef_revwalk_next(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||||
{
|
{
|
||||||
|
int error;
|
||||||
ErlNifBinary bin;
|
ErlNifBinary bin;
|
||||||
geef_revwalk *walk;
|
geef_revwalk *walk;
|
||||||
|
|
||||||
@@ -71,8 +72,12 @@ geef_revwalk_next(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
|||||||
if (!enif_alloc_binary(GIT_OID_RAWSZ, &bin))
|
if (!enif_alloc_binary(GIT_OID_RAWSZ, &bin))
|
||||||
return atoms.error;
|
return atoms.error;
|
||||||
|
|
||||||
if (git_revwalk_next((git_oid *)bin.data, walk->walk) < 0)
|
if ((error = git_revwalk_next((git_oid *)bin.data, walk->walk)) < 0) {
|
||||||
|
if (error == GIT_ITEROVER)
|
||||||
|
return enif_make_tuple2(env, atoms.error, atoms.iterover);
|
||||||
|
|
||||||
return geef_error(env);
|
return geef_error(env);
|
||||||
|
}
|
||||||
|
|
||||||
return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &bin));
|
return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &bin));
|
||||||
}
|
}
|
||||||
|
|||||||
34
test/revwalk_test.erl
Normal file
34
test/revwalk_test.erl
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
-module(revwalk_test).
|
||||||
|
-compile([export_all]).
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
|
repo_test_() ->
|
||||||
|
case os:getenv("GEEF_RESOURCES") of
|
||||||
|
false ->
|
||||||
|
[];
|
||||||
|
_ ->
|
||||||
|
{foreach, fun start/0, fun stop/1, [fun amount_test/1]}
|
||||||
|
end.
|
||||||
|
|
||||||
|
start() ->
|
||||||
|
BasePath = os:getenv("GEEF_RESOURCES"),
|
||||||
|
Path = filename:join([BasePath, "testrepo.git"]),
|
||||||
|
{ok, Repo} = geef_repo:open(Path),
|
||||||
|
Repo.
|
||||||
|
|
||||||
|
count_walk(Walk, Acc) ->
|
||||||
|
case geef_revwalk:next(Walk) of
|
||||||
|
{ok, _} ->
|
||||||
|
count_walk(Walk, Acc + 1);
|
||||||
|
{error, iterover} ->
|
||||||
|
Acc
|
||||||
|
end.
|
||||||
|
|
||||||
|
amount_test(Repo) ->
|
||||||
|
{ok, Walk} = geef_repo:revwalk(Repo),
|
||||||
|
Id = geef_oid:parse("a4a7dce85cf63874e984719f4fdd239f5145052f"),
|
||||||
|
ok = geef_revwalk:push(Walk, Id),
|
||||||
|
[?_assertEqual(6, count_walk(Walk, 0))].
|
||||||
|
|
||||||
|
stop(_Repo) ->
|
||||||
|
ok.
|
||||||
Reference in New Issue
Block a user