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.
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
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);
}