Hash :
1e30f33a
Author :
tokyovania
Date :
2022-07-05T15:23:26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
#include <stdio.h>
#include <string.h>
#include <erl_nif.h>
#include <git2.h>
#include "mstr.h"
ERL_NIF_TERM branches_nif (ErlNifEnv *env, int argc,
const ERL_NIF_TERM argv[]);
ERL_NIF_TERM content_nif (ErlNifEnv *env, int argc,
const ERL_NIF_TERM argv[]);
ERL_NIF_TERM create_nif (ErlNifEnv *env, int argc,
const ERL_NIF_TERM argv[]);
ERL_NIF_TERM diff_nif (ErlNifEnv *env, int argc,
const ERL_NIF_TERM argv[]);
ERL_NIF_TERM files_nif (ErlNifEnv *env, int argc,
const ERL_NIF_TERM argv[]);
ERL_NIF_TERM log_nif (ErlNifEnv *env, int argc,
const ERL_NIF_TERM argv[]);
ERL_NIF_TERM tags_nif (ErlNifEnv *env, int argc,
const ERL_NIF_TERM argv[]);
int load (ErlNifEnv *env, void **a, ERL_NIF_TERM b);
ERL_NIF_TERM
test (const char *test_name,
ERL_NIF_TERM (*fun) (ErlNifEnv *env,
int argc,
const ERL_NIF_TERM argv[]),
const ERL_NIF_TERM argv[])
{
int argc = 0;
int i = 0;
ERL_NIF_TERM res = 0;
while (argv[argc])
argc++;
res = fun(NULL, argc, argv);
printf("%s(", test_name);
if (argv[i]) {
printf("%s", argv[i++]);
while (argv[i])
printf(", %s", argv[i++]);
}
printf(") => %s\n", res);
return res;
}
int main (int argc, char **argv)
{
char *repo = "priv/git/kmx.io/kmxgit.git";
char *content_sha1 = "7ad943b223f99c79746386c2b57d32ba6e889e2c";
char *diff_from = "v0.2.0";
char *diff_to = "v0.3.0";
char *tree = "v0.2";
char *revspec_single = "^edf1fbc96f1efb9b9acafa998b5b4c4a4361bf34";
char *dir = "lib/kmxgit";
int i = 0;
libmstr_init();
load(NULL, NULL, NULL);
if (argc < 2 || !strcmp(argv[1], "branches")) {
test("branches", branches_nif, (const char *[]) {
repo, NULL});
}
if (argc < 2 || !strcmp(argv[1], "content")) {
test("content", content_nif, (const char *[]) {
repo, content_sha1, NULL});
}
if (argc < 2 || !strcmp(argv[1], "create")) {
test("create", create_nif, (const char *[]) {
"test_git_nif_create", NULL});
test("create_error", create_nif, (const char *[]) {
"..", NULL});
}
if (argc < 2 || !strcmp(argv[1], "diff")) {
test("diff", diff_nif, (const char *[]) {
repo, diff_from, diff_to, NULL});
}
if (argc < 2 || !strcmp(argv[1], "files")) {
test("files", files_nif, (const char *[]) {
repo, tree, dir, NULL});
test("files_blob", files_nif, (const char *[]) {
repo, tree, "README.md", NULL});
}
if (argc < 2 || !strcmp(argv[1], "log")) {
test("log", log_nif, (const char *[]) {
repo, tree, ".", "0", "100", NULL});
test("log_revspec_single", log_nif, (const char *[]) {
repo, revspec_single, ".", "0", "100", NULL});
}
if (argc < 2 || !strcmp(argv[1], "tags")) {
test("tags", tags_nif, (const char *[]) {
repo, NULL});
}
if (argc < 2 || !strcmp(argv[1], "loop")) {
for (i = 0; i < 2; i++) {
test("branches_loop", branches_nif, (const char *[]) {
"priv/git/kmx.io/git-auth.git", NULL});
test("files_loop", files_nif, (const char *[]) {
"priv/git/kmx.io/git-auth.git", "master","", NULL});
test("content_loop", content_nif, (const char *[]) {
"priv/git/kmx.io/git-auth.git",
"47232bf062f109330b6ad8cacdc329285d9d2ce3", NULL});
}
}
git_libgit2_shutdown();
libmstr_shutdown();
fflush(stdout);
return 0;
}