<commit_before>/*****************************************************************************
 * This file is part of gfxprim library.                                     *
 *                                                                           *
 * Gfxprim is free software; you can redistribute it and/or                  *
 * modify it under the terms of the GNU Lesser General Public                *
 * License as published by the Free Software Foundation; either              *
 * version 2.1 of the License, or (at your option) any later version.        *
 *                                                                           *
 * Gfxprim is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Lesser General Public License for more details.                           *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public          *
 * License along with gfxprim; if not, write to the Free Software            *
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,                        *
 * Boston, MA  02110-1301  USA                                               *
 *                                                                           *
 * Copyright (C) 2009-2012 <NAME> <<EMAIL>>                       *
 *                                                                           *
 *****************************************************************************/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>

#include "tst_log.h"
#include "tst_job.h"
#include "tst_test.h"

int tst_warn(const char *fmt, ...)
{
	va_list va;
	int ret;

	va_start(va, fmt);
	ret = vfprintf(stderr, fmt, va);
	va_end(va);

	return ret;
}
	
static int run_test(const struct tst_test *test, FILE *html, FILE *json)
{
	struct tst_job job;

	job.test = test;

	/* 
	 * Flush the file before forking, otherwise
	 * there would be a copy of its buffers in both
	 * child and parent and the lines in the resulting
	 * file would be repeated several times.
	 */
	fflush(html);
	fflush(json);

	tst_job_run(&job);
	tst_job_wait(&job);

	tst_log_append(&job, html, TST_LOG_HTML);
	tst_log_append(&job, json, TST_LOG_JSON);

	/* Free the test message store */
	tst_msg_clear(&job.store);

	return job.result;
}

void tst_run_suite(const struct tst_suite *suite, const char *tst_name)
{
	unsigned int i;
	unsigned int counters[TST_MAX] = {};
	unsigned int counter = 0;
	int ret;

	fprintf(stderr, "Running \e[1;37m%s\e[0m\n\n", suite->suite_name);

	//TODO:
	FILE *html = tst_log_open(suite, "log.html", TST_LOG_HTML);
	FILE *json = tst_log_open(suite, "log.json", TST_LOG_JSON);

	for (i = 0; suite->tests[i].name != NULL; i++) {
		if (tst_name == NULL || !strcmp(tst_name, suite->tests[i].name)) {
			ret = run_test(&suite->tests[i], html, json);
			counters[ret]++;
			
			if (ret != TST_SKIPPED)
				counter++;
		}
	}

	tst_log_close(html, TST_LOG_HTML);
	tst_log_close(json, TST_LOG_JSON);

	fprintf(stderr, "\nSummary: succedded %u out of "
	                "%u %.2f%% (skipped %u)\n",
	                counters[0], counter, 100.00 * counters[0] / counter,
		        counters[TST_SKIPPED]);
}

void tst_list_suite(const struct tst_suite *suite)
{
	int i;

	fprintf(stderr, "Testsuite: \e[1;37m%s\e[0m\n\n", suite->suite_name);

	for (i = 0; suite->tests[i].name != NULL; i++)
		fprintf(stderr, "Test: \e[1;37m%s\e[0m\n", suite->tests[i].name);
}
<commit_msg>tests: framework: Avoid division by zero.<commit_after>/*****************************************************************************
 * This file is part of gfxprim library.                                     *
 *                                                                           *
 * Gfxprim is free software; you can redistribute it and/or                  *
 * modify it under the terms of the GNU Lesser General Public                *
 * License as published by the Free Software Foundation; either              *
 * version 2.1 of the License, or (at your option) any later version.        *
 *                                                                           *
 * Gfxprim is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Lesser General Public License for more details.                           *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public          *
 * License along with gfxprim; if not, write to the Free Software            *
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,                        *
 * Boston, MA  02110-1301  USA                                               *
 *                                                                           *
 * Copyright (C) 2009-2012 <NAME> <<EMAIL>>                       *
 *                                                                           *
 *****************************************************************************/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>

#include "tst_log.h"
#include "tst_job.h"
#include "tst_test.h"

int tst_warn(const char *fmt, ...)
{
	va_list va;
	int ret;

	va_start(va, fmt);
	ret = vfprintf(stderr, fmt, va);
	va_end(va);

	return ret;
}
	
static int run_test(const struct tst_test *test, FILE *html, FILE *json)
{
	struct tst_job job;

	job.test = test;

	/* 
	 * Flush the file before forking, otherwise
	 * there would be a copy of its buffers in both
	 * child and parent and the lines in the resulting
	 * file would be repeated several times.
	 */
	fflush(html);
	fflush(json);

	tst_job_run(&job);
	tst_job_wait(&job);

	tst_log_append(&job, html, TST_LOG_HTML);
	tst_log_append(&job, json, TST_LOG_JSON);

	/* Free the test message store */
	tst_msg_clear(&job.store);

	return job.result;
}

void tst_run_suite(const struct tst_suite *suite, const char *tst_name)
{
	unsigned int i;
	unsigned int counters[TST_MAX] = {};
	unsigned int counter = 0;
	int ret;

	fprintf(stderr, "Running \e[1;37m%s\e[0m\n\n", suite->suite_name);

	//TODO:
	FILE *html = tst_log_open(suite, "log.html", TST_LOG_HTML);
	FILE *json = tst_log_open(suite, "log.json", TST_LOG_JSON);

	for (i = 0; suite->tests[i].name != NULL; i++) {
		if (tst_name == NULL || !strcmp(tst_name, suite->tests[i].name)) {
			ret = run_test(&suite->tests[i], html, json);
			counters[ret]++;
			
			if (ret != TST_SKIPPED)
				counter++;
		}
	}

	tst_log_close(html, TST_LOG_HTML);
	tst_log_close(json, TST_LOG_JSON);

	float percents;
	
	if (counter == 0)
		percents = 100;
	else
		percents = 100.00 * counters[0] / counter;

	fprintf(stderr, "\nSummary: succedded %u out of "
	                "%u %.2f%% (skipped %u)\n",
	                counters[0], counter, percents,
		        counters[TST_SKIPPED]);
}

void tst_list_suite(const struct tst_suite *suite)
{
	int i;

	fprintf(stderr, "Testsuite: \e[1;37m%s\e[0m\n\n", suite->suite_name);

	for (i = 0; suite->tests[i].name != NULL; i++)
		fprintf(stderr, "Test: \e[1;37m%s\e[0m\n", suite->tests[i].name);
}

{'fraction_non_alphanumeric': 0.1506376195536663, 'fraction_numerical': 0.012221041445270989, 'mean_word_length': 1.9829635499207607, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4482220', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2221, 'n_words': 657}