Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-09-30 09:19:14 +0400
committerCarlos Martín Nieto <cmn@dwim.me>2014-09-30 09:24:28 +0400
commit3b6534b80768e8751b398cd3aeffb888e374c8d4 (patch)
treec373d53f835a8f868477cd03721a674123ec1b89 /tests/describe
parent1f501a086b4a9103f5ef5540c82c57d8559f0aff (diff)
describe: split into gather and format steps
Instead of printing out to the buffer inside the information-gathering phase, write the data to a intermediate result structure. This allows us to split the options into gathering options and formatting options, simplifying the gathering code.
Diffstat (limited to 'tests/describe')
-rw-r--r--tests/describe/describe.c9
-rw-r--r--tests/describe/describe_helpers.c8
-rw-r--r--tests/describe/describe_helpers.h1
-rw-r--r--tests/describe/t6120.c59
4 files changed, 46 insertions, 31 deletions
diff --git a/tests/describe/describe.c b/tests/describe/describe.c
index a7f3c84df..e2dda96cd 100644
--- a/tests/describe/describe.c
+++ b/tests/describe/describe.c
@@ -5,14 +5,15 @@ void test_describe_describe__can_describe_against_a_bare_repo(void)
{
git_repository *repo;
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
+ git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- assert_describe("hard_tag", "HEAD", repo, &opts, false);
+ assert_describe("hard_tag", "HEAD", repo, &opts, &fmt_opts, false);
opts.show_commit_oid_as_fallback = 1;
- assert_describe("be3563a", "HEAD^", repo, &opts, true);
+ assert_describe("be3563a", "HEAD^", repo, &opts, &fmt_opts, true);
git_repository_free(repo);
}
@@ -33,14 +34,16 @@ void test_describe_describe__cannot_describe_against_a_repo_with_no_ref(void)
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
git_buf buf = GIT_BUF_INIT;
git_object *object;
+ git_describe_result *result = NULL;
repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_revparse_single(&object, repo, "HEAD"));
cl_git_pass(git_reference_foreach(repo, delete_cb, NULL));
- cl_git_fail(git_describe_commit(&buf, object, &opts));
+ cl_git_fail(git_describe_commit(&result, object, &opts));
+ git_describe_result_free(result);
git_object_free(object);
git_buf_free(&buf);
cl_git_sandbox_cleanup();
diff --git a/tests/describe/describe_helpers.c b/tests/describe/describe_helpers.c
index 7235d320f..d975ddf4b 100644
--- a/tests/describe/describe_helpers.c
+++ b/tests/describe/describe_helpers.c
@@ -5,20 +5,24 @@ void assert_describe(
const char *revparse_spec,
git_repository *repo,
git_describe_opts *opts,
+ git_describe_format_options *fmt_opts,
bool is_prefix_match)
{
git_object *object;
- git_buf label;
+ git_buf label = GIT_BUF_INIT;
+ git_describe_result *result;
cl_git_pass(git_revparse_single(&object, repo, revparse_spec));
- cl_git_pass(git_describe_commit(&label, object, opts));
+ cl_git_pass(git_describe_commit(&result, object, opts));
+ cl_git_pass(git_describe_format(&label, result, fmt_opts));
if (is_prefix_match)
cl_assert_equal_i(0, git__prefixcmp(git_buf_cstr(&label), expected_output));
else
cl_assert_equal_s(expected_output, label);
+ git_describe_result_free(result);
git_object_free(object);
git_buf_free(&label);
}
diff --git a/tests/describe/describe_helpers.h b/tests/describe/describe_helpers.h
index 0f107f5a7..a666b46cf 100644
--- a/tests/describe/describe_helpers.h
+++ b/tests/describe/describe_helpers.h
@@ -6,4 +6,5 @@ extern void assert_describe(
const char *revparse_spec,
git_repository *repo,
git_describe_opts *opts,
+ git_describe_format_options *fmt_opts,
bool is_prefix_match);
diff --git a/tests/describe/t6120.c b/tests/describe/t6120.c
index d589e82a6..39489f3c5 100644
--- a/tests/describe/t6120.c
+++ b/tests/describe/t6120.c
@@ -19,56 +19,62 @@ void test_describe_t6120__cleanup(void)
void test_describe_t6120__default(void)
{
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
-
- assert_describe("A-", "HEAD", repo, &opts, true);
- assert_describe("A-", "HEAD^", repo, &opts, true);
- assert_describe("R-", "HEAD^^", repo, &opts, true);
- assert_describe("A-", "HEAD^^2", repo, &opts, true);
- assert_describe("B", "HEAD^^2^", repo, &opts, false);
- assert_describe("R-", "HEAD^^^", repo, &opts, true);
+ git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
+
+ assert_describe("A-", "HEAD", repo, &opts, &fmt_opts, true);
+ assert_describe("A-", "HEAD^", repo, &opts, &fmt_opts, true);
+ assert_describe("R-", "HEAD^^", repo, &opts, &fmt_opts, true);
+ assert_describe("A-", "HEAD^^2", repo, &opts, &fmt_opts, true);
+ assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts, false);
+ assert_describe("R-", "HEAD^^^", repo, &opts, &fmt_opts, true);
}
void test_describe_t6120__tags(void)
{
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
+ git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS;
- assert_describe("c-", "HEAD", repo, &opts, true);
- assert_describe("c-", "HEAD^", repo, &opts, true);
- assert_describe("e-", "HEAD^^", repo, &opts, true);
- assert_describe("c-", "HEAD^^2", repo, &opts, true);
- assert_describe("B", "HEAD^^2^", repo, &opts, false);
- assert_describe("e", "HEAD^^^", repo, &opts, false);
+ assert_describe("c-", "HEAD", repo, &opts, &fmt_opts, true);
+ assert_describe("c-", "HEAD^", repo, &opts, &fmt_opts, true);
+ assert_describe("e-", "HEAD^^", repo, &opts, &fmt_opts, true);
+ assert_describe("c-", "HEAD^^2", repo, &opts, &fmt_opts, true);
+ assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts, false);
+ assert_describe("e", "HEAD^^^", repo, &opts, &fmt_opts, false);
}
void test_describe_t6120__all(void)
{
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
+ git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_ALL;
- assert_describe("heads/master", "HEAD", repo, &opts, false);
- assert_describe("tags/c-", "HEAD^", repo, &opts, true);
- assert_describe("tags/e", "HEAD^^^", repo, &opts, false);
+ assert_describe("heads/master", "HEAD", repo, &opts, &fmt_opts, false);
+ assert_describe("tags/c-", "HEAD^", repo, &opts, &fmt_opts, true);
+ assert_describe("tags/e", "HEAD^^^", repo, &opts, &fmt_opts, false);
}
void test_describe_t6120__longformat(void)
{
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
- opts.always_use_long_format = 1;
+ git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
+
+ fmt_opts.always_use_long_format = 1;
- assert_describe("B-0-", "HEAD^^2^", repo, &opts, true);
- assert_describe("A-3-", "HEAD^^2", repo, &opts, true);
+ assert_describe("B-0-", "HEAD^^2^", repo, &opts, &fmt_opts, true);
+ assert_describe("A-3-", "HEAD^^2", repo, &opts, &fmt_opts, true);
}
void test_describe_t6120__firstparent(void)
{
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
+ git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS;
- assert_describe("c-7-", "HEAD", repo, &opts, true);
+ assert_describe("c-7-", "HEAD", repo, &opts, &fmt_opts, true);
opts.only_follow_first_parent = 1;
- assert_describe("e-3-", "HEAD", repo, &opts, true);
+ assert_describe("e-3-", "HEAD", repo, &opts, &fmt_opts, true);
}
static void commit_and_tag(
@@ -100,6 +106,7 @@ static void commit_and_tag(
void test_describe_t6120__pattern(void)
{
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
+ git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
git_oid tag_id;
git_object *head;
git_signature *tagger;
@@ -121,15 +128,15 @@ void test_describe_t6120__pattern(void)
/* Exercize */
opts.pattern = "test-*";
- assert_describe("test-annotated-", "HEAD", repo, &opts, true);
+ assert_describe("test-annotated-", "HEAD", repo, &opts, &fmt_opts, true);
opts.describe_strategy = GIT_DESCRIBE_TAGS;
opts.pattern = "test1-*";
- assert_describe("test1-lightweight-", "HEAD", repo, &opts, true);
+ assert_describe("test1-lightweight-", "HEAD", repo, &opts, &fmt_opts, true);
opts.pattern = "test2-*";
- assert_describe("test2-lightweight-", "HEAD", repo, &opts, true);
+ assert_describe("test2-lightweight-", "HEAD", repo, &opts, &fmt_opts, true);
- opts.always_use_long_format = 1;
- assert_describe("test2-lightweight-", "HEAD^", repo, &opts, true);
+ fmt_opts.always_use_long_format = 1;
+ assert_describe("test2-lightweight-", "HEAD^", repo, &opts, &fmt_opts, true);
}