make repository test less verbose by default
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
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index ac7b326..ff3cb34 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -17,8 +17,10 @@
#include <sys/stat.h>
#include <sys/queue.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sha1.h>
#include <zlib.h>
@@ -28,9 +30,25 @@
#include "got_repository.h"
#include "got_sha1.h"
#include "got_diff.h"
+#include "unistd.h"
#define GOT_REPO_PATH "../../../"
+int verbose = 0;
+
+void
+test_printf(char *fmt, ...)
+{
+ va_list ap;
+
+ if (!verbose)
+ return;
+
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+}
+
static const struct got_error *
print_commit_object(struct got_object *, struct got_repository *);
@@ -73,12 +91,12 @@ print_tree_object(struct got_object *obj, char *parent,
char *next_parent;
if (!S_ISDIR(te->mode)) {
- printf("%s %s/%s\n",
+ test_printf("%s %s/%s\n",
got_object_id_str(&te->id, hex, sizeof(hex)),
parent, te->name);
continue;
}
- printf("%s %s/%s\n",
+ test_printf("%s %s/%s\n",
got_object_id_str(&te->id, hex, sizeof(hex)),
parent, te->name);
@@ -125,23 +143,23 @@ print_commit_object(struct got_object *obj, struct got_repository *repo)
if (err != NULL)
return err;
- printf("tree: %s\n",
+ test_printf("tree: %s\n",
got_object_id_str(&commit->tree_id, buf, sizeof(buf)));
- printf("parent%s: ", (commit->nparents == 1) ? "" : "s");
+ test_printf("parent%s: ", (commit->nparents == 1) ? "" : "s");
SIMPLEQ_FOREACH(pid, &commit->parent_ids, entry) {
- printf("%s\n",
+ test_printf("%s\n",
got_object_id_str(&pid->id, buf, sizeof(buf)));
}
- printf("author: %s\n", commit->author);
- printf("committer: %s\n", commit->committer);
- printf("log: %s\n", commit->logmsg);
+ test_printf("author: %s\n", commit->author);
+ test_printf("committer: %s\n", commit->committer);
+ test_printf("log: %s\n", commit->logmsg);
err = got_object_open(&treeobj, repo, &commit->tree_id);
if (err != NULL)
return err;
if (got_object_get_type(treeobj) == GOT_OBJ_TYPE_TREE) {
print_tree_object(treeobj, "", repo);
- printf("\n");
+ test_printf("\n");
}
got_object_close(treeobj);
@@ -171,7 +189,7 @@ repo_read_log(const char *repo_path)
err = got_ref_resolve(&id, repo, head_ref);
if (err != NULL || head_ref == NULL)
return 0;
- printf("HEAD is at %s\n", got_object_id_str(id, buf, sizeof(buf)));
+ test_printf("HEAD is at %s\n", got_object_id_str(id, buf, sizeof(buf)));
err = got_object_open(&obj, repo, id);
if (err != NULL || obj == NULL)
return 0;
@@ -217,15 +235,15 @@ repo_read_blob(const char *repo_path)
if (err != NULL)
return 0;
- putchar('\n');
+ test_printf("\n");
do {
err = got_object_blob_read_block(blob, &len);
if (err)
break;
for (i = 0; i < len; i++)
- putchar(blob->zb.outbuf[i]);
+ test_printf("%c", blob->zb.outbuf[i]);
} while (len != 0);
- putchar('\n');
+ test_printf("\n");
got_object_blob_close(blob);
got_object_close(obj);
@@ -278,9 +296,9 @@ repo_diff_blob(const char *repo_path)
if (err != NULL)
return 0;
- putchar('\n');
+ test_printf("\n");
got_diff_blob(blob1, blob2, NULL, NULL, stdout);
- putchar('\n');
+ test_printf("\n");
got_object_blob_close(blob1);
got_object_blob_close(blob2);
@@ -335,9 +353,9 @@ repo_diff_tree(const char *repo_path)
if (err != NULL)
return 0;
- putchar('\n');
+ test_printf("\n");
got_diff_tree(tree1, tree2, repo);
- putchar('\n');
+ test_printf("\n");
got_object_tree_close(tree1);
got_object_tree_close(tree2);
@@ -352,18 +370,40 @@ repo_diff_tree(const char *repo_path)
printf("test %s %s\n", (name), test_ok ? "ok" : "failed"); \
failure = (failure || !test_ok); }
+
+void
+usage(void)
+{
+ fprintf(stderr, "usage: repository_test [-v] [REPO_PATH]\n");
+}
+
int
-main(int argc, const char *argv[])
+main(int argc, char *argv[])
{
int test_ok = 0, failure = 0;
const char *repo_path;
+ int ch;
+ int vflag = 0;
+
+ while ((ch = getopt(argc, argv, "v")) != -1) {
+ switch (ch) {
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ usage();
+ return 1;
+ }
+ }
+ argc -= optind;
+ argv += optind;
- if (argc == 1)
+ if (argc == 0)
repo_path = GOT_REPO_PATH;
- else if (argc == 2)
+ else if (argc == 1)
repo_path = argv[1];
else {
- fprintf(stderr, "usage: repository_test [REPO_PATH]\n");
+ usage();
return 1;
}