verify diff output in blob diff test
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
diff --git a/regress/repository/Makefile b/regress/repository/Makefile
index aabadbc..765397c 100644
--- a/regress/repository/Makefile
+++ b/regress/repository/Makefile
@@ -4,7 +4,7 @@ PROG = repository_test
SRCS = path.c repository.c error.c refs.c object.c sha1.c diff.c \
diffreg.c pack.c delta.c zbuf.c repository_test.c
-CPPFLAGS = -I${.CURDIR}/../../include
+CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lutil -lz
DEBUG = -O0 -g
CFLAGS += -Werror -Wall -Wstrict-prototypes -Wunused-variable
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index d822baa..85c1d23 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -19,6 +19,7 @@
#include <stdarg.h>
#include <stdio.h>
+#include <util.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -31,6 +32,12 @@
#include "got_repository.h"
#include "got_diff.h"
+#include "got_lib_path.h"
+
+#ifndef nitems
+#define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
+#endif
+
#define GOT_REPO_PATH "../../../"
static int verbose;
@@ -294,6 +301,26 @@ repo_diff_blob(const char *repo_path)
struct got_blob_object *blob1;
struct got_blob_object *blob2;
FILE *outfile;
+ int i;
+ char *line;
+ size_t len;
+ const char delim[3] = {'\0', '\0', '\0'};
+ const char *expected_output[] = {
+ "--- 141f5fdc96126c1f4195558560a3c915e3d9b4c3",
+ "+++ de7eb21b21c7823a753261aadf7cba35c9580fbf",
+ "@@ -1,10 +1,10 @@",
+ " .PATH:${.CURDIR}/../../lib",
+ " ",
+ " PROG = repository_test",
+ "-SRCS = path.c repository.c error.c refs.c repository_test.c",
+ "+SRCS = path.c repository.c error.c refs.c object.c sha1.c repository_test.c",
+ " ",
+ " CPPFLAGS = -I${.CURDIR}/../../include",
+ "-LDADD = -lutil",
+ "+LDADD = -lutil -lz",
+ " ",
+ " NOMAN = yes"
+ };
err = got_repo_open(&repo, repo_path);
if (err != NULL || repo == NULL)
@@ -319,14 +346,29 @@ repo_diff_blob(const char *repo_path)
return 0;
test_printf("\n");
- if (!verbose) {
- outfile = fopen("/dev/null", "w+");
- if (outfile == NULL)
- return 0;
- } else
- outfile = stdout;
+ outfile = got_opentemp();
+ if (outfile == NULL)
+ return 0;
got_diff_blob(blob1, blob2, NULL, NULL, outfile);
+ rewind(outfile);
+ i = 0;
+ while ((line = fparseln(outfile, &len, NULL, delim, 0)) != NULL) {
+ test_printf(line);
+ test_printf("\n");
+ if (i < nitems(expected_output) &&
+ strcmp(line, expected_output[i]) != 0) {
+ test_printf("diff output mismatch; expected: '%s'\n",
+ expected_output[i]);
+ }
+ i++;
+ }
+ fclose(outfile);
test_printf("\n");
+ if (i != nitems(expected_output) + 1) {
+ test_printf("number of lines expected: %d; actual: %d\n",
+ nitems(expected_output), i - 1);
+ return 0;
+ }
got_object_blob_close(blob1);
got_object_blob_close(blob2);