Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@

* When skipping tests, don't clutter the output with the full skipped test.
* Store the failure position for failed tests, include in test summary.
* Eliminate bs_test().
* Make it easy to run a single case, or a single set.
* Use bs_test_case_init(), bs_test_case_fini() for the overloaded prepare/report.
17 changes: 0 additions & 17 deletions include/libbase/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,6 @@ bool bs_test_failed(bs_test_t *test_ptr);
*/
void *bs_test_context(bs_test_t *test_ptr);

/**
* Runs test sets.
*
* @param test_sets
* @param argc
* @param argv
* @param param_ptr Optional, points to a @ref bs_test_param_t and
* specifies parameters for the test environment.
*
* @return 0 on success or the number of failed test sets.
*/
int bs_test(
const bs_test_set_t *test_sets,
int argc,
const char **argv,
const bs_test_param_t *param_ptr);

/**
* Runs test sets.
*
Expand Down
98 changes: 0 additions & 98 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,104 +186,6 @@ static const char *bs_test_report_separator_ptr =

/* == Exported Functions =================================================== */

/* ------------------------------------------------------------------------- */
int bs_test(
const bs_test_set_t *test_sets,
int argc,
const char **argv,
const bs_test_param_t *param_ptr)
{
struct bs_test_report report = {};
int i;
bool run_set;
bs_dllist_t failed_tests = {};
struct bs_test_env env = {};
const bs_arg_t bs_test_args[] = {
BS_ARG_STRING(
"test_filter",
"Filter to apply for selecting tests. Uses fnmatch on the full name.",
"*",
&env.filter_ptr),
BS_ARG_STRING(
"test_data_directory",
"Directory to use for test data. Setting this flag takes precedence "
"over the parameter specified through the `bs_test_param_t` arg to "
"bs_test().",
NULL,
&env.data_dir_ptr),
BS_ARG_SENTINEL()
};

if (NULL == test_sets) return 0;
if (!bs_arg_parse(bs_test_args, BS_ARG_MODE_NO_EXTRA, &argc, argv)) {
bs_arg_print_usage(stderr, bs_test_args);
return -1;
}

if (NULL == env.data_dir_ptr &&
NULL != param_ptr &&
NULL != param_ptr->test_data_dir_ptr) {
env.data_dir_ptr = logged_strdup(param_ptr->test_data_dir_ptr);
if (NULL == env.data_dir_ptr) return -1;
}

bs_test_tcode_init();

/** List of all failed tests. */
while (NULL != test_sets->name_ptr) {

/* If any args are given, check if the name matches. */
run_set = 1 >= argc;
for (i = 1; i < argc; i++) {
if (0 == strcmp(argv[i], test_sets->name_ptr)) {
run_set = true;;
}
}

if (run_set && test_sets->enabled) {
if (bs_test_set(test_sets, &env, &failed_tests)) {
report.failed++;
} else {
report.succeeded++;
}
} else {
report.skipped++;
}

report.total++;
test_sets++;
}

if (report.failed) {
bs_test_attr(BS_TEST_ATTR_FAIL);
bs_test_puts("FAILED: % 66d/% 3d\n",
report.failed, report.total);

/* Print all failed tests. */
struct bs_test_fail_node *fnode_ptr;
while (NULL != (fnode_ptr = (struct bs_test_fail_node*)
bs_dllist_pop_front(&failed_tests))) {
bs_test_puts(" %s\n", fnode_ptr->full_name_ptr);
bs_test_case_fail_node_destroy(fnode_ptr);
}
bs_test_attr(BS_TEST_ATTR_RESET);
} else if (report.succeeded) {
bs_test_attr(BS_TEST_ATTR_SUCCESS);
bs_test_puts("SUCCESS: % 65d/% 3d\n",
report.succeeded, report.total);
bs_test_attr(BS_TEST_ATTR_RESET);
}
if (report.skipped) {
bs_test_attr(BS_TEST_ATTR_SKIP);
bs_test_puts("SKIPPED: % 65d/% 3d\n", report.skipped, report.total);
bs_test_attr(BS_TEST_ATTR_RESET);
}

BS_ASSERT(0 == bs_dllist_size(&failed_tests));
bs_arg_cleanup(bs_test_args);
return report.failed;
}

/* ------------------------------------------------------------------------- */
int bs_test_sets(
const bs_test_set_t** test_set_ptrs,
Expand Down
Loading