diff options
Diffstat (limited to 'tests-clar/commit/parse.c')
-rw-r--r-- | tests-clar/commit/parse.c | 117 |
1 files changed, 81 insertions, 36 deletions
diff --git a/tests-clar/commit/parse.c b/tests-clar/commit/parse.c index bbb502cb5..b99d27991 100644 --- a/tests-clar/commit/parse.c +++ b/tests-clar/commit/parse.c @@ -108,19 +108,20 @@ passing_signature_test_case passing_signature_cases[] = { // Parse an obviously invalid signature {"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60}, // Parse an obviously invalid signature - {"committer foo<@bar>123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60}, + {"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60}, // Parse an obviously invalid signature {"committer <>\n", "committer ", "", "", 0, 0}, - {"committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 0, 0}, - {"committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 0, 0}, - {"author Vicent Marti <tanoku@gmail.com> notime \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0}, - {"author Vicent Marti <tanoku@gmail.com> 123456 notimezone \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0}, - {"author Vicent Marti <tanoku@gmail.com> notime +0100\n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0}, + {"committer Vicent Marti <tanoku@gmail.com> 123456 -1500 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 0}, + {"committer Vicent Marti <tanoku@gmail.com> 123456 +0163 \n", "committer ", "Vicent Marti", "tanoku@gmail.com", 123456, 0}, {"author Vicent Marti <tanoku@gmail.com>\n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0}, - {"author A U Thor <author@example.com>, C O. Miter <comiter@example.com> 1234567890 -0700\n", "author ", "A U Thor", "author@example.com", 1234567890, -420}, - {"author A U Thor <author@example.com> and others 1234567890 -0700\n", "author ", "A U Thor", "author@example.com", 1234567890, -420}, - {"author A U Thor <author@example.com> and others 1234567890\n", "author ", "A U Thor", "author@example.com", 1234567890, 0}, - {"author A U Thor> <author@example.com> and others 1234567890\n", "author ", "A U Thor>", "author@example.com", 1234567890, 0}, + /* a variety of dates */ + {"author Vicent Marti <tanoku@gmail.com> 0 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0, 0}, + {"author Vicent Marti <tanoku@gmail.com> 1234567890 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 1234567890, 0}, + {"author Vicent Marti <tanoku@gmail.com> 2147483647 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0x7fffffff, 0}, + {"author Vicent Marti <tanoku@gmail.com> 4294967295 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0xffffffff, 0}, + {"author Vicent Marti <tanoku@gmail.com> 4294967296 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 4294967296, 0}, + {"author Vicent Marti <tanoku@gmail.com> 8589934592 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 8589934592, 0}, + {NULL,NULL,NULL,NULL,0,0} }; @@ -137,7 +138,7 @@ failing_signature_test_case failing_signature_cases[] = { {"author Vicent Marti <broken@email 12345 \n", "author "}, {"committer Vicent Marti ><\n", "committer "}, {"author ", "author "}, - {NULL,NULL,} + {NULL, NULL,} }; void test_commit_parse__signature(void) @@ -149,12 +150,13 @@ void test_commit_parse__signature(void) { const char *str = passcase->string; size_t len = strlen(passcase->string); - struct git_signature person = {NULL, NULL, {0, 0}}; + struct git_signature person = {0}; + cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n')); - cl_assert(strcmp(passcase->name, person.name) == 0); - cl_assert(strcmp(passcase->email, person.email) == 0); - cl_assert(passcase->time == person.when.time); - cl_assert(passcase->offset == person.when.offset); + cl_assert_equal_s(passcase->name, person.name); + cl_assert_equal_s(passcase->email, person.email); + cl_assert_equal_i((int)passcase->time, (int)person.when.time); + cl_assert_equal_i(passcase->offset, person.when.offset); git__free(person.name); git__free(person.email); } @@ -162,7 +164,7 @@ void test_commit_parse__signature(void) { const char *str = failcase->string; size_t len = strlen(failcase->string); - git_signature person = {NULL, NULL, {0, 0}}; + git_signature person = {0}; cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n')); git__free(person.name); git__free(person.email); } @@ -236,6 +238,30 @@ author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ \n\ a simple commit which works\n", +/* simple commit with GPG signature */ +"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n\ +parent 34734e478d6cf50c27c9d69026d93974d052c454\n\ +author Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\ +committer Ben Burkert <ben@benburkert.com> 1358451456 -0800\n\ +gpgsig -----BEGIN PGP SIGNATURE-----\n\ + Version: GnuPG v1.4.12 (Darwin)\n\ + \n\ + iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\ + o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\ + JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\ + AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\ + SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\ + who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\ + 6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\ + cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\ + c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\ + ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\ + 7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\ + cpxtDQQMGYFpXK/71stq\n\ + =ozeK\n\ + -----END PGP SIGNATURE-----\n\ +\n\ +a simple commit which works\n", }; void test_commit_parse__entire_commit(void) @@ -251,10 +277,8 @@ void test_commit_parse__entire_commit(void) commit->object.repo = g_repo; cl_git_fail(git_commit__parse_buffer( - commit, - failing_commit_cases[i], - strlen(failing_commit_cases[i])) - ); + commit, failing_commit_cases[i], strlen(failing_commit_cases[i])) + ); git_commit__free(commit); } @@ -272,17 +296,11 @@ void test_commit_parse__entire_commit(void) strlen(passing_commit_cases[i])) ); - git_commit__free(commit); - - commit = (git_commit*)git__malloc(sizeof(git_commit)); - memset(commit, 0x0, sizeof(git_commit)); - commit->object.repo = g_repo; - - cl_git_pass(git_commit__parse_buffer( - commit, - passing_commit_cases[i], - strlen(passing_commit_cases[i])) - ); + if (!i) + cl_assert_equal_s("", git_commit_message(commit)); + else + cl_assert(git__prefixcmp( + git_commit_message(commit), "a simple commit which works") == 0); git_commit__free(commit); } @@ -323,10 +341,10 @@ void test_commit_parse__details0(void) { commit_time = git_commit_time(commit); parents = git_commit_parentcount(commit); - cl_assert(strcmp(author->name, "Scott Chacon") == 0); - cl_assert(strcmp(author->email, "schacon@gmail.com") == 0); - cl_assert(strcmp(committer->name, "Scott Chacon") == 0); - cl_assert(strcmp(committer->email, "schacon@gmail.com") == 0); + cl_assert_equal_s("Scott Chacon", author->name); + cl_assert_equal_s("schacon@gmail.com", author->email); + cl_assert_equal_s("Scott Chacon", committer->name); + cl_assert_equal_s("schacon@gmail.com", committer->email); cl_assert(message != NULL); cl_assert(strchr(message, '\n') != NULL); cl_assert(commit_time > 0); @@ -348,3 +366,30 @@ void test_commit_parse__details0(void) { } } +void test_commit_parse__leading_lf(void) +{ + git_commit *commit; + const char *buffer = +"tree 1810dff58d8a660512d4832e740f692884338ccd\n\ +parent e90810b8df3e80c413d903f631643c716887138d\n\ +author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ +committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ +\n\ +\n\ +\n\ +This commit has a few LF at the start of the commit message"; + const char *message = +"\n\ +\n\ +This commit has a few LF at the start of the commit message"; + + commit = (git_commit*)git__malloc(sizeof(git_commit)); + memset(commit, 0x0, sizeof(git_commit)); + commit->object.repo = g_repo; + + cl_git_pass(git_commit__parse_buffer(commit, buffer, strlen(buffer))); + + cl_assert_equal_s(message, git_commit_message(commit)); + + git_commit__free(commit); +} |