Commit 5431c46a by Carlos Martín Nieto

describe: use globs in the tests

This makes us be closer to git's tests, and lets us better describe what
we expect from the output.
parent 55f1b6b6
...@@ -9,11 +9,11 @@ void test_describe_describe__can_describe_against_a_bare_repo(void) ...@@ -9,11 +9,11 @@ void test_describe_describe__can_describe_against_a_bare_repo(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
assert_describe("hard_tag", "HEAD", repo, &opts, &fmt_opts, false); assert_describe("hard_tag", "HEAD", repo, &opts, &fmt_opts);
opts.show_commit_oid_as_fallback = 1; opts.show_commit_oid_as_fallback = 1;
assert_describe("be3563a", "HEAD^", repo, &opts, &fmt_opts, true); assert_describe("be3563a*", "HEAD^", repo, &opts, &fmt_opts);
git_repository_free(repo); git_repository_free(repo);
} }
......
...@@ -5,8 +5,7 @@ void assert_describe( ...@@ -5,8 +5,7 @@ void assert_describe(
const char *revparse_spec, const char *revparse_spec,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_opts *opts,
git_describe_format_options *fmt_opts, git_describe_format_options *fmt_opts)
bool is_prefix_match)
{ {
git_object *object; git_object *object;
git_buf label = GIT_BUF_INIT; git_buf label = GIT_BUF_INIT;
...@@ -17,10 +16,7 @@ void assert_describe( ...@@ -17,10 +16,7 @@ void assert_describe(
cl_git_pass(git_describe_commit(&result, object, opts)); cl_git_pass(git_describe_commit(&result, object, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts)); cl_git_pass(git_describe_format(&label, result, fmt_opts));
if (is_prefix_match) cl_git_pass(p_fnmatch(expected_output, git_buf_cstr(&label), 0));
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_describe_result_free(result);
git_object_free(object); git_object_free(object);
...@@ -29,11 +25,9 @@ void assert_describe( ...@@ -29,11 +25,9 @@ void assert_describe(
void assert_describe_workdir( void assert_describe_workdir(
const char *expected_output, const char *expected_output,
const char *expected_suffix,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_opts *opts,
git_describe_format_options *fmt_opts, git_describe_format_options *fmt_opts)
bool is_prefix_match)
{ {
git_buf label = GIT_BUF_INIT; git_buf label = GIT_BUF_INIT;
git_describe_result *result; git_describe_result *result;
...@@ -41,13 +35,7 @@ void assert_describe_workdir( ...@@ -41,13 +35,7 @@ void assert_describe_workdir(
cl_git_pass(git_describe_workdir(&result, repo, opts)); cl_git_pass(git_describe_workdir(&result, repo, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts)); cl_git_pass(git_describe_format(&label, result, fmt_opts));
if (is_prefix_match) cl_git_pass(p_fnmatch(expected_output, git_buf_cstr(&label), 0));
cl_assert_equal_i(0, git__prefixcmp(git_buf_cstr(&label), expected_output));
else
cl_assert_equal_s(expected_output, label);
if (expected_suffix)
cl_assert_equal_i(0, git__suffixcmp(git_buf_cstr(&label), expected_suffix));
git_describe_result_free(result); git_describe_result_free(result);
git_buf_free(&label); git_buf_free(&label);
......
...@@ -6,13 +6,10 @@ extern void assert_describe( ...@@ -6,13 +6,10 @@ extern void assert_describe(
const char *revparse_spec, const char *revparse_spec,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_opts *opts,
git_describe_format_options *fmt_opts, git_describe_format_options *fmt_opts);
bool is_prefix_match);
extern void assert_describe_workdir( extern void assert_describe_workdir(
const char *expected_output, const char *expected_output,
const char *expected_suffix,
git_repository *repo, git_repository *repo,
git_describe_opts *opts, git_describe_opts *opts,
git_describe_format_options *fmt_opts, git_describe_format_options *fmt_opts);
bool is_prefix_match);
...@@ -21,12 +21,12 @@ void test_describe_t6120__default(void) ...@@ -21,12 +21,12 @@ void test_describe_t6120__default(void)
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; 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);
assert_describe("A-", "HEAD^", repo, &opts, &fmt_opts, true); assert_describe("A-*", "HEAD^", repo, &opts, &fmt_opts);
assert_describe("R-", "HEAD^^", repo, &opts, &fmt_opts, true); assert_describe("R-*", "HEAD^^", repo, &opts, &fmt_opts);
assert_describe("A-", "HEAD^^2", repo, &opts, &fmt_opts, true); assert_describe("A-*", "HEAD^^2", repo, &opts, &fmt_opts);
assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts, false); assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts);
assert_describe("R-", "HEAD^^^", repo, &opts, &fmt_opts, true); assert_describe("R-*", "HEAD^^^", repo, &opts, &fmt_opts);
} }
void test_describe_t6120__tags(void) void test_describe_t6120__tags(void)
...@@ -35,12 +35,12 @@ void test_describe_t6120__tags(void) ...@@ -35,12 +35,12 @@ void test_describe_t6120__tags(void)
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS; opts.describe_strategy = GIT_DESCRIBE_TAGS;
assert_describe("c-", "HEAD", repo, &opts, &fmt_opts, true); assert_describe("c-*", "HEAD", repo, &opts, &fmt_opts);
assert_describe("c-", "HEAD^", repo, &opts, &fmt_opts, true); assert_describe("c-*", "HEAD^", repo, &opts, &fmt_opts);
assert_describe("e-", "HEAD^^", repo, &opts, &fmt_opts, true); assert_describe("e-*", "HEAD^^", repo, &opts, &fmt_opts);
assert_describe("c-", "HEAD^^2", repo, &opts, &fmt_opts, true); assert_describe("c-*", "HEAD^^2", repo, &opts, &fmt_opts);
assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts, false); assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts);
assert_describe("e", "HEAD^^^", repo, &opts, &fmt_opts, false); assert_describe("e", "HEAD^^^", repo, &opts, &fmt_opts);
} }
void test_describe_t6120__all(void) void test_describe_t6120__all(void)
...@@ -49,9 +49,9 @@ void test_describe_t6120__all(void) ...@@ -49,9 +49,9 @@ void test_describe_t6120__all(void)
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_ALL; opts.describe_strategy = GIT_DESCRIBE_ALL;
assert_describe("heads/master", "HEAD", repo, &opts, &fmt_opts, false); assert_describe("heads/master", "HEAD", repo, &opts, &fmt_opts);
assert_describe("tags/c-", "HEAD^", repo, &opts, &fmt_opts, true); assert_describe("tags/c-*", "HEAD^", repo, &opts, &fmt_opts);
assert_describe("tags/e", "HEAD^^^", repo, &opts, &fmt_opts, false); assert_describe("tags/e", "HEAD^^^", repo, &opts, &fmt_opts);
} }
void test_describe_t6120__longformat(void) void test_describe_t6120__longformat(void)
...@@ -61,8 +61,8 @@ void test_describe_t6120__longformat(void) ...@@ -61,8 +61,8 @@ void test_describe_t6120__longformat(void)
fmt_opts.always_use_long_format = 1; fmt_opts.always_use_long_format = 1;
assert_describe("B-0-", "HEAD^^2^", repo, &opts, &fmt_opts, true); assert_describe("B-0-*", "HEAD^^2^", repo, &opts, &fmt_opts);
assert_describe("A-3-", "HEAD^^2", repo, &opts, &fmt_opts, true); assert_describe("A-3-*", "HEAD^^2", repo, &opts, &fmt_opts);
} }
void test_describe_t6120__firstparent(void) void test_describe_t6120__firstparent(void)
...@@ -71,10 +71,10 @@ void test_describe_t6120__firstparent(void) ...@@ -71,10 +71,10 @@ void test_describe_t6120__firstparent(void)
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS; opts.describe_strategy = GIT_DESCRIBE_TAGS;
assert_describe("c-7-", "HEAD", repo, &opts, &fmt_opts, true); assert_describe("c-7-*", "HEAD", repo, &opts, &fmt_opts);
opts.only_follow_first_parent = 1; opts.only_follow_first_parent = 1;
assert_describe("e-3-", "HEAD", repo, &opts, &fmt_opts, true); assert_describe("e-3-*", "HEAD", repo, &opts, &fmt_opts);
} }
void test_describe_t6120__workdir(void) void test_describe_t6120__workdir(void)
...@@ -82,13 +82,13 @@ void test_describe_t6120__workdir(void) ...@@ -82,13 +82,13 @@ void test_describe_t6120__workdir(void)
git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
assert_describe_workdir("A-", NULL, repo, &opts, &fmt_opts, true); assert_describe_workdir("A-*[0-9a-f]", repo, &opts, &fmt_opts);
cl_git_mkfile("describe/file", "something different"); cl_git_mkfile("describe/file", "something different");
fmt_opts.dirty_suffix = "-dirty"; fmt_opts.dirty_suffix = "-dirty";
assert_describe_workdir("A-", "-dirty", repo, &opts, &fmt_opts, true); assert_describe_workdir("A-*[0-9a-f]-dirty", repo, &opts, &fmt_opts);
fmt_opts.dirty_suffix = ".mod"; fmt_opts.dirty_suffix = ".mod";
assert_describe_workdir("A-", ".mod", repo, &opts, &fmt_opts, true); assert_describe_workdir("A-*[0-9a-f].mod", repo, &opts, &fmt_opts);
} }
static void commit_and_tag( static void commit_and_tag(
...@@ -142,15 +142,15 @@ void test_describe_t6120__pattern(void) ...@@ -142,15 +142,15 @@ void test_describe_t6120__pattern(void)
/* Exercize */ /* Exercize */
opts.pattern = "test-*"; opts.pattern = "test-*";
assert_describe("test-annotated-", "HEAD", repo, &opts, &fmt_opts, true); assert_describe("test-annotated-*", "HEAD", repo, &opts, &fmt_opts);
opts.describe_strategy = GIT_DESCRIBE_TAGS; opts.describe_strategy = GIT_DESCRIBE_TAGS;
opts.pattern = "test1-*"; opts.pattern = "test1-*";
assert_describe("test1-lightweight-", "HEAD", repo, &opts, &fmt_opts, true); assert_describe("test1-lightweight-*", "HEAD", repo, &opts, &fmt_opts);
opts.pattern = "test2-*"; opts.pattern = "test2-*";
assert_describe("test2-lightweight-", "HEAD", repo, &opts, &fmt_opts, true); assert_describe("test2-lightweight-*", "HEAD", repo, &opts, &fmt_opts);
fmt_opts.always_use_long_format = 1; fmt_opts.always_use_long_format = 1;
assert_describe("test2-lightweight-", "HEAD^", repo, &opts, &fmt_opts, true); assert_describe("test2-lightweight-*", "HEAD^", repo, &opts, &fmt_opts);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment