Skip to content

Commit

Permalink
Add run-time --max-msg command line argument
Browse files Browse the repository at this point in the history
Resolves #33
- Defaults to TEST_MSG_MAXSIZE as normal.
- Adds new usage line in --help output
  • Loading branch information
RosscoG committed Nov 29, 2024
1 parent 31751b4 commit cb3d59a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions include/acutest.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ static int acutest_test_already_logged_ = 0;
static int acutest_case_already_logged_ = 0;
static int acutest_verbose_level_ = 2;
static int acutest_test_failures_ = 0;
static int acutest_max_msg_ = TEST_MSG_MAXSIZE;
static int acutest_colorize_ = 0;
static int acutest_timer_ = 0;

Expand Down Expand Up @@ -888,7 +889,7 @@ acutest_case_(const char* fmt, ...)
void ACUTEST_ATTRIBUTE_(format (printf, 1, 2))
acutest_message_(const char* fmt, ...)
{
char buffer[TEST_MSG_MAXSIZE];
char buffer[acutest_max_msg_];
char* line_beg;
char* line_end;
va_list args;
Expand All @@ -902,9 +903,9 @@ acutest_message_(const char* fmt, ...)
return;

va_start(args, fmt);
vsnprintf(buffer, TEST_MSG_MAXSIZE, fmt, args);
vsnprintf(buffer, acutest_max_msg_, fmt, args);
va_end(args);
buffer[TEST_MSG_MAXSIZE-1] = '\0';
buffer[acutest_max_msg_-1] = '\0';

line_beg = buffer;
while(1) {
Expand Down Expand Up @@ -1292,10 +1293,10 @@ acutest_run_(const struct acutest_test_* test, int index, int master_index)
/* Windows has no fork(). So we propagate all info into the child
* through a command line arguments. */
snprintf(buffer, sizeof(buffer),
"%s --worker=%d %s --no-exec --no-summary %s --verbose=%d --color=%s -- \"%s\"",
"%s --worker=%d %s --no-exec --no-summary %s --verbose=%d --max-msg=%d --color=%s -- \"%s\"",
acutest_argv0_, index, acutest_timer_ ? "--time" : "",
acutest_tap_ ? "--tap" : "", acutest_verbose_level_,
acutest_colorize_ ? "always" : "never",
acutest_max_msg_, acutest_colorize_ ? "always" : "never",
test->name);
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(STARTUPINFO);
Expand Down Expand Up @@ -1543,6 +1544,7 @@ acutest_help_(void)
printf(" 2 ... As 1 and failed conditions (this is default)\n");
printf(" 3 ... As 1 and all conditions (and extended summary)\n");
printf(" -q, --quiet Same as --verbose=0\n");
printf(" --max-msg=NUMBER Set output limit to NUMBER\n");
printf(" --color[=WHEN] Enable colorized output\n");
printf(" (WHEN is one of 'auto', 'always', 'never')\n");
printf(" --no-color Same as --color=never\n");
Expand Down Expand Up @@ -1571,6 +1573,7 @@ static const ACUTEST_CMDLINE_OPTION_ acutest_cmdline_options_[] = {
{ 'l', "list", 'l', 0 },
{ 'v', "verbose", 'v', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_ },
{ 'q', "quiet", 'q', 0 },
{ 0, "max-msg", 'm', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_ },
{ 0, "color", 'c', ACUTEST_CMDLINE_OPTFLAG_OPTIONALARG_ },
{ 0, "no-color", 'C', 0 },
{ 'h', "help", 'h', 0 },
Expand Down Expand Up @@ -1642,6 +1645,10 @@ acutest_cmdline_callback_(int id, const char* arg)
acutest_verbose_level_ = 0;
break;

case 'm':
acutest_max_msg_ = (arg != NULL ? atoi(arg) : acutest_max_msg_);
break;

case 'c':
if(arg == NULL || strcmp(arg, "always") == 0) {
acutest_colorize_ = 1;
Expand Down

0 comments on commit cb3d59a

Please sign in to comment.