We used to get rebuilds of all test programs when one test was
touched.
Because we want portable Makefiles we need to specify the dependencies
this way - there isn't really a good way to do this without resorting
to unportable pattern matching.
Be verbose instead.
Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
Makefile.in | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/Makefile.in b/Makefile.in
index 545f110a..63ddb8a1 100644
--- a/Makefile.in+++ b/Makefile.in
@@ -331,6 +331,7 @@ clean-auto:
$(TEST_PROGRAMS) \
$(MANPAGES)
+###### TEST SUITE #####################################TEST_PROGRAMS = \
tests/json-escape \
tests/github-parse \
@@ -342,7 +343,17 @@ TEST_PROGRAMS = \
tests/base64 \
tests/difftests
-$(TEST_PROGRAMS): libgcli.a $(TEST_PROGRAMS:=.tests.o)+tests/json-escape: tests/json-escape.tests.o+tests/github-parse: tests/github-parse.tests.o+tests/gitlab-parse: tests/gitlab-parse.tests.o+tests/gitea-parse: tests/gitea-parse.tests.o+tests/bugzilla-parse: tests/bugzilla-parse.tests.o+tests/url-encode: tests/url-encode.tests.o+tests/jsongen: tests/jsongen.tests.o+tests/base64: tests/base64.tests.o+tests/difftests: tests/difftests.tests.o++$(TEST_PROGRAMS): libgcli.a $(CCACHE) $(CC) $(CFLAGS) $(CCDEPFLAGS) $(CPPFLAGS) \
$(LIBATFC_CFLAGS) $(LIBCURL_CFLAGS) $(LIBCRYPTO_CFLAGS) \
$(LDFLAGS) -o $@ $(@:=.tests.o) libgcli.a \
--
2.45.2
[PATCH gcli 2/3] diffutil: Fix buggy hunk range info parser
We used to get errors parsing diffs when the file diffed was missing
a trailing newline. This gave a diff line like:
\ No newline at end of file
This caused a hiccup in the parser which made the line a comment
at the end of the diff which makes no sense.
Also add a test case for this specific bug.
Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
src/diffutil.c | 3 +-tests/difftests.c | 37 +++++++++++++++++++
.../stuff_with_no_newline_in_diff.diff | 11 ++++++
3 files changed, 50 insertions(+), 1 deletion(-)
create mode 100644 tests/samples/stuff_with_no_newline_in_diff.diff
diff --git a/src/diffutil.c b/src/diffutil.c
index fc370298..dd57579e 100644
--- a/src/diffutil.c+++ b/src/diffutil.c
@@ -523,7 +523,7 @@ read_hunk_body(struct gcli_diff_parser *parser, struct gcli_diff_hunk *hunk)
/* If it is a comment, don't count this line into the absolute diff
* offset of the hunk */
if (line.start[0] == ' ' || line.start[0] == '+' ||
- line.start[0] == '-')+ line.start[0] == '-' || line.start[0] == '\\') {
parser->diff_line_offset += 1;
}
@@ -925,6 +925,7 @@ gcli_hunk_get_comments(struct gcli_diff const *diff,
case '+':
case ' ':
case '-':
+ case '\\': ctx.diff_line_offset += 1;
ctx.last_line_is_new = hd == '+';
diff --git a/tests/difftests.c b/tests/difftests.c
index 65ef5366..d7bf9ca3 100644
--- a/tests/difftests.c+++ b/tests/difftests.c
@@ -1044,6 +1044,42 @@ ATF_TC_BODY(bug_short_hunk_range, tc)
gcli_free_diff_parser(&parser);
}
+ATF_TC_WITHOUT_HEAD(bug_no_newline_at_end_of_file);+ATF_TC_BODY(bug_no_newline_at_end_of_file, tc)+{+ struct gcli_patch patch = {0};+ struct gcli_diff_parser parser = {0};+ struct gcli_diff_comments comments = {0};+ struct gcli_diff_comment *comment = NULL;++ char const *const fname = "stuff_with_no_newline_in_diff.diff";++ FILE *inf = open_sample(fname);+ ATF_REQUIRE(gcli_diff_parser_from_file(inf, fname, &parser) == 0);+ ATF_REQUIRE(gcli_parse_patch(&parser, &patch) == 0);++ TAILQ_INIT(&comments);+ ATF_REQUIRE(gcli_patch_get_comments(&patch, &comments) == 0);++ comment = TAILQ_FIRST(&comments);+ ATF_REQUIRE(comment);++ ATF_CHECK(comment->before.start_row == 1);+ ATF_CHECK(comment->before.end_row == 1);++ ATF_CHECK(comment->after.start_row == 1);+ ATF_CHECK(comment->after.end_row == 1);++ ATF_CHECK_STREQ(comment->comment, "This is a comment\n");+ ATF_CHECK_STREQ(comment->diff_text,+ "-this is a test file\n"+ "+this is a test file\n"+ "\\ No newline at end of file\n");++ gcli_free_patch(&patch);+ gcli_free_diff_parser(&parser);+}+ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, free_patch_cleans_up_properly);
@@ -1069,6 +1105,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, patch_for_git_object_format_version_1);
ATF_TP_ADD_TC(tp, bug_patch_series_fail_get_comments);
ATF_TP_ADD_TC(tp, bug_short_hunk_range);
+ ATF_TP_ADD_TC(tp, bug_no_newline_at_end_of_file); return atf_no_error();
}
diff --git a/tests/samples/stuff_with_no_newline_in_diff.diff b/tests/samples/stuff_with_no_newline_in_diff.diff
new file mode 100644
index 00000000..7f05b111
--- /dev/null+++ b/tests/samples/stuff_with_no_newline_in_diff.diff
@@ -0,0 +1,11 @@
+diff --git a/test.txt b/test.txt+index 493021b..68a4528 100644+--- a/test.txt++++ b/test.txt+@@ -1 +1 @@+> This is a comment+{+-this is a test file++this is a test file+\ No newline at end of file+}
--
2.45.2