bundle-uri: unit test "key=value" parsing
Create a new 'test-tool bundle-uri' test helper. This helper will assist in testing logic deep in the bundle URI feature. This change introduces the 'parse-key-values' subcommand, which parses an input file as a list of lines. These are fed into bundle_uri_parse_line() to test how we construct a 'struct bundle_list' from that data. The list is then output to stdout as if the key-value pairs were a Git config file. We use an input file instead of stdin because of a future change to parse in config-file format that works better as an input file. Co-authored-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9424e373fd
commit
d796cedbe8
33
bundle-uri.c
33
bundle-uri.c
@ -66,6 +66,39 @@ int for_all_bundles_in_list(struct bundle_list *list,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int summarize_bundle(struct remote_bundle_info *info, void *data)
|
||||
{
|
||||
FILE *fp = data;
|
||||
fprintf(fp, "[bundle \"%s\"]\n", info->id);
|
||||
fprintf(fp, "\turi = %s\n", info->uri);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_bundle_list(FILE *fp, struct bundle_list *list)
|
||||
{
|
||||
const char *mode;
|
||||
|
||||
switch (list->mode) {
|
||||
case BUNDLE_MODE_ALL:
|
||||
mode = "all";
|
||||
break;
|
||||
|
||||
case BUNDLE_MODE_ANY:
|
||||
mode = "any";
|
||||
break;
|
||||
|
||||
case BUNDLE_MODE_NONE:
|
||||
default:
|
||||
mode = "<unknown>";
|
||||
}
|
||||
|
||||
fprintf(fp, "[bundle]\n");
|
||||
fprintf(fp, "\tversion = %d\n", list->version);
|
||||
fprintf(fp, "\tmode = %s\n", mode);
|
||||
|
||||
for_all_bundles_in_list(list, summarize_bundle, fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a key-value pair, update the state of the given bundle list.
|
||||
* Returns 0 if the key-value pair is understood. Returns -1 if the key
|
||||
|
Reference in New Issue
Block a user