Commit 5431c46a9604ac5c5d17390013d3741196b41051

Carlos Martín Nieto 2014-09-30T09:04:04

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.

diff --git a/tests/describe/describe.c b/tests/describe/describe.c
index e2dda96..d2df36c 100644
--- a/tests/describe/describe.c
+++ b/tests/describe/describe.c
@@ -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")));
 
-	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;
 
-	assert_describe("be3563a", "HEAD^", repo, &opts, &fmt_opts, true);
+	assert_describe("be3563a*", "HEAD^", repo, &opts, &fmt_opts);
 
 	git_repository_free(repo);
 }
diff --git a/tests/describe/describe_helpers.c b/tests/describe/describe_helpers.c
index 230e1bd..e4dfcef 100644
--- a/tests/describe/describe_helpers.c
+++ b/tests/describe/describe_helpers.c
@@ -5,8 +5,7 @@ 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_describe_format_options *fmt_opts)
 {
 	git_object *object;
 	git_buf label = GIT_BUF_INIT;
@@ -17,10 +16,7 @@ void assert_describe(
 	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);
+	cl_git_pass(p_fnmatch(expected_output, git_buf_cstr(&label), 0));
 
 	git_describe_result_free(result);
 	git_object_free(object);
@@ -29,11 +25,9 @@ void assert_describe(
 
 void assert_describe_workdir(
 	const char *expected_output,
-	const char *expected_suffix,
 	git_repository *repo,
 	git_describe_opts *opts,
-	git_describe_format_options *fmt_opts,
-	bool is_prefix_match)
+	git_describe_format_options *fmt_opts)
 {
 	git_buf label = GIT_BUF_INIT;
 	git_describe_result *result;
@@ -41,13 +35,7 @@ void assert_describe_workdir(
 	cl_git_pass(git_describe_workdir(&result, repo, 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);
-
-	if (expected_suffix)
-		cl_assert_equal_i(0, git__suffixcmp(git_buf_cstr(&label), expected_suffix));
+	cl_git_pass(p_fnmatch(expected_output, git_buf_cstr(&label), 0));
 
 	git_describe_result_free(result);
 	git_buf_free(&label);
diff --git a/tests/describe/describe_helpers.h b/tests/describe/describe_helpers.h
index 6f79358..5d64172 100644
--- a/tests/describe/describe_helpers.h
+++ b/tests/describe/describe_helpers.h
@@ -6,13 +6,10 @@ 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);
+	git_describe_format_options *fmt_opts);
 
 extern void assert_describe_workdir(
 	const char *expected_output,
-	const char *expected_suffix,
 	git_repository *repo,
 	git_describe_opts *opts,
-	git_describe_format_options *fmt_opts,
-	bool is_prefix_match);
+	git_describe_format_options *fmt_opts);
diff --git a/tests/describe/t6120.c b/tests/describe/t6120.c
index 2ac59a6..b470938 100644
--- a/tests/describe/t6120.c
+++ b/tests/describe/t6120.c
@@ -21,12 +21,12 @@ void test_describe_t6120__default(void)
 	git_describe_opts opts = GIT_DESCRIBE_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, 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);
+	assert_describe("A-*", "HEAD", repo, &opts, &fmt_opts);
+	assert_describe("A-*", "HEAD^", repo, &opts, &fmt_opts);
+	assert_describe("R-*", "HEAD^^", repo, &opts, &fmt_opts);
+	assert_describe("A-*", "HEAD^^2", repo, &opts, &fmt_opts);
+	assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts);
+	assert_describe("R-*", "HEAD^^^", repo, &opts, &fmt_opts);
 }
 
 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;
 	opts.describe_strategy = GIT_DESCRIBE_TAGS;
 
-	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);
+	assert_describe("c-*", "HEAD", repo, &opts, &fmt_opts);
+	assert_describe("c-*", "HEAD^", repo, &opts, &fmt_opts);
+	assert_describe("e-*", "HEAD^^", repo, &opts, &fmt_opts);
+	assert_describe("c-*", "HEAD^^2", repo, &opts, &fmt_opts);
+	assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts);
+	assert_describe("e", "HEAD^^^", repo, &opts, &fmt_opts);
 }
 
 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;
 	opts.describe_strategy = GIT_DESCRIBE_ALL;
 
-	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);
+	assert_describe("heads/master", "HEAD", repo, &opts, &fmt_opts);
+	assert_describe("tags/c-*", "HEAD^", repo, &opts, &fmt_opts);
+	assert_describe("tags/e", "HEAD^^^", repo, &opts, &fmt_opts);
 }
 
 void test_describe_t6120__longformat(void)
@@ -61,8 +61,8 @@ void test_describe_t6120__longformat(void)
 
 	fmt_opts.always_use_long_format = 1;
 
-	assert_describe("B-0-", "HEAD^^2^", repo, &opts, &fmt_opts, true);
-	assert_describe("A-3-", "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);
 }
 
 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;
 	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;
-	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)
@@ -82,13 +82,13 @@ void test_describe_t6120__workdir(void)
 	git_describe_opts opts = GIT_DESCRIBE_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");
 
 	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";
-	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(
@@ -142,15 +142,15 @@ void test_describe_t6120__pattern(void)
 
 	/* Exercize */
 	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.pattern = "test1-*";
-	assert_describe("test1-lightweight-", "HEAD", repo, &opts, &fmt_opts, true);
+	assert_describe("test1-lightweight-*", "HEAD", repo, &opts, &fmt_opts);
 
 	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;
-	assert_describe("test2-lightweight-", "HEAD^", repo, &opts, &fmt_opts, true);
+	assert_describe("test2-lightweight-*", "HEAD^", repo, &opts, &fmt_opts);
 }