tests,json: Improve verbose mode and add verbose 2

* tests/json/t-json.c (main): Handle multiple verbose args.
(test-contains): Improve verbose output
This commit is contained in:
Andre Heinecke 2018-11-14 13:14:52 +01:00
parent 3e5684d99b
commit 9933641cce
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C

View File

@ -36,7 +36,7 @@
#include "../../src/cJSON.h" #include "../../src/cJSON.h"
/* Register tests here */ /* Register tests here */
static const char*tests[] = { "t-config", NULL }; static const char*tests[] = { "t-keylist", "t-config", "t-keylist", NULL };
static int verbose = 0; static int verbose = 0;
@ -95,14 +95,18 @@ get_file (const char *fname)
int int
test_contains (cjson_t needle, cjson_t hay) test_contains (cjson_t needle, cjson_t hay)
{ {
/*fprintf (stderr, "checking \n%s\n -------against-------- \n%s\n", if (verbose == 2)
cJSON_Print (needle), cJSON_Print (hay)); */ fprintf (stderr, "%s: -------checking-------- "
"\n%s\n -------against-------- \n%s\n",
nonnull (needle->string), cJSON_Print (needle),
cJSON_Print (hay));
/* Type check. This automatically checks bool vals and NULL */ /* Type check. This automatically checks bool vals and NULL */
if (needle->type != hay->type) if (needle->type != hay->type)
{ {
if (verbose) if (verbose)
fprintf (stderr, "type mismatch expected %i got %i\n", needle->type, fprintf (stderr, "%s: type mismatch expected %i got %i\n",
nonnull (needle->string), needle->type,
hay->type); hay->type);
return 1; return 1;
} }
@ -113,8 +117,9 @@ test_contains (cjson_t needle, cjson_t hay)
if (needle->valueint != hay->valueint) if (needle->valueint != hay->valueint)
{ {
if (verbose) if (verbose)
fprintf (stderr, "Value mismatch. Expected %i got %i\n", fprintf (stderr, "%s: value mismatch. Expected %i got %i\n",
needle->valueint, hay->valueint); nonnull (needle->string), needle->valueint,
hay->valueint);
return 1; return 1;
} }
} }
@ -123,8 +128,8 @@ test_contains (cjson_t needle, cjson_t hay)
if (strcmp (needle->valuestring, hay->valuestring)) if (strcmp (needle->valuestring, hay->valuestring))
{ {
if (verbose) if (verbose)
fprintf (stderr, "String mismatch Expected '%s' got '%s'\n", fprintf (stderr, "%s: string mismatch Expected '%s' got '%s'\n",
needle->valuestring, hay->valuestring); needle->string, needle->valuestring, hay->valuestring);
return 1; return 1;
} }
} }
@ -329,14 +334,21 @@ int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
const char *gpgme_json = getenv ("gpgme_json"); const char *gpgme_json = getenv ("gpgme_json");
int last_argc = -1;
if (argc == 2 && !strcmp (argv[1], "--verbose")) if (argc)
{ argc--; argv++; }
while (argc && last_argc != argc )
{ {
/* Note that verbose will print out lots of mismatchs last_argc = argc;
because we have to try trough anonymous objects */ if (!strcmp (*argv, "--verbose"))
verbose = 1; {
verbose++;
argc--; argv++;
}
} }
init_gpgme (GPGME_PROTOCOL_SPAWN); init_gpgme (GPGME_PROTOCOL_SPAWN);