Skip to content

Commit

Permalink
libflux/test: add verbose option to message tests
Browse files Browse the repository at this point in the history
Problem: It can be difficult to test/debug flux_msg_fprint tests
becauses tests default to routing all output to /dev/null.

Solution: Support a simple verbose option in test/message.c to have
fprintf output go to stderr.
  • Loading branch information
chu11 committed Jun 25, 2021
1 parent d481443 commit 5174a42
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/common/libflux/test/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdbool.h>
#include <czmq.h>
#include <errno.h>
#include <stdio.h>
Expand All @@ -19,6 +20,7 @@
#include "src/common/libflux/message.h"
#include "src/common/libtap/tap.h"

static bool verbose = false;
/* flux_msg_get_route_first, flux_msg_get_route_last, _get_route_count
* on message with variable number of routing frames
*/
Expand Down Expand Up @@ -921,7 +923,7 @@ void check_print (void)
{
flux_msg_t *msg;
char buf[] = "xxxxxxxx";
FILE *f = fopen ("/dev/null", "w");
FILE *f = verbose ? stderr : fopen ("/dev/null", "w");
if (!f)
BAIL_OUT ("cannot open /dev/null for writing");

Expand Down Expand Up @@ -1110,6 +1112,13 @@ void check_refcount (void)

int main (int argc, char *argv[])
{
int opt;

while ((opt = getopt (argc, argv, "v")) != -1) {
if (opt == 'v')
verbose = true;
}

plan (NO_PLAN);

check_proto ();
Expand Down

0 comments on commit 5174a42

Please sign in to comment.