diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/diff/format_email.c | 193 | ||||
-rw-r--r-- | tests/diff/stats.c | 357 |
2 files changed, 159 insertions, 391 deletions
diff --git a/tests/diff/format_email.c b/tests/diff/format_email.c index 3260fdea8..18ad99bd5 100644 --- a/tests/diff/format_email.c +++ b/tests/diff/format_email.c @@ -17,15 +17,44 @@ void test_diff_format_email__cleanup(void) cl_git_sandbox_cleanup(); } -void test_diff_format_email__simple(void) +static void assert_email_match( + const char *expected, + const char *oidstr, + git_diff_format_email_options *opts) { git_oid oid; git_commit *commit = NULL; git_diff *diff = NULL; - git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; git_buf buf = GIT_BUF_INIT; - const char *email = + git_oid_fromstr(&oid, oidstr); + + cl_git_pass(git_commit_lookup(&commit, repo, &oid)); + + opts->id = git_commit_id(commit); + opts->author = git_commit_author(commit); + if (!opts->summary) + opts->summary = git_commit_summary(commit); + + cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); + cl_git_pass(git_diff_format_email(&buf, diff, opts)); + + cl_assert_equal_s(expected, git_buf_cstr(&buf)); + git_buf_clear(&buf); + + cl_git_pass(git_diff_commit_as_email( + &buf, repo, commit, 1, 1, opts->flags, NULL)); + cl_assert_equal_s(expected, git_buf_cstr(&buf)); + + git_diff_free(diff); + git_commit_free(commit); + git_buf_free(&buf); +} + +void test_diff_format_email__simple(void) +{ + git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; + const char *email = "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <jacquesg@striata.com>\n" \ "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \ @@ -64,25 +93,8 @@ void test_diff_format_email__simple(void) "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; - git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - opts.id = git_commit_id(commit); - opts.author = git_commit_author(commit); - opts.summary = git_commit_summary(commit); - - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_buf_clear(&buf); - cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_free(&buf); + assert_email_match( + email, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); } void test_diff_format_email__multiple(void) @@ -90,10 +102,10 @@ void test_diff_format_email__multiple(void) git_oid oid; git_commit *commit = NULL; git_diff *diff = NULL; - git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; + git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; git_buf buf = GIT_BUF_INIT; - const char *email = + const char *email = "From 10808fe9c9be5a190c0ba68d1a002233fb363508 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <jacquesg@striata.com>\n" \ "Date: Thu, 10 Apr 2014 19:37:05 +0200\n" \ @@ -167,6 +179,7 @@ void test_diff_format_email__multiple(void) "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; + git_oid_fromstr(&oid, "10808fe9c9be5a190c0ba68d1a002233fb363508"); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); @@ -196,7 +209,7 @@ void test_diff_format_email__multiple(void) cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); + cl_assert_equal_s(email, git_buf_cstr(&buf)); git_diff_free(diff); git_commit_free(commit); @@ -205,13 +218,8 @@ void test_diff_format_email__multiple(void) void test_diff_format_email__exclude_marker(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; - git_buf buf = GIT_BUF_INIT; - - const char *email = + const char *email = "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <jacquesg@striata.com>\n" \ "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \ @@ -250,27 +258,10 @@ void test_diff_format_email__exclude_marker(void) "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; - git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - opts.id = git_commit_id(commit); - opts.author = git_commit_author(commit); - opts.summary = git_commit_summary(commit); - opts.flags |= GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER; - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_buf_clear(&buf); - cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, - GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER, NULL)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_free(&buf); + assert_email_match( + email, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); } void test_diff_format_email__invalid_no(void) @@ -303,13 +294,8 @@ void test_diff_format_email__invalid_no(void) void test_diff_format_email__mode_change(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; - git_buf buf = GIT_BUF_INIT; - - const char *email = + const char *email = "From 7ade76dd34bba4733cf9878079f9fd4a456a9189 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <jacquesg@striata.com>\n" \ "Date: Thu, 10 Apr 2014 10:05:03 +0200\n" \ @@ -330,36 +316,14 @@ void test_diff_format_email__mode_change(void) "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; - git_oid_fromstr(&oid, "7ade76dd34bba4733cf9878079f9fd4a456a9189"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - opts.id = git_commit_id(commit); - opts.author = git_commit_author(commit); - opts.summary = git_commit_summary(commit); - - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_buf_clear(&buf); - cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_free(&buf); + assert_email_match( + email, "7ade76dd34bba4733cf9878079f9fd4a456a9189", &opts); } void test_diff_format_email__rename_add_remove(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; - git_buf buf = GIT_BUF_INIT; - - const char *email = + const char *email = "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <jacquesg@striata.com>\n" \ "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \ @@ -422,35 +386,13 @@ void test_diff_format_email__rename_add_remove(void) "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; - git_oid_fromstr(&oid, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - opts.id = git_commit_id(commit); - opts.author = git_commit_author(commit); - opts.summary = git_commit_summary(commit); - - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_buf_clear(&buf); - cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_free(&buf); + assert_email_match( + email, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", &opts); } void test_diff_format_email__multiline_summary(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; - git_buf buf = GIT_BUF_INIT; - const char *email = "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <jacquesg@striata.com>\n" \ @@ -490,36 +432,15 @@ void test_diff_format_email__multiline_summary(void) "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; - git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - opts.id = git_commit_id(commit); - opts.author = git_commit_author(commit); opts.summary = "Modify some content\nSome extra stuff here"; - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_buf_clear(&buf); - cl_git_pass(git_diff_commit_as_email(&buf, repo, commit, 1, 1, 0, NULL)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_free(&buf); + assert_email_match( + email, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); } void test_diff_format_email__binary(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; - git_buf buf = GIT_BUF_INIT; - - /* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */ const char *email = "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \ "From: Jacques Germishuys <jacquesg@striata.com>\n" \ @@ -536,21 +457,11 @@ void test_diff_format_email__binary(void) "--\n" \ "libgit2 " LIBGIT2_VERSION "\n" \ "\n"; + /* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */ - git_oid_fromstr(&oid, "8d7523f6fcb2404257889abe0d96f093d9f524f9"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - opts.id = git_commit_id(commit); - opts.author = git_commit_author(commit); opts.summary = "Modified binary file"; - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_format_email(&buf, diff, &opts)); - cl_assert(strcmp(git_buf_cstr(&buf), email) == 0); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_free(&buf); + assert_email_match( + email, "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts); } diff --git a/tests/diff/stats.c b/tests/diff/stats.c index 131b7681d..055019f69 100644 --- a/tests/diff/stats.c +++ b/tests/diff/stats.c @@ -5,246 +5,173 @@ #include "commit.h" #include "diff.h" -static git_repository *repo; +static git_repository *_repo; +static git_diff_stats *_stats; void test_diff_stats__initialize(void) { - repo = cl_git_sandbox_init("diff_format_email"); + _repo = cl_git_sandbox_init("diff_format_email"); } void test_diff_stats__cleanup(void) { + git_diff_stats_free(_stats); _stats = NULL; cl_git_sandbox_cleanup(); } -void test_diff_stats__stat(void) +static void diff_stats_from_commit_oid( + git_diff_stats **stats, const char *oidstr, bool rename) { git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; - git_buf buf = GIT_BUF_INIT; + git_commit *commit; + git_diff *diff; + + git_oid_fromstr(&oid, oidstr); + cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); + cl_git_pass(git_diff__commit(&diff, _repo, commit, NULL)); + if (rename) + cl_git_pass(git_diff_find_similar(diff, NULL)); + cl_git_pass(git_diff_get_stats(stats, diff)); + + git_diff_free(diff); + git_commit_free(commit); +} +void test_diff_stats__stat(void) +{ + git_buf buf = GIT_BUF_INIT; const char *stat = " file1.txt | 8 +++++---\n" \ " 1 file changed, 5 insertions(+), 3 deletions(-)\n"; - git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); + diff_stats_from_commit_oid( + &_stats, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", false); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); + cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(5, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(3, git_diff_stats_deletions(_stats)); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 1); - cl_assert(git_diff_stats_insertions(stats) == 5); - cl_assert(git_diff_stats_deletions(stats) == 3); - - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); git_buf_free(&buf); } void test_diff_stats__multiple_hunks(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file2.txt | 5 +++--\n" \ " file3.txt | 6 ++++--\n" \ " 2 files changed, 7 insertions(+), 4 deletions(-)\n"; - git_oid_fromstr(&oid, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); + diff_stats_from_commit_oid( + &_stats, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2", false); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 2); - cl_assert(git_diff_stats_insertions(stats) == 7); - cl_assert(git_diff_stats_deletions(stats) == 4); + cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(7, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(4, git_diff_stats_deletions(_stats)); - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__numstat(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = "3 2 file2.txt\n" "4 2 file3.txt\n"; - git_oid_fromstr(&oid, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - - cl_git_pass(git_diff_get_stats(&stats, diff)); - - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_NUMBER)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); + diff_stats_from_commit_oid( + &_stats, "cd471f0d8770371e1bc78bcbb38db4c7e4106bd2", false); - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__shortstat(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " 1 file changed, 5 insertions(+), 3 deletions(-)\n"; - git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); + diff_stats_from_commit_oid( + &_stats, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", false); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 1); - cl_assert(git_diff_stats_insertions(stats) == 5); - cl_assert(git_diff_stats_deletions(stats) == 3); + cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(5, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(3, git_diff_stats_deletions(_stats)); - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_SHORT)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_SHORT, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__rename(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file2.txt => file2.txt.renamed | 1 +\n" " file3.txt => file3.txt.renamed | 4 +++-\n" - " 2 files changed, 4 insertions(+), 1 deletions(-)\n"; - - git_oid_fromstr(&oid, "8947a46e2097638ca6040ad4877246f4186ec3bd"); + " 2 files changed, 4 insertions(+), 1 deletion(-)\n"; - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_find_similar(diff, NULL)); + diff_stats_from_commit_oid( + &_stats, "8947a46e2097638ca6040ad4877246f4186ec3bd", true); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 2); - cl_assert(git_diff_stats_insertions(stats) == 4); - cl_assert(git_diff_stats_deletions(stats) == 1); + cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(4, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(1, git_diff_stats_deletions(_stats)); - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__rename_nochanges(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file2.txt.renamed => file2.txt.renamed2 | 0\n" " file3.txt.renamed => file3.txt.renamed2 | 0\n" " 2 files changed, 0 insertions(+), 0 deletions(-)\n"; - git_oid_fromstr(&oid, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_find_similar(diff, NULL)); + diff_stats_from_commit_oid( + &_stats, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4", true); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 2); - cl_assert(git_diff_stats_insertions(stats) == 0); - cl_assert(git_diff_stats_deletions(stats) == 0); + cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(0, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(0, git_diff_stats_deletions(_stats)); - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__rename_and_modifiy(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file2.txt.renamed2 | 2 +-\n" " file3.txt.renamed2 => file3.txt.renamed | 0\n" - " 2 files changed, 1 insertions(+), 1 deletions(-)\n"; + " 2 files changed, 1 insertion(+), 1 deletion(-)\n"; - git_oid_fromstr(&oid, "4ca10087e696d2ba78d07b146a118e9a7096ed4f"); + diff_stats_from_commit_oid( + &_stats, "4ca10087e696d2ba78d07b146a118e9a7096ed4f", true); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_diff_find_similar(diff, NULL)); + cl_assert_equal_sz(2, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(1, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(1, git_diff_stats_deletions(_stats)); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 2); - cl_assert(git_diff_stats_insertions(stats) == 1); - cl_assert(git_diff_stats_deletions(stats) == 1); - - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__rename_no_find(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file2.txt | 5 -----\n" " file2.txt.renamed | 6 ++++++\n" @@ -252,33 +179,21 @@ void test_diff_stats__rename_no_find(void) " file3.txt.renamed | 7 +++++++\n" " 4 files changed, 13 insertions(+), 10 deletions(-)\n"; - git_oid_fromstr(&oid, "8947a46e2097638ca6040ad4877246f4186ec3bd"); + diff_stats_from_commit_oid( + &_stats, "8947a46e2097638ca6040ad4877246f4186ec3bd", false); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); + cl_assert_equal_sz(4, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(13, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(10, git_diff_stats_deletions(_stats)); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 4); - cl_assert(git_diff_stats_insertions(stats) == 13); - cl_assert(git_diff_stats_deletions(stats) == 10); - - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__rename_nochanges_no_find(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file2.txt.renamed | 6 ------\n" " file2.txt.renamed2 | 6 ++++++\n" @@ -286,143 +201,85 @@ void test_diff_stats__rename_nochanges_no_find(void) " file3.txt.renamed2 | 7 +++++++\n" " 4 files changed, 13 insertions(+), 13 deletions(-)\n"; - git_oid_fromstr(&oid, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); + diff_stats_from_commit_oid( + &_stats, "3991dce9e71a0641ca49a6a4eea6c9e7ff402ed4", false); - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 4); - cl_assert(git_diff_stats_insertions(stats) == 13); - cl_assert(git_diff_stats_deletions(stats) == 13); - - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); + cl_assert_equal_sz(4, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(13, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(13, git_diff_stats_deletions(_stats)); - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__rename_and_modifiy_no_find(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file2.txt.renamed2 | 2 +-\n" " file3.txt.renamed | 7 +++++++\n" " file3.txt.renamed2 | 7 -------\n" " 3 files changed, 8 insertions(+), 8 deletions(-)\n"; - git_oid_fromstr(&oid, "4ca10087e696d2ba78d07b146a118e9a7096ed4f"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 3); - cl_assert(git_diff_stats_insertions(stats) == 8); - cl_assert(git_diff_stats_deletions(stats) == 8); + diff_stats_from_commit_oid( + &_stats, "4ca10087e696d2ba78d07b146a118e9a7096ed4f", false); - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); + cl_assert_equal_sz(3, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(8, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(8, git_diff_stats_deletions(_stats)); - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__binary(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - - /* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */ const char *stat = " binary.bin | Bin 3 -> 0 bytes\n" " 1 file changed, 0 insertions(+), 0 deletions(-)\n"; + /* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */ - git_oid_fromstr(&oid, "8d7523f6fcb2404257889abe0d96f093d9f524f9"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - - cl_git_pass(git_diff_get_stats(&stats, diff)); - cl_assert(git_diff_stats_files_changed(stats) == 1); - cl_assert(git_diff_stats_insertions(stats) == 0); - cl_assert(git_diff_stats_deletions(stats) == 0); + diff_stats_from_commit_oid( + &_stats, "8d7523f6fcb2404257889abe0d96f093d9f524f9", false); - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); + cl_assert_equal_sz(1, git_diff_stats_files_changed(_stats)); + cl_assert_equal_sz(0, git_diff_stats_insertions(_stats)); + cl_assert_equal_sz(0, git_diff_stats_deletions(_stats)); - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__binary_numstat(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = "- - binary.bin\n"; - git_oid_fromstr(&oid, "8d7523f6fcb2404257889abe0d96f093d9f524f9"); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - - cl_git_pass(git_diff_get_stats(&stats, diff)); + diff_stats_from_commit_oid( + &_stats, "8d7523f6fcb2404257889abe0d96f093d9f524f9", false); - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_NUMBER)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_NUMBER, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } void test_diff_stats__mode_change(void) { - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_diff_stats *stats = NULL; git_buf buf = GIT_BUF_INIT; - const char *stat = " file1.txt.renamed | 0\n" \ " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ - " mode change 100644 => 100755 file1.txt.renamed\n" \ - "\n"; + " mode change 100644 => 100755 file1.txt.renamed\n"; - git_oid_fromstr(&oid, "7ade76dd34bba4733cf9878079f9fd4a456a9189"); + diff_stats_from_commit_oid( + &_stats, "7ade76dd34bba4733cf9878079f9fd4a456a9189", false); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - - cl_git_pass(git_diff_get_stats(&stats, diff)); - - cl_git_pass(git_diff_stats_to_buf(&buf, stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY)); - cl_assert(strcmp(git_buf_cstr(&buf), stat) == 0); - - git_diff_stats_free(stats); - git_diff_free(diff); - git_commit_free(commit); + cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0)); + cl_assert_equal_s(stat, git_buf_cstr(&buf)); git_buf_free(&buf); } |