print.h 4.57 KB
Newer Older
1
/* clap: clar protocol, the traditional clar output format */
Vicent Marti committed
2

3
static void clar_print_clap_init(int test_count, int suite_count, const char *suite_names)
Vicent Marti committed
4 5 6
{
	(void)test_count;
	printf("Loaded %d suites: %s\n", (int)suite_count, suite_names);
7
	printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n");
Vicent Marti committed
8 9
}

10
static void clar_print_clap_shutdown(int test_count, int suite_count, int error_count)
Vicent Marti committed
11 12 13 14 15 16
{
	(void)test_count;
	(void)suite_count;
	(void)error_count;

	printf("\n\n");
Etienne Samson committed
17
	clar_report_all();
Vicent Marti committed
18 19
}

20
static void clar_print_clap_error(int num, const struct clar_report *report, const struct clar_error *error)
Vicent Marti committed
21 22 23
{
	printf("  %d) Failure:\n", num);

24
	printf("%s::%s [%s:%"PRIuZ"]\n",
Etienne Samson committed
25 26
		report->suite,
		report->test,
Vicent Marti committed
27 28 29 30 31 32 33 34 35 36 37 38
		error->file,
		error->line_number);

	printf("  %s\n", error->error_msg);

	if (error->description != NULL)
		printf("  %s\n", error->description);

	printf("\n");
	fflush(stdout);
}

39
static void clar_print_clap_ontest(const char *test_name, int test_number, enum cl_test_status status)
Vicent Marti committed
40 41 42
{
	(void)test_name;
	(void)test_number;
Vicent Marti committed
43 44 45 46 47

	switch(status) {
	case CL_TEST_OK: printf("."); break;
	case CL_TEST_FAILURE: printf("F"); break;
	case CL_TEST_SKIP: printf("S"); break;
Etienne Samson committed
48
	case CL_TEST_NOTRUN: printf("N"); break;
Vicent Marti committed
49 50
	}

Vicent Marti committed
51 52 53
	fflush(stdout);
}

54
static void clar_print_clap_onsuite(const char *suite_name, int suite_index)
Vicent Marti committed
55
{
Russell Belfer committed
56 57 58
	if (_clar.report_suite_names)
		printf("\n%s", suite_name);

Vicent Marti committed
59 60 61
	(void)suite_index;
}

62
static void clar_print_clap_onabort(const char *fmt, va_list arg)
63 64 65 66
{
	vfprintf(stderr, fmt, arg);
}

Edward Thomson committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/* tap: test anywhere protocol format */

static void clar_print_tap_init(int test_count, int suite_count, const char *suite_names)
{
	(void)test_count;
	(void)suite_count;
	(void)suite_names;
	printf("TAP version 13\n");
}

static void clar_print_tap_shutdown(int test_count, int suite_count, int error_count)
{
	(void)suite_count;
	(void)error_count;

	printf("1..%d\n", test_count);
}

static void clar_print_tap_error(int num, const struct clar_report *report, const struct clar_error *error)
{
	(void)num;
	(void)report;
	(void)error;
}

static void print_escaped(const char *str)
{
	char *c;

	while ((c = strchr(str, '\'')) != NULL) {
		printf("%.*s", (int)(c - str), str);
		printf("''");
		str = c + 1;
	}

	printf("%s", str);
}

static void clar_print_tap_ontest(const char *test_name, int test_number, enum cl_test_status status)
{
	const struct clar_error *error = _clar.last_report->errors;

	(void)test_name;
	(void)test_number;

	switch(status) {
	case CL_TEST_OK:
		printf("ok %d - %s::%s\n", test_number, _clar.active_suite, test_name);
		break;
	case CL_TEST_FAILURE:
		printf("not ok %d - %s::%s\n", test_number, _clar.active_suite, test_name);

		printf("    ---\n");
		printf("    reason: |\n");
		printf("      %s\n", error->error_msg);

		if (error->description)
			printf("      %s\n", error->description);

		printf("    at:\n");
		printf("      file: '"); print_escaped(error->file); printf("'\n");
		printf("      line: %" PRIuZ "\n", error->line_number);
129
		printf("      function: '%s'\n", error->function);
Edward Thomson committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
		printf("    ---\n");

		break;
	case CL_TEST_SKIP:
	case CL_TEST_NOTRUN:
		printf("ok %d - # SKIP %s::%s\n", test_number, _clar.active_suite, test_name);
		break;
	}

	fflush(stdout);
}

static void clar_print_tap_onsuite(const char *suite_name, int suite_index)
{
	printf("# start of suite %d: %s\n", suite_index, suite_name);
}

static void clar_print_tap_onabort(const char *fmt, va_list arg)
{
	printf("Bail out! ");
	vprintf(fmt, arg);
	fflush(stdout);
}

154 155
/* indirection between protocol output selection */

Edward Thomson committed
156
#define PRINT(FN, ...) do { \
157 158
		switch (_clar.output_format) { \
			case CL_OUTPUT_CLAP: \
Edward Thomson committed
159 160 161 162
				clar_print_clap_##FN (__VA_ARGS__); \
				break; \
			case CL_OUTPUT_TAP: \
				clar_print_tap_##FN (__VA_ARGS__); \
163 164 165 166 167 168
				break; \
			default: \
				abort(); \
		} \
	} while (0)

169 170
static void clar_print_init(int test_count, int suite_count, const char *suite_names)
{
171
	PRINT(init, test_count, suite_count, suite_names);
172 173 174 175
}

static void clar_print_shutdown(int test_count, int suite_count, int error_count)
{
176
	PRINT(shutdown, test_count, suite_count, error_count);
177 178 179 180
}

static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error)
{
181
	PRINT(error, num, report, error);
182 183 184 185
}

static void clar_print_ontest(const char *test_name, int test_number, enum cl_test_status status)
{
186
	PRINT(ontest, test_name, test_number, status);
187 188 189 190
}

static void clar_print_onsuite(const char *suite_name, int suite_index)
{
191
	PRINT(onsuite, suite_name, suite_index);
192 193
}

Vicent Marti committed
194 195 196 197
static void clar_print_onabort(const char *msg, ...)
{
	va_list argp;
	va_start(argp, msg);
198
	PRINT(onabort, msg, argp);
Vicent Marti committed
199 200
	va_end(argp);
}