Commit d1a721c5 by Vicent Marti

clay: Bump to 0.9.0, add TAP support

Comes with schu's stress tests for config files. Hopefully the diffs
will stay minimal from now on.
parent 2ba14f23
......@@ -4,13 +4,13 @@ from __future__ import with_statement
from string import Template
import re, fnmatch, os
VERSION = "0.8.0"
VERSION = "0.9.0"
TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*(void)?\s*\))\s*\{"
TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*void\s*\))\s*\{"
CLAY_HEADER = """
/*
* Clay v0.7.0
* Clay v0.9.0
*
* This is an autogenerated file. Do not modify.
* To add new unit tests or suites, regenerate the whole
......@@ -18,27 +18,17 @@ CLAY_HEADER = """
*/
"""
TEMPLATE_SUITE = Template(
r"""
{
"${clean_name}",
${initialize},
${cleanup},
${cb_ptr}, ${cb_count}
}
""")
def main():
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-c', '--clay-path', dest='clay_path')
parser.add_option('-v', '--report-to', dest='print_mode', default='stdout')
parser.add_option('-v', '--report-to', dest='print_mode', default='default')
options, args = parser.parse_args()
for folder in args:
for folder in args or ['.']:
builder = ClayTestBuilder(folder,
clay_path = options.clay_path,
print_mode = options.print_mode)
......@@ -47,17 +37,22 @@ def main():
class ClayTestBuilder:
def __init__(self, path, clay_path = None, print_mode = 'stdout'):
def __init__(self, path, clay_path = None, print_mode = 'default'):
self.declarations = []
self.callbacks = []
self.suites = []
self.suite_list = []
self.suite_names = []
self.callback_data = {}
self.suite_data = {}
self.clay_path = os.path.abspath(clay_path) if clay_path else None
self.print_mode = print_mode
self.path = os.path.abspath(path)
self.modules = ["clay_sandbox.c", "clay_fixtures.c", "clay_fs.c"]
self.modules = [
"clay_sandbox.c",
"clay_fixtures.c",
"clay_fs.c"
]
self.modules.append("clay_print_%s.c" % print_mode)
print("Loading test suites...")
......@@ -66,7 +61,6 @@ class ClayTestBuilder:
module_root = [c for c in module_root.split(os.sep) if c]
tests_in_module = fnmatch.filter(files, "*.c")
tests_in_module.sort()
for test_file in tests_in_module:
full_path = os.path.join(root, test_file)
......@@ -75,51 +69,107 @@ class ClayTestBuilder:
with open(full_path) as f:
self._process_test_file(test_name, f.read())
if not self.suites:
if not self.suite_data:
raise RuntimeError(
'No tests found under "%s"' % folder_name)
def render(self):
main_file = os.path.join(self.path, 'clay_main.c')
with open(main_file, "w") as out:
template = Template(self._load_file('clay.c'))
out.write(self._render_main())
header_file = os.path.join(self.path, 'clay.h')
with open(header_file, "w") as out:
out.write(self._render_header())
print ('Written Clay suite to "%s"' % self.path)
#####################################################
# Internal methods
#####################################################
def _render_cb(self, cb):
return '{"%s", &%s}' % (cb['short_name'], cb['symbol'])
def _render_suite(self, suite):
template = Template(
r"""
{
"${clean_name}",
${initialize},
${cleanup},
${cb_ptr}, ${cb_count}
}
""")
output = template.substitute(
clay_print = self._get_print_method(),
clay_modules = self._get_modules(),
callbacks = {}
for cb in ['initialize', 'cleanup']:
callbacks[cb] = (self._render_cb(suite[cb])
if suite[cb] else "{NULL, NULL}")
return template.substitute(
clean_name = suite['name'].replace("_", "::"),
initialize = callbacks['initialize'],
cleanup = callbacks['cleanup'],
cb_ptr = "_clay_cb_%s" % suite['name'],
cb_count = suite['cb_count']
).strip()
suites_str = ", ".join(self.suite_list),
def _render_callbacks(self, suite_name, callbacks):
template = Template(
r"""
static const struct clay_func _clay_cb_${suite_name}[] = {
${callbacks}
};
""")
callbacks = [
self._render_cb(cb)
for cb in callbacks
if cb['short_name'] not in ('initialize', 'cleanup')
]
return template.substitute(
suite_name = suite_name,
callbacks = ",\n\t".join(callbacks)
).strip()
test_callbacks = ",\n\t".join(self.callbacks),
cb_count = len(self.callbacks),
def _render_header(self):
template = Template(self._load_file('clay.h'))
test_suites = ",\n\t".join(self.suites),
suite_count = len(self.suites),
)
declarations = "\n".join(
"extern %s;" % decl
for decl in sorted(self.declarations)
)
out.write(output)
return template.substitute(
extern_declarations = declarations,
)
header_file = os.path.join(self.path, 'clay.h')
with open(header_file, "w") as out:
template = Template(self._load_file('clay.h'))
def _render_main(self):
template = Template(self._load_file('clay.c'))
suite_names = sorted(self.suite_names)
output = template.substitute(
extern_declarations = "\n".join(self.declarations),
)
suite_data = [
self._render_suite(self.suite_data[s])
for s in suite_names
]
out.write(output)
callbacks = [
self._render_callbacks(s, self.callback_data[s])
for s in suite_names
]
print ('Written Clay suite to "%s"' % self.path)
callback_count = sum(
len(cbs) for cbs in self.callback_data.values()
)
#####################################################
# Internal methods
#####################################################
def _get_print_method(self):
return {
'stdout' : 'printf(__VA_ARGS__)',
'stderr' : 'fprintf(stderr, __VA_ARGS__)',
'silent' : ''
}[self.print_mode]
return template.substitute(
clay_modules = self._get_modules(),
clay_callbacks = "\n".join(callbacks),
clay_suites = ",\n\t".join(suite_data),
clay_suite_count = len(suite_data),
clay_callback_count = callback_count,
)
def _load_file(self, filename):
if self.clay_path:
......@@ -151,52 +201,67 @@ class ClayTestBuilder:
return comment
def _process_test_file(self, test_name, contents):
regex_string = TEST_FUNC_REGEX % test_name
def _process_test_file(self, suite_name, contents):
regex_string = TEST_FUNC_REGEX % suite_name
regex = re.compile(regex_string, re.MULTILINE)
callbacks = []
initialize = cleanup = "{NULL, NULL, 0}"
initialize = cleanup = None
for (declaration, symbol, short_name, _) in regex.findall(contents):
self.declarations.append("extern %s;" % declaration)
func_ptr = '{"%s", &%s, %d}' % (
short_name, symbol, len(self.suites)
)
for (declaration, symbol, short_name) in regex.findall(contents):
data = {
"short_name" : short_name,
"declaration" : declaration,
"symbol" : symbol
}
if short_name == 'initialize':
initialize = func_ptr
initialize = data
elif short_name == 'cleanup':
cleanup = func_ptr
cleanup = data
else:
callbacks.append(func_ptr)
callbacks.append(data)
if not callbacks:
return
clean_name = test_name.replace("_", "::")
tests_in_suite = len(callbacks)
suite = TEMPLATE_SUITE.substitute(
clean_name = clean_name,
initialize = initialize,
cleanup = cleanup,
cb_ptr = "&_all_callbacks[%d]" % len(self.callbacks),
cb_count = len(callbacks)
).strip()
suite = {
"name" : suite_name,
"initialize" : initialize,
"cleanup" : cleanup,
"cb_count" : tests_in_suite
}
if initialize:
self.declarations.append(initialize['declaration'])
if cleanup:
self.declarations.append(cleanup['declaration'])
self.declarations += [
callback['declaration']
for callback in callbacks
]
callbacks.sort(key=lambda x: x['short_name'])
self.callback_data[suite_name] = callbacks
self.suite_data[suite_name] = suite
self.suite_names.append(suite_name)
self.callbacks += callbacks
self.suites.append(suite)
self.suite_list.append(clean_name)
print(" %s (%d tests)" % (suite_name, tests_in_suite))
print(" %s (%d tests)" % (clean_name, len(callbacks)))
CLAY_FILES = {
"clay.c" : r"""eJy9GWtT20jys/wrZk3AEggHyDd74SqVu1xRl2WrAqlsFaFUsjTGc9HDqxkFONb//brnpdHLux+uji+gnu6efndPc8CKJKtTSn6OOaeVmG+uJgcWxqn4d77twESasVUPxsouqGLFYxuWx2KDkMnbY1LR32tW0ZSsy4rwuEhX5TMQkOO3LpMX/la8bCnv8AYwF7EUdnKQ0jUrKEmy+CXawqXCn8/nAXnz2kB2gMbWgEiir9c37y4mB55l9sSKtHxSNzRQrU4D4BuaZfGWdcAp6JBoQTwtSfTL++ub6MMHEkVJSpPMOUKp/S2YIYQ/AxK1vxu8/Dsw1gd5mVJAbUAOXrKxQBI5Hw1GnCSU8zarPsyVsErrrQ+/pHj2A5Vg60LaMPrl+uafX99dRBEAvW0VP+YxSco8p2B8CI6QTKW53l1MkbPDuki2L74oQ7Kuyjwkoow4+w+IpI8iLg812GBFd5+/3Hx4f/cPl9nX6Nd/kbMLB3IbXd/+/fqz/xwQ338mRyQCyEeABOSnS3LmEuffBc23kTFBRgtp4B4QSGiRsvXEwyhE3UHQOhHKceT27v1ddLecHNCM01awQIA+xQzjgkCs459blvoXgQzvBq8uGKSOCqlO8PSu7NwoxWpyYorBPt9MJxPEYwn5UTLILR5VuZ+UBRcQKnFFjiNe1lVCg2UXLynBMwOYIXGBKYUwXdpL3KPJmj2LuqIRmq/FaRXzDhuDWsQ5VeykijJhaVVBRXideC6Bg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Kuo51IJ+Y/XaSOpecPqYAIPj/P56cvQgtVd74Rtyt9hto5uArqt11fN3nR7jkMjdgrbe6YN7KnIH2pjOuqZSsWcoWxG+zaOnqkSXDy1a/AiTnimyykLtK9ufTEuB6cfjg3Ta7J+qSGQVsr9GEeCa2SVc9j14IT/vI4VmlymdtOSKOrOal/f29+4NqgEOdz5E2z/GF4ABeagMA=="""
"clay.h" : r"""eJy9Vctu2zAQPEdfwVo9WIIQp9c0DWAENmLACIrWQdsTQZOriKhMqiTVqCj67yUp+aGH46YHn0wtdzizu0M65KlgkCKM75bTb3g1+7zC9xgHoQ1yAb14EHJB85IButGG5Xx9md0GwU/JGaI5+YUx0RqUGQcXXBhEpWDccCmS4MKutY1kRKE45TkkdUpuWTq7oJRUnRgDTRUvmrMcUGeyzBkma6lM9H6nAWswmOZARFmMfWwcN59R/R1HCaoXsiA/SrDgLTbVLag7NuSp64/vwnzxdfX4aYY/Tlf3waE6B+WVKRWM22X6GBZk02JpwpoItpbVayBbdS9AQrA9T4NgEscBitHUz8O2DW0IVVKjZ24yBFWRc8oN8r1GG9CaPIHNn+wmb1k3pTa4sBPFYwtQCXJTiNqD9jsRuv2ArhLrlvliOcPYrZaLB78azUtBvQBK8hylxM6eXaMRCvdnJuhd1CN2maeJb47yzqoCqAGG0pYAI72GEwpqktP0b47XbfmV7asj5hoJaZBRJQzxbmd1lwH9/h9zog53pkFdRX3mM09qSMIZBnUVnbhUQv7jdWokDd2wh8flcvgqdECHPe+BmtJ3iLab6/TjpjtVx95ue4a+BXui9l7pwl6sxad0EYOVzKWizkT2NPseTp6JElw8ddV7AQM+OeaOFdiXtr4Ml6Phx6Jhes2pX2oIYqVyP8aRQAW0dK66Hg14zuvYgMkks5uWRBGXq319b39DZUAJfLjzJ9j+GfwFGCyeSg=="""
}
if __name__ == '__main__':
main()
......@@ -37,16 +37,16 @@ void cl_fixture_cleanup(const char *fixture_name);
/**
* Assertion macros with no error message
*/
#define cl_must_pass(expr) cl_must_pass_((expr), NULL)
#define cl_must_fail(expr) cl_must_fail_((expr), NULL)
#define cl_assert(expr) cl_assert_((expr), NULL)
#define cl_must_pass(expr) cl_must_pass_(expr, NULL)
#define cl_must_fail(expr) cl_must_fail_(expr, NULL)
#define cl_assert(expr) cl_assert_(expr, NULL)
/**
* Check macros with no error message
*/
#define cl_check_pass(expr) cl_check_pass_((expr), NULL)
#define cl_check_fail(expr) cl_check_fail_((expr), NULL)
#define cl_check(expr) cl_check_((expr), NULL)
#define cl_check_pass(expr) cl_check_pass_(expr, NULL)
#define cl_check_fail(expr) cl_check_fail_(expr, NULL)
#define cl_check(expr) cl_check_(expr, NULL)
/**
* Forced failure/warning
......@@ -57,21 +57,13 @@ void cl_fixture_cleanup(const char *fixture_name);
/**
* Test method declarations
*/
extern void test_status_single__hash_single_file(void);
extern void test_status_worktree__initialize(void);
extern void test_status_worktree__cleanup(void);
extern void test_status_worktree__whole_repository(void);
extern void test_status_worktree__empty_repository(void);
extern void test_network_remotes__initialize(void);
extern void test_network_remotes__cleanup(void);
extern void test_network_remotes__parsing(void);
extern void test_network_remotes__refspec_parsing(void);
extern void test_network_remotes__fnmatch(void);
extern void test_network_remotes__transform(void);
extern void test_config_stress__cleanup(void);
extern void test_config_stress__dont_break_on_invalid_input(void);
extern void test_config_stress__initialize(void);
extern void test_core_dirent__dont_traverse_dot(void);
extern void test_core_dirent__traverse_subfolder(void);
extern void test_core_dirent__traverse_slash_terminated_folder(void);
extern void test_core_dirent__dont_traverse_empty_folders(void);
extern void test_core_dirent__traverse_slash_terminated_folder(void);
extern void test_core_dirent__traverse_subfolder(void);
extern void test_core_dirent__traverse_weird_filenames(void);
extern void test_core_filebuf__0(void);
extern void test_core_filebuf__1(void);
......@@ -83,9 +75,9 @@ extern void test_core_path__1(void);
extern void test_core_path__2(void);
extern void test_core_path__5(void);
extern void test_core_path__6(void);
extern void test_core_rmdir__initialize(void);
extern void test_core_rmdir__delete_recursive(void);
extern void test_core_rmdir__fail_to_delete_non_empty_dir(void);
extern void test_core_rmdir__initialize(void);
extern void test_core_string__0(void);
extern void test_core_string__1(void);
extern void test_core_strtol__int32(void);
......@@ -93,40 +85,51 @@ extern void test_core_strtol__int64(void);
extern void test_core_vector__0(void);
extern void test_core_vector__1(void);
extern void test_core_vector__2(void);
extern void test_object_tree_frompath__initialize(void);
extern void test_object_tree_frompath__cleanup(void);
extern void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void);
extern void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void);
extern void test_object_tree_frompath__fail_when_processing_an_invalid_path(void);
extern void test_object_raw_chars__find_invalid_chars_in_oid(void);
extern void test_network_remotes__cleanup(void);
extern void test_network_remotes__fnmatch(void);
extern void test_network_remotes__initialize(void);
extern void test_network_remotes__parsing(void);
extern void test_network_remotes__refspec_parsing(void);
extern void test_network_remotes__transform(void);
extern void test_object_raw_chars__build_valid_oid_from_raw_bytes(void);
extern void test_object_raw_chars__find_invalid_chars_in_oid(void);
extern void test_object_raw_compare__compare_allocfmt_oids(void);
extern void test_object_raw_compare__compare_fmt_oids(void);
extern void test_object_raw_compare__compare_pathfmt_oids(void);
extern void test_object_raw_compare__succeed_on_copy_oid(void);
extern void test_object_raw_compare__succeed_on_oid_comparison_lesser(void);
extern void test_object_raw_compare__succeed_on_oid_comparison_equal(void);
extern void test_object_raw_compare__succeed_on_oid_comparison_greater(void);
extern void test_object_raw_compare__compare_fmt_oids(void);
extern void test_object_raw_compare__compare_allocfmt_oids(void);
extern void test_object_raw_compare__compare_pathfmt_oids(void);
extern void test_object_raw_compare__succeed_on_oid_comparison_lesser(void);
extern void test_object_raw_convert__succeed_on_oid_to_string_conversion(void);
extern void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void);
extern void test_object_raw_fromstr__fail_on_invalid_oid_string(void);
extern void test_object_raw_fromstr__succeed_on_valid_oid_string(void);
extern void test_object_raw_hash__hash_by_blocks(void);
extern void test_object_raw_hash__hash_buffer_in_single_call(void);
extern void test_object_raw_hash__hash_vector(void);
extern void test_object_raw_hash__hash_junk_data(void);
extern void test_object_raw_hash__hash_by_blocks(void);
extern void test_object_raw_hash__hash_commit_object(void);
extern void test_object_raw_hash__hash_tree_object(void);
extern void test_object_raw_hash__hash_tag_object(void);
extern void test_object_raw_hash__hash_zero_length_object(void);
extern void test_object_raw_hash__hash_junk_data(void);
extern void test_object_raw_hash__hash_multi_byte_object(void);
extern void test_object_raw_hash__hash_one_byte_object(void);
extern void test_object_raw_hash__hash_tag_object(void);
extern void test_object_raw_hash__hash_tree_object(void);
extern void test_object_raw_hash__hash_two_byte_object(void);
extern void test_object_raw_hash__hash_multi_byte_object(void);
extern void test_object_raw_hash__hash_vector(void);
extern void test_object_raw_hash__hash_zero_length_object(void);
extern void test_object_raw_short__oid_shortener_no_duplicates(void);
extern void test_object_raw_short__oid_shortener_stresstest_git_oid_shorten(void);
extern void test_object_raw_size__validate_oid_size(void);
extern void test_object_raw_type2string__convert_type_to_string(void);
extern void test_object_raw_type2string__convert_string_to_type(void);
extern void test_object_raw_type2string__check_type_is_loose(void);
extern void test_object_raw_type2string__convert_string_to_type(void);
extern void test_object_raw_type2string__convert_type_to_string(void);
extern void test_object_tree_frompath__cleanup(void);
extern void test_object_tree_frompath__fail_when_processing_an_invalid_path(void);
extern void test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment(void);
extern void test_object_tree_frompath__initialize(void);
extern void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void);
extern void test_status_single__hash_single_file(void);
extern void test_status_worktree__cleanup(void);
extern void test_status_worktree__empty_repository(void);
extern void test_status_worktree__initialize(void);
extern void test_status_worktree__whole_repository(void);
#endif
......@@ -23,6 +23,6 @@
* just for consistency. Use with `git_` library
* calls that are supposed to fail!
*/
#define cl_git_fail(expr) cl_must_fail((expr))
#define cl_git_fail(expr) cl_must_fail(expr)
#endif
......@@ -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,259 @@ 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_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
},
{
"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 = 21;
static size_t _clay_callback_count = 64;
/* Core test functions */
static void
clay_run_test(
const struct clay_func *test,
......@@ -128,28 +375,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 +396,8 @@ clay_report_errors(void)
free(error);
error = next;
}
_clay.errors = _clay.last_error = NULL;
}
static void
......@@ -174,6 +406,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 +417,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 +428,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 +460,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 +476,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 +491,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 +547,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,202 +871,68 @@ cl_fs_cleanup(void)
#endif
static const struct clay_func _all_callbacks[] = {
{"hash_single_file", &test_status_single__hash_single_file, 0},
{"whole_repository", &test_status_worktree__whole_repository, 1},
{"empty_repository", &test_status_worktree__empty_repository, 1},
{"parsing", &test_network_remotes__parsing, 2},
{"refspec_parsing", &test_network_remotes__refspec_parsing, 2},
{"fnmatch", &test_network_remotes__fnmatch, 2},
{"transform", &test_network_remotes__transform, 2},
{"dont_traverse_dot", &test_core_dirent__dont_traverse_dot, 3},
{"traverse_subfolder", &test_core_dirent__traverse_subfolder, 3},
{"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder, 3},
{"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders, 3},
{"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames, 3},
{"0", &test_core_filebuf__0, 4},
{"1", &test_core_filebuf__1, 4},
{"2", &test_core_filebuf__2, 4},
{"streq", &test_core_oid__streq, 5},
{"0", &test_core_path__0, 6},
{"1", &test_core_path__1, 6},
{"2", &test_core_path__2, 6},
{"5", &test_core_path__5, 6},
{"6", &test_core_path__6, 6},
{"delete_recursive", &test_core_rmdir__delete_recursive, 7},
{"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir, 7},
{"0", &test_core_string__0, 8},
{"1", &test_core_string__1, 8},
{"int32", &test_core_strtol__int32, 9},
{"int64", &test_core_strtol__int64, 9},
{"0", &test_core_vector__0, 10},
{"1", &test_core_vector__1, 10},
{"2", &test_core_vector__2, 10},
{"retrieve_tree_from_path_to_treeentry", &test_object_tree_frompath__retrieve_tree_from_path_to_treeentry, 11},
{"fail_when_processing_an_unknown_tree_segment", &test_object_tree_frompath__fail_when_processing_an_unknown_tree_segment, 11},
{"fail_when_processing_an_invalid_path", &test_object_tree_frompath__fail_when_processing_an_invalid_path, 11},
{"find_invalid_chars_in_oid", &test_object_raw_chars__find_invalid_chars_in_oid, 12},
{"build_valid_oid_from_raw_bytes", &test_object_raw_chars__build_valid_oid_from_raw_bytes, 12},
{"succeed_on_copy_oid", &test_object_raw_compare__succeed_on_copy_oid, 13},
{"succeed_on_oid_comparison_lesser", &test_object_raw_compare__succeed_on_oid_comparison_lesser, 13},
{"succeed_on_oid_comparison_equal", &test_object_raw_compare__succeed_on_oid_comparison_equal, 13},
{"succeed_on_oid_comparison_greater", &test_object_raw_compare__succeed_on_oid_comparison_greater, 13},
{"compare_fmt_oids", &test_object_raw_compare__compare_fmt_oids, 13},
{"compare_allocfmt_oids", &test_object_raw_compare__compare_allocfmt_oids, 13},
{"compare_pathfmt_oids", &test_object_raw_compare__compare_pathfmt_oids, 13},
{"succeed_on_oid_to_string_conversion", &test_object_raw_convert__succeed_on_oid_to_string_conversion, 14},
{"succeed_on_oid_to_string_conversion_big", &test_object_raw_convert__succeed_on_oid_to_string_conversion_big, 14},
{"fail_on_invalid_oid_string", &test_object_raw_fromstr__fail_on_invalid_oid_string, 15},
{"succeed_on_valid_oid_string", &test_object_raw_fromstr__succeed_on_valid_oid_string, 15},
{"hash_by_blocks", &test_object_raw_hash__hash_by_blocks, 16},
{"hash_buffer_in_single_call", &test_object_raw_hash__hash_buffer_in_single_call, 16},
{"hash_vector", &test_object_raw_hash__hash_vector, 16},
{"hash_junk_data", &test_object_raw_hash__hash_junk_data, 16},
{"hash_commit_object", &test_object_raw_hash__hash_commit_object, 16},
{"hash_tree_object", &test_object_raw_hash__hash_tree_object, 16},
{"hash_tag_object", &test_object_raw_hash__hash_tag_object, 16},
{"hash_zero_length_object", &test_object_raw_hash__hash_zero_length_object, 16},
{"hash_one_byte_object", &test_object_raw_hash__hash_one_byte_object, 16},
{"hash_two_byte_object", &test_object_raw_hash__hash_two_byte_object, 16},
{"hash_multi_byte_object", &test_object_raw_hash__hash_multi_byte_object, 16},
{"oid_shortener_no_duplicates", &test_object_raw_short__oid_shortener_no_duplicates, 17},
{"oid_shortener_stresstest_git_oid_shorten", &test_object_raw_short__oid_shortener_stresstest_git_oid_shorten, 17},
{"validate_oid_size", &test_object_raw_size__validate_oid_size, 18},
{"convert_type_to_string", &test_object_raw_type2string__convert_type_to_string, 19},
{"convert_string_to_type", &test_object_raw_type2string__convert_string_to_type, 19},
{"check_type_is_loose", &test_object_raw_type2string__check_type_is_loose, 19}
};
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[] = {
{
"status::single",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[0], 1
},
{
"status::worktree",
{"initialize", &test_status_worktree__initialize, 1},
{"cleanup", &test_status_worktree__cleanup, 1},
&_all_callbacks[1], 2
},
{
"network::remotes",
{"initialize", &test_network_remotes__initialize, 2},
{"cleanup", &test_network_remotes__cleanup, 2},
&_all_callbacks[3], 4
},
{
"core::dirent",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[7], 5
},
{
"core::filebuf",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[12], 3
},
{
"core::oid",
{"initialize", &test_core_oid__initialize, 5},
{NULL, NULL, 0},
&_all_callbacks[15], 1
},
{
"core::path",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[16], 5
},
{
"core::rmdir",
{"initialize", &test_core_rmdir__initialize, 7},
{NULL, NULL, 0},
&_all_callbacks[21], 2
},
{
"core::string",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[23], 2
},
{
"core::strtol",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[25], 2
},
{
"core::vector",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[27], 3
},
{
"object::tree::frompath",
{"initialize", &test_object_tree_frompath__initialize, 11},
{"cleanup", &test_object_tree_frompath__cleanup, 11},
&_all_callbacks[30], 3
},
{
"object::raw::chars",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[33], 2
},
{
"object::raw::compare",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[35], 7
},
{
"object::raw::convert",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[42], 2
},
{
"object::raw::fromstr",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[44], 2
},
{
"object::raw::hash",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[46], 11
},
{
"object::raw::short",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[57], 2
},
{
"object::raw::size",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[59], 1
},
{
"object::raw::type2string",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[60], 3
}
};
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[] = "status::single, status::worktree, network::remotes, core::dirent, core::filebuf, core::oid, core::path, core::rmdir, core::string, core::strtol, core::vector, object::tree::frompath, object::raw::chars, object::raw::compare, object::raw::convert, object::raw::fromstr, object::raw::hash, object::raw::short, object::raw::size, object::raw::type2string";
int _MAIN_CC main(int argc, char *argv[])
{
return clay_test(
argc, argv, _suites_str,
_all_callbacks, 63,
_all_suites, 20
);
return clay_test(argc, argv);
}
#include "clay_libgit2.h"
#include "filebuf.h"
#include "fileops.h"
#include "posix.h"
#define TEST_CONFIG "git-test-config"
void test_config_stress__initialize(void)
{
git_filebuf file;
git_filebuf_open(&file, TEST_CONFIG, 0);
git_filebuf_printf(&file, "[color]\n\tui = auto\n");
git_filebuf_printf(&file, "[core]\n\teditor = \n");
git_filebuf_commit(&file, 0666);
}
void test_config_stress__cleanup(void)
{
p_unlink(TEST_CONFIG);
}
void test_config_stress__dont_break_on_invalid_input(void)
{
const char *editor, *color;
struct git_config_file *file;
git_config *config;
cl_git_pass(git_futils_exists(TEST_CONFIG));
cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
cl_git_pass(git_config_new(&config));
cl_git_pass(git_config_add_file(config, file, 0));
cl_git_pass(git_config_get_string(config, "color.ui", &color));
cl_git_pass(git_config_get_string(config, "core.editor", &editor));
git_config_free(config);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment