Example #1
0
static void
clay_parse_args(int argc, char **argv)
{
	int i;

	for (i = 1; i < argc; ++i) {
		char *argument = argv[i];
		char action;
		int num;

		if (argument[0] != '-')
			clay_usage(argv[0]);

		action = argument[1];
		num = strtol(argument + 2, &argument, 10);

		if (*argument != '\0' || num < 0)
			clay_usage(argv[0]);

		switch (action) {
		case 's':
			if ((size_t)num >= _clay_suite_count) {
				clay_print_onabort("Suite number %d does not exist.\n", num);
				exit(-1);
			}

			clay_run_suite(&_clay_suites[num]);
			break;

		default:
			clay_usage(argv[0]);
		}
	}
}
Example #2
0
static void
clay_parse_args(
	int argc, char **argv,
	const struct clay_func *callbacks,
	size_t cb_count,
	const struct clay_suite *suites,
	size_t suite_count)
{
	int i;

	for (i = 1; i < argc; ++i) {
		char *argument = argv[i];
		char action;
		int num;

		if (argument[0] != '-')
			clay_usage(argv[0]);

		action = argument[1];
		num = strtol(argument + 2, &argument, 10);

		if (*argument != '\0' || num < 0)
			clay_usage(argv[0]);

		switch (action) {
		case 't':
			if ((size_t)num >= cb_count) {
				fprintf(stderr, "Test number %d does not exist.\n", num);
				exit(-1);
			}

			clay_print("Started (%s::%s)\n",
				suites[callbacks[num].suite_n].name,
				callbacks[num].name);

			clay_run_single(&callbacks[num], &suites[callbacks[num].suite_n]);
			break;

		case 's':
			if ((size_t)num >= suite_count) {
				fprintf(stderr, "Suite number %d does not exist.\n", num);
				exit(-1);
			}

			clay_print("Started (%s::*)\n", suites[num].name);
			clay_run_suite(&suites[num]);
			break;

		default:
			clay_usage(argv[0]);
		}
	}
}