<commit_before>
#include <libws.h>
#include <libws_log.h>
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include "jansson.h"
#include "cargo/cargo.h"
#include "libws_test_helpers.h"

typedef enum libws_autobahn_state_e
{
	LIBWS_AUTOBAHN_STATE_TEST = 0,
	LIBWS_AUTOBAHN_STATE_REPORT = 1,
	LIBWS_AUTOBAHN_STATE_TESTINFO = 2,
	LIBWS_AUTOBAHN_STATE_TESTSTATUS = 3,
	LIBWS_AUTOBAHN_STATE_COUNT = 4,
} libws_autobahn_state_t;

typedef struct libws_autobahn_args_s
{
	int ssl;
	int port;
	int range[2];
	size_t range_count;
	char *agentname;
	size_t agentname_count;
	char *server;
	int reports;
	int help;
	int debug;
	int nocolor;
	int all;
	int maxtime;
	int fulldata;
	int compact;
	const char *config;

	int skiprange[2];
	size_t skiprange_count;

	int *skip;
	size_t skip_count;

	int *tests;
	size_t test_count;

	char **extras;
	size_t extra_count;
} libws_autobahn_args_t;

libws_autobahn_state_t state;
libws_autobahn_args_t args;
int server_case_count = 0;
int current_case = -1;
int global_return = 0;

void draw_line()
{
	int i;

	for (i = 0; i < 80; i++)
		printf("-");

	printf("\n");
}

void print_linebreak(char *str, int width)
{
	char *s = strdup(str);
	char *start = s;
	char *prev = s;
	char *p = NULL;

	if (!s)
		return;

	p = strpbrk(s, " ");
	while (p != NULL)
	{
		if ((p - start) > width)
		{
			*prev = '\n';
			start = p;
		}

		prev = p;
		p = strpbrk(p + 1, " ");
	}

	libws_test_STATUS("%s", s);
	free(s);
}

void parse_test_info(char *msg)
{
	char headline[128];
	json_error_t error;
	json_t *json = NULL;
	char *id = NULL;
	char *description = NULL;

	if (!(json = json_loads(msg, 0, &error)))
	{
		fprintf(stderr, "Failed to load test info json: %s\n", error.text);
		return;
	}

	if (json_unpack_ex(json, &error, 0,
		"{"
			"s:s"
			"s:s"
		"}",
		"id", &id,
		"description", &description))
	{
		fprintf(stderr, "Failed to parse test info: %s\n", error.text);
		json_decref(json);
		return;
	}

	snprintf(headline, sizeof(headline), "[%*d] - %*s", 3, current_case, 6, id);

	if (args.compact)
	{
		libws_test_printf(stdout, MAGNETA, "%*s: ", 10, headline);
	}
	else
	{
		libws_test_HEADLINE(headline);
		print_linebreak(description, 80);
	}
}

void parse_test_status(char *msg)
{
	json_error_t error;
	json_t *json = NULL;
	char *behavior = NULL;

	if (!(json = json_loads(msg, 0, &error)))
	{
		fprintf(stderr, "Failed to load test info json: %s\n", error.text);
		return;
	}

	if (json_unpack_ex(json, &error, 0,
		"{"
			"s:s"
		"}",
		"behavior", &behavior))
	{
		fprintf(stderr, "Failed to parse test info: %s\n", error.text);
		json_decref(json);
		return;
	}

	if (!strcmp(behavior, "OK"))
	{
		if (args.compact)
		{
			libws_test_printf(stderr, BRIGHT, "[");
			libws_test_printf(stderr, GREEN, "SUCCESS");
			libws_test_printf(stderr, BRIGHT, "] ");
		}
		else
		{
			libws_test_SUCCESS("");
		}
	}
	else
	{
		if (args.compact)
		{
			libws_test_printf(stderr, BRIGHT, "[");
			libws_test_printf(stderr, RED, "FAILURE");
			libws_test_printf(stderr, BRIGHT, "] ");<commit_msg>Count "informational" as a success.<commit_after>
#include <libws.h>
#include <libws_log.h>
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include "jansson.h"
#include "cargo/cargo.h"
#include "libws_test_helpers.h"

typedef enum libws_autobahn_state_e
{
	LIBWS_AUTOBAHN_STATE_TEST = 0,
	LIBWS_AUTOBAHN_STATE_REPORT = 1,
	LIBWS_AUTOBAHN_STATE_TESTINFO = 2,
	LIBWS_AUTOBAHN_STATE_TESTSTATUS = 3,
	LIBWS_AUTOBAHN_STATE_COUNT = 4,
} libws_autobahn_state_t;

typedef struct libws_autobahn_args_s
{
	int ssl;
	int port;
	int range[2];
	size_t range_count;
	char *agentname;
	size_t agentname_count;
	char *server;
	int reports;
	int help;
	int debug;
	int nocolor;
	int all;
	int maxtime;
	int fulldata;
	int compact;
	const char *config;

	int skiprange[2];
	size_t skiprange_count;

	int *skip;
	size_t skip_count;

	int *tests;
	size_t test_count;

	char **extras;
	size_t extra_count;
} libws_autobahn_args_t;

libws_autobahn_state_t state;
libws_autobahn_args_t args;
int server_case_count = 0;
int current_case = -1;
int global_return = 0;

void draw_line()
{
	int i;

	for (i = 0; i < 80; i++)
		printf("-");

	printf("\n");
}

void print_linebreak(char *str, int width)
{
	char *s = strdup(str);
	char *start = s;
	char *prev = s;
	char *p = NULL;

	if (!s)
		return;

	p = strpbrk(s, " ");
	while (p != NULL)
	{
		if ((p - start) > width)
		{
			*prev = '\n';
			start = p;
		}

		prev = p;
		p = strpbrk(p + 1, " ");
	}

	libws_test_STATUS("%s", s);
	free(s);
}

void parse_test_info(char *msg)
{
	char headline[128];
	json_error_t error;
	json_t *json = NULL;
	char *id = NULL;
	char *description = NULL;

	if (!(json = json_loads(msg, 0, &error)))
	{
		fprintf(stderr, "Failed to load test info json: %s\n", error.text);
		return;
	}

	if (json_unpack_ex(json, &error, 0,
		"{"
			"s:s"
			"s:s"
		"}",
		"id", &id,
		"description", &description))
	{
		fprintf(stderr, "Failed to parse test info: %s\n", error.text);
		json_decref(json);
		return;
	}

	snprintf(headline, sizeof(headline), "[%*d] - %*s", 3, current_case, 6, id);

	if (args.compact)
	{
		libws_test_printf(stdout, MAGNETA, "%*s: ", 10, headline);
	}
	else
	{
		libws_test_HEADLINE(headline);
		print_linebreak(description, 80);
	}
}

void parse_test_status(char *msg)
{
	json_error_t error;
	json_t *json = NULL;
	char *behavior = NULL;

	if (!(json = json_loads(msg, 0, &error)))
	{
		fprintf(stderr, "Failed to load test info json: %s\n", error.text);
		return;
	}

	if (json_unpack_ex(json, &error, 0,
		"{"
			"s:s"
		"}",
		"behavior", &behavior))
	{
		fprintf(stderr, "Failed to parse test info: %s\n", error.text);
		json_decref(json);
		return;
	}

	if (!strcmp(behavior, "OK") || !strcmp(behavior, "INFORMATIONAL"))
	{
		if (args.compact)
		{
			libws_test_printf(stderr, BRIGHT, "[");
			libws_test_printf(stderr, GREEN, "SUCCESS");
			libws_test_printf(stderr, BRIGHT, "] ");
		}
		else
		{
			libws_test_SUCCESS("");
		}
	}
	else
	{
		if (args.compact)
		{
			libws_test_printf(stderr, BRIGHT, "[");
			libws_test_printf(stderr, RED, "FAILURE");
			libws_test_printf(stderr, BRIGHT, "] ");
{'fraction_non_alphanumeric': 0.15891597177678, 'fraction_numerical': 0.008659397049390635, 'mean_word_length': 4.0997547015535565, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3194294', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2693, 'n_words': 592}