summaryrefslogtreecommitdiff
path: root/tests-clay/clay_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clay/clay_main.c')
-rw-r--r--tests-clay/clay_main.c533
1 files changed, 349 insertions, 184 deletions
diff --git a/tests-clay/clay_main.c b/tests-clay/clay_main.c
index da90872ce..4ad6fc467 100644
--- a/tests-clay/clay_main.c
+++ b/tests-clay/clay_main.c
@@ -4,13 +4,12 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
+#include <stdarg.h>
/* required for sandboxing */
#include <sys/types.h>
#include <sys/stat.h>
-#define clay_print(...) printf(__VA_ARGS__)
-
#ifdef _WIN32
# include <windows.h>
# include <io.h>
@@ -82,7 +81,6 @@ static struct {
struct clay_func {
const char *name;
void (*ptr)(void);
- size_t suite_n;
};
struct clay_suite {
@@ -93,10 +91,268 @@ struct clay_suite {
size_t test_count;
};
+/* From clay_print_*.c */
+static void clay_print_init(int test_count, int suite_count, const char *suite_names);
+static void clay_print_shutdown(int test_count, int suite_count, int error_count);
+static void clay_print_error(int num, const struct clay_error *error);
+static void clay_print_ontest(const char *test_name, int test_number, int failed);
+static void clay_print_onsuite(const char *suite_name);
+static void clay_print_onabort(const char *msg, ...);
+
/* From clay_sandbox.c */
static void clay_unsandbox(void);
static int clay_sandbox(void);
+/* Autogenerated test data by clay */
+static const struct clay_func _clay_cb_config_stress[] = {
+ {"dont_break_on_invalid_input", &test_config_stress__dont_break_on_invalid_input}
+};
+static const struct clay_func _clay_cb_core_dirent[] = {
+ {"dont_traverse_dot", &test_core_dirent__dont_traverse_dot},
+ {"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders},
+ {"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder},
+ {"traverse_subfolder", &test_core_dirent__traverse_subfolder},
+ {"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames}
+};
+static const struct clay_func _clay_cb_core_filebuf[] = {
+ {"0", &test_core_filebuf__0},
+ {"1", &test_core_filebuf__1},
+ {"2", &test_core_filebuf__2}
+};
+static const struct clay_func _clay_cb_core_oid[] = {
+ {"streq", &test_core_oid__streq}
+};
+static const struct clay_func _clay_cb_core_path[] = {
+ {"0", &test_core_path__0},
+ {"1", &test_core_path__1},
+ {"2", &test_core_path__2},
+ {"5", &test_core_path__5},
+ {"6", &test_core_path__6}
+};
+static const struct clay_func _clay_cb_core_rmdir[] = {
+ {"delete_recursive", &test_core_rmdir__delete_recursive},
+ {"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir}
+};
+static const struct clay_func _clay_cb_core_string[] = {
+ {"0", &test_core_string__0},
+ {"1", &test_core_string__1}
+};
+static const struct clay_func _clay_cb_core_strtol[] = {
+ {"int32", &test_core_strtol__int32},
+ {"int64", &test_core_strtol__int64}
+};
+static const struct clay_func _clay_cb_core_vector[] = {
+ {"0", &test_core_vector__0},
+ {"1", &test_core_vector__1},
+ {"2", &test_core_vector__2}
+};
+static const struct clay_func _clay_cb_index_rename[] = {
+ {"single_file", &test_index_rename__single_file}
+};
+static const struct clay_func _clay_cb_network_remotes[] = {
+ {"fnmatch", &test_network_remotes__fnmatch},
+ {"parsing", &test_network_remotes__parsing},
+ {"refspec_parsing", &test_network_remotes__refspec_parsing},
+ {"transform", &test_network_remotes__transform}
+};
+static const struct clay_func _clay_cb_object_raw_chars[] = {
+ {"build_valid_oid_from_raw_bytes", &test_object_raw_chars__build_valid_oid_from_raw_bytes},
+ {"find_invalid_chars_in_oid", &test_object_raw_chars__find_invalid_chars_in_oid}
+};
+static const struct clay_func _clay_cb_object_raw_compare[] = {
+ {"compare_allocfmt_oids", &test_object_raw_compare__compare_allocfmt_oids},
+ {"compare_fmt_oids", &test_object_raw_compare__compare_fmt_oids},
+ {"compare_pathfmt_oids", &test_object_raw_compare__compare_pathfmt_oids},
+ {"succeed_on_copy_oid", &test_object_raw_compare__succeed_on_copy_oid},
+ {"succeed_on_oid_comparison_equal", &test_object_raw_compare__succeed_on_oid_comparison_equal},
+ {"succeed_on_oid_comparison_greater", &test_object_raw_compare__succeed_on_oid_comparison_greater},
+ {"succeed_on_oid_comparison_lesser", &test_object_raw_compare__succeed_on_oid_comparison_lesser}
+};
+static const struct clay_func _clay_cb_object_raw_convert[] = {
+ {"succeed_on_oid_to_string_conversion", &test_object_raw_convert__succeed_on_oid_to_string_conversion},
+ {"succeed_on_oid_to_string_conversion_big", &test_object_raw_convert__succeed_on_oid_to_string_conversion_big}
+};
+static const struct clay_func _clay_cb_object_raw_fromstr[] = {
+ {"fail_on_invalid_oid_string", &test_object_raw_fromstr__fail_on_invalid_oid_string},
+ {"succeed_on_valid_oid_string", &test_object_raw_fromstr__succeed_on_valid_oid_string}
+};
+static const struct clay_func _clay_cb_object_raw_hash[] = {
+ {"hash_buffer_in_single_call", &test_object_raw_hash__hash_buffer_in_single_call},
+ {"hash_by_blocks", &test_object_raw_hash__hash_by_blocks},
+ {"hash_commit_object", &test_object_raw_hash__hash_commit_object},
+ {"hash_junk_data", &test_object_raw_hash__hash_junk_data},
+ {"hash_multi_byte_object", &test_object_raw_hash__hash_multi_byte_object},
+ {"hash_one_byte_object", &test_object_raw_hash__hash_one_byte_object},
+ {"hash_tag_object", &test_object_raw_hash__hash_tag_object},
+ {"hash_tree_object", &test_object_raw_hash__hash_tree_object},
+ {"hash_two_byte_object", &test_object_raw_hash__hash_two_byte_object},
+ {"hash_vector", &test_object_raw_hash__hash_vector},
+ {"hash_zero_length_object", &test_object_raw_hash__hash_zero_length_object}
+};
+static const struct clay_func _clay_cb_object_raw_short[] = {
+ {"oid_shortener_no_duplicates", &test_object_raw_short__oid_shortener_no_duplicates},
+ {"oid_shortener_stresstest_git_oid_shorten", &test_object_raw_short__oid_shortener_stresstest_git_oid_shorten}
+};
+static const struct clay_func _clay_cb_object_raw_size[] = {
+ {"validate_oid_size", &test_object_raw_size__validate_oid_size}
+};
+static const struct clay_func _clay_cb_object_raw_type2string[] = {
+ {"check_type_is_loose", &test_object_raw_type2string__check_type_is_loose},
+ {"convert_string_to_type", &test_object_raw_type2string__convert_string_to_type},
+ {"convert_type_to_string", &test_object_raw_type2string__convert_type_to_string}
+};
+static const struct clay_func _clay_cb_object_tree_frompath[] = {
+ {"fail_when_processing_an_invalid_path", &test_object_tree_frompath__fail_when_processing_an_invalid_path},
+ {"fail_when_processing_an_unknown_tree_segment", &test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment},
+ {"retrieve_tree_from_path_to_treeentry", &test_object_tree_frompath__retrieve_tree_from_path_to_treeentry}
+};
+static const struct clay_func _clay_cb_status_single[] = {
+ {"hash_single_file", &test_status_single__hash_single_file}
+};
+static const struct clay_func _clay_cb_status_worktree[] = {
+ {"empty_repository", &test_status_worktree__empty_repository},
+ {"whole_repository", &test_status_worktree__whole_repository}
+};
+
+static const struct clay_suite _clay_suites[] = {
+ {
+ "config::stress",
+ {"initialize", &test_config_stress__initialize},
+ {"cleanup", &test_config_stress__cleanup},
+ _clay_cb_config_stress, 1
+ },
+ {
+ "core::dirent",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_dirent, 5
+ },
+ {
+ "core::filebuf",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_filebuf, 3
+ },
+ {
+ "core::oid",
+ {"initialize", &test_core_oid__initialize},
+ {NULL, NULL},
+ _clay_cb_core_oid, 1
+ },
+ {
+ "core::path",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_path, 5
+ },
+ {
+ "core::rmdir",
+ {"initialize", &test_core_rmdir__initialize},
+ {NULL, NULL},
+ _clay_cb_core_rmdir, 2
+ },
+ {
+ "core::string",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_string, 2
+ },
+ {
+ "core::strtol",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_strtol, 2
+ },
+ {
+ "core::vector",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_core_vector, 3
+ },
+ {
+ "index::rename",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_index_rename, 1
+ },
+ {
+ "network::remotes",
+ {"initialize", &test_network_remotes__initialize},
+ {"cleanup", &test_network_remotes__cleanup},
+ _clay_cb_network_remotes, 4
+ },
+ {
+ "object::raw::chars",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_chars, 2
+ },
+ {
+ "object::raw::compare",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_compare, 7
+ },
+ {
+ "object::raw::convert",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_convert, 2
+ },
+ {
+ "object::raw::fromstr",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_fromstr, 2
+ },
+ {
+ "object::raw::hash",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_hash, 11
+ },
+ {
+ "object::raw::short",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_short, 2
+ },
+ {
+ "object::raw::size",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_size, 1
+ },
+ {
+ "object::raw::type2string",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_object_raw_type2string, 3
+ },
+ {
+ "object::tree::frompath",
+ {"initialize", &test_object_tree_frompath__initialize},
+ {"cleanup", &test_object_tree_frompath__cleanup},
+ _clay_cb_object_tree_frompath, 3
+ },
+ {
+ "status::single",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_status_single, 1
+ },
+ {
+ "status::worktree",
+ {"initialize", &test_status_worktree__initialize},
+ {"cleanup", &test_status_worktree__cleanup},
+ _clay_cb_status_worktree, 2
+ }
+};
+
+static size_t _clay_suite_count = 22;
+static size_t _clay_callback_count = 65;
+
+/* Core test functions */
static void
clay_run_test(
const struct clay_func *test,
@@ -128,28 +384,11 @@ clay_run_test(
_clay.local_cleanup = NULL;
_clay.local_cleanup_payload = NULL;
- clay_print("%c", (_clay.suite_errors > error_st) ? 'F' : '.');
-}
-
-static void
-clay_print_error(int num, const struct clay_error *error)
-{
- clay_print(" %d) Failure:\n", num);
-
- clay_print("%s::%s (%s) [%s:%d] [-t%d]\n",
- error->suite,
- error->test,
- "no description",
- error->file,
- error->line_number,
- error->test_number);
-
- clay_print(" %s\n", error->error_msg);
-
- if (error->description != NULL)
- clay_print(" %s\n", error->description);
-
- clay_print("\n");
+ clay_print_ontest(
+ test->name,
+ _clay.test_count,
+ (_clay.suite_errors > error_st)
+ );
}
static void
@@ -166,6 +405,8 @@ clay_report_errors(void)
free(error);
error = next;
}
+
+ _clay.errors = _clay.last_error = NULL;
}
static void
@@ -174,6 +415,8 @@ clay_run_suite(const struct clay_suite *suite)
const struct clay_func *test = suite->tests;
size_t i;
+ clay_print_onsuite(suite->name);
+
_clay.active_suite = suite->name;
_clay.suite_errors = 0;
@@ -183,6 +426,7 @@ clay_run_suite(const struct clay_suite *suite)
}
}
+#if 0 /* temporarily disabled */
static void
clay_run_single(const struct clay_func *test,
const struct clay_suite *suite)
@@ -193,24 +437,20 @@ clay_run_single(const struct clay_func *test,
clay_run_test(test, &suite->initialize, &suite->cleanup);
}
+#endif
static void
clay_usage(const char *arg)
{
printf("Usage: %s [options]\n\n", arg);
printf("Options:\n");
- printf(" -tXX\t\tRun only the test number XX\n");
+// printf(" -tXX\t\tRun only the test number XX\n");
printf(" -sXX\t\tRun only the suite number XX\n");
exit(-1);
}
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)
+clay_parse_args(int argc, char **argv)
{
int i;
@@ -229,27 +469,13 @@ clay_parse_args(
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);
+ if ((size_t)num >= _clay_suite_count) {
+ clay_print_onabort("Suite number %d does not exist.\n", num);
exit(-1);
}
- clay_print("Started (%s::*)\n", suites[num].name);
- clay_run_suite(&suites[num]);
+ clay_run_suite(&_clay_suites[num]);
break;
default:
@@ -259,15 +485,13 @@ clay_parse_args(
}
static int
-clay_test(
- int argc, char **argv,
- const char *suites_str,
- const struct clay_func *callbacks,
- size_t cb_count,
- const struct clay_suite *suites,
- size_t suite_count)
+clay_test(int argc, char **argv)
{
- clay_print("Loaded %d suites: %s\n", (int)suite_count, suites_str);
+ clay_print_init(
+ (int)_clay_callback_count,
+ (int)_clay_suite_count,
+ ""
+ );
if (clay_sandbox() < 0) {
fprintf(stderr,
@@ -276,21 +500,18 @@ clay_test(
}
if (argc > 1) {
- clay_parse_args(argc, argv,
- callbacks, cb_count, suites, suite_count);
-
+ clay_parse_args(argc, argv);
} else {
size_t i;
- clay_print("Started\n");
-
- for (i = 0; i < suite_count; ++i) {
- const struct clay_suite *s = &suites[i];
- clay_run_suite(s);
- }
+ for (i = 0; i < _clay_suite_count; ++i)
+ clay_run_suite(&_clay_suites[i]);
}
- clay_print("\n\n");
- clay_report_errors();
+ clay_print_shutdown(
+ (int)_clay_callback_count,
+ (int)_clay_suite_count,
+ _clay.total_errors
+ );
clay_unsandbox();
return _clay.total_errors;
@@ -335,7 +556,7 @@ clay__assert(
if (should_abort) {
if (!_clay.trampoline_enabled) {
- fprintf(stderr,
+ clay_print_onabort(
"Fatal error: a cleanup method raised an exception.");
exit(-1);
}
@@ -659,124 +880,68 @@ cl_fs_cleanup(void)
#endif
-static const struct clay_func _all_callbacks[] = {
- {"dont_traverse_dot", &test_core_dirent__dont_traverse_dot, 0},
- {"traverse_subfolder", &test_core_dirent__traverse_subfolder, 0},
- {"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder, 0},
- {"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders, 0},
- {"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames, 0},
- {"0", &test_core_filebuf__0, 1},
- {"1", &test_core_filebuf__1, 1},
- {"2", &test_core_filebuf__2, 1},
- {"streq", &test_core_oid__streq, 2},
- {"0", &test_core_path__0, 3},
- {"1", &test_core_path__1, 3},
- {"2", &test_core_path__2, 3},
- {"5", &test_core_path__5, 3},
- {"6", &test_core_path__6, 3},
- {"delete_recursive", &test_core_rmdir__delete_recursive, 4},
- {"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir, 4},
- {"0", &test_core_string__0, 5},
- {"1", &test_core_string__1, 5},
- {"int32", &test_core_strtol__int32, 6},
- {"int64", &test_core_strtol__int64, 6},
- {"0", &test_core_vector__0, 7},
- {"1", &test_core_vector__1, 7},
- {"2", &test_core_vector__2, 7},
- {"parsing", &test_network_remotes__parsing, 8},
- {"refspec_parsing", &test_network_remotes__refspec_parsing, 8},
- {"fnmatch", &test_network_remotes__fnmatch, 8},
- {"transform", &test_network_remotes__transform, 8},
- {"retrieve_tree_from_path_to_treeentry", &test_object_tree_frompath__retrieve_tree_from_path_to_treeentry, 9},
- {"fail_when_processing_an_unknown_tree_segment", &test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment, 9},
- {"fail_when_processing_an_invalid_path", &test_object_tree_frompath__fail_when_processing_an_invalid_path, 9},
- {"hash_single_file", &test_status_single__hash_single_file, 10},
- {"whole_repository", &test_status_worktree__whole_repository, 11},
- {"empty_repository", &test_status_worktree__empty_repository, 11}
-};
+static void clay_print_init(int test_count, int suite_count, const char *suite_names)
+{
+ (void)suite_names;
+ (void)suite_count;
+ printf("TAP version 13\n");
+ printf("1..%d\n", test_count);
+}
-static const struct clay_suite _all_suites[] = {
- {
- "core::dirent",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[0], 5
- },
- {
- "core::filebuf",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[5], 3
- },
- {
- "core::oid",
- {"initialize", &test_core_oid__initialize, 2},
- {NULL, NULL, 0},
- &_all_callbacks[8], 1
- },
- {
- "core::path",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[9], 5
- },
- {
- "core::rmdir",
- {"initialize", &test_core_rmdir__initialize, 4},
- {NULL, NULL, 0},
- &_all_callbacks[14], 2
- },
- {
- "core::string",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[16], 2
- },
- {
- "core::strtol",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[18], 2
- },
- {
- "core::vector",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[20], 3
- },
- {
- "network::remotes",
- {"initialize", &test_network_remotes__initialize, 8},
- {"cleanup", &test_network_remotes__cleanup, 8},
- &_all_callbacks[23], 4
- },
- {
- "object::tree::frompath",
- {"initialize", &test_object_tree_frompath__initialize, 9},
- {"cleanup", &test_object_tree_frompath__cleanup, 9},
- &_all_callbacks[27], 3
- },
- {
- "status::single",
- {NULL, NULL, 0},
- {NULL, NULL, 0},
- &_all_callbacks[30], 1
- },
- {
- "status::worktree",
- {"initialize", &test_status_worktree__initialize, 11},
- {"cleanup", &test_status_worktree__cleanup, 11},
- &_all_callbacks[31], 2
- }
-};
+static void clay_print_shutdown(int test_count, int suite_count, int error_count)
+{
+ (void)test_count;
+ (void)suite_count;
+ (void)error_count;
+
+ printf("\n");
+}
+
+static void clay_print_error(int num, const struct clay_error *error)
+{
+ (void)num;
+
+ printf(" ---\n");
+ printf(" message : %s\n", error->error_msg);
+ printf(" severity: fail\n");
+ printf(" suite : %s\n", error->suite);
+ printf(" test : %s\n", error->test);
+ printf(" file : %s\n", error->file);
+ printf(" line : %d\n", error->line_number);
+
+ if (error->description != NULL)
+ printf(" description: %s\n", error->description);
+
+ printf(" ...\n");
+}
+
+static void clay_print_ontest(const char *test_name, int test_number, int failed)
+{
+ printf("%s %d - %s\n",
+ failed ? "not ok" : "ok",
+ test_number,
+ test_name
+ );
+
+ clay_report_errors();
+}
+
+static void clay_print_onsuite(const char *suite_name)
+{
+ printf("# *** %s ***\n", suite_name);
+}
+
+static void clay_print_onabort(const char *msg, ...)
+{
+ va_list argp;
+ va_start(argp, msg);
+ fprintf(stdout, "Bail out! ");
+ vfprintf(stdout, msg, argp);
+ va_end(argp);
+}
-static const char _suites_str[] = "core::dirent, core::filebuf, core::oid, core::path, core::rmdir, core::string, core::strtol, core::vector, network::remotes, object::tree::frompath, status::single, status::worktree";
int _MAIN_CC main(int argc, char *argv[])
{
- return clay_test(
- argc, argv, _suites_str,
- _all_callbacks, 33,
- _all_suites, 12
- );
+ return clay_test(argc, argv);
}