Commit 3f21a23c by Vicent Martí

Merge pull request #1432 from arrbee/update-clar

Update clar and some test helpers clean up
parents 33a59401 1323c6d1
...@@ -47,22 +47,12 @@ static void execute_test(void) ...@@ -47,22 +47,12 @@ static void execute_test(void)
void test_checkout_binaryunicode__noautocrlf(void) void test_checkout_binaryunicode__noautocrlf(void)
{ {
git_config *config; cl_repo_set_bool(g_repo, "core.autocrlf", false);
cl_git_pass(git_repository_config(&config, g_repo));
cl_git_pass(git_config_set_bool(config, "core.autocrlf", false));
git_config_free(config);
execute_test(); execute_test();
} }
void test_checkout_binaryunicode__autocrlf(void) void test_checkout_binaryunicode__autocrlf(void)
{ {
git_config *config; cl_repo_set_bool(g_repo, "core.autocrlf", true);
cl_git_pass(git_repository_config(&config, g_repo));
cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
git_config_free(config);
execute_test(); execute_test();
} }
...@@ -24,30 +24,13 @@ void test_checkout_crlf__cleanup(void) ...@@ -24,30 +24,13 @@ void test_checkout_crlf__cleanup(void)
cl_git_sandbox_cleanup(); cl_git_sandbox_cleanup();
} }
#ifdef GIT_WIN32
static void set_config_entry_to(const char *entry_name, bool value)
{
git_config *cfg;
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_bool(cfg, entry_name, value));
git_config_free(cfg);
}
static void set_core_autocrlf_to(bool value)
{
set_config_entry_to("core.autocrlf", value);
}
#endif
void test_checkout_crlf__detect_crlf_autocrlf_false(void) void test_checkout_crlf__detect_crlf_autocrlf_false(void)
{ {
#ifdef GIT_WIN32 #ifdef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
set_core_autocrlf_to(false); cl_repo_set_bool(g_repo, "core.autocrlf", false);
git_checkout_head(g_repo, &opts); git_checkout_head(g_repo, &opts);
...@@ -63,7 +46,7 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void) ...@@ -63,7 +46,7 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
set_core_autocrlf_to(false); cl_repo_set_bool(g_repo, "core.autocrlf", false);
git_checkout_head(g_repo, &opts); git_checkout_head(g_repo, &opts);
...@@ -82,7 +65,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void) ...@@ -82,7 +65,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
set_core_autocrlf_to(true); cl_repo_set_bool(g_repo, "core.autocrlf", true);
git_checkout_head(g_repo, &opts); git_checkout_head(g_repo, &opts);
...@@ -98,7 +81,7 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void) ...@@ -98,7 +81,7 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
set_core_autocrlf_to(true); cl_repo_set_bool(g_repo, "core.autocrlf", true);
git_checkout_head(g_repo, &opts); git_checkout_head(g_repo, &opts);
......
...@@ -92,21 +92,6 @@ void test_checkout_index__honor_the_specified_pathspecs(void) ...@@ -92,21 +92,6 @@ void test_checkout_index__honor_the_specified_pathspecs(void)
test_file_contents("./testrepo/new.txt", "my new file\n"); test_file_contents("./testrepo/new.txt", "my new file\n");
} }
static void set_config_entry_to(const char *entry_name, bool value)
{
git_config *cfg;
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_bool(cfg, entry_name, value));
git_config_free(cfg);
}
static void set_core_autocrlf_to(bool value)
{
set_config_entry_to("core.autocrlf", value);
}
void test_checkout_index__honor_the_gitattributes_directives(void) void test_checkout_index__honor_the_gitattributes_directives(void)
{ {
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
...@@ -115,7 +100,7 @@ void test_checkout_index__honor_the_gitattributes_directives(void) ...@@ -115,7 +100,7 @@ void test_checkout_index__honor_the_gitattributes_directives(void)
"new.txt text eol=lf\n"; "new.txt text eol=lf\n";
cl_git_mkfile("./testrepo/.gitattributes", attributes); cl_git_mkfile("./testrepo/.gitattributes", attributes);
set_core_autocrlf_to(false); cl_repo_set_bool(g_repo, "core.autocrlf", false);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
...@@ -133,7 +118,7 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void) ...@@ -133,7 +118,7 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
const char *expected_readme_text = "hey there\r\n"; const char *expected_readme_text = "hey there\r\n";
cl_git_pass(p_unlink("./testrepo/.gitattributes")); cl_git_pass(p_unlink("./testrepo/.gitattributes"));
set_core_autocrlf_to(true); cl_repo_set_bool(g_repo, "core.autocrlf", true);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
...@@ -143,16 +128,11 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void) ...@@ -143,16 +128,11 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
#endif #endif
} }
static void set_repo_symlink_handling_cap_to(bool value)
{
set_config_entry_to("core.symlinks", value);
}
void test_checkout_index__honor_coresymlinks_setting_set_to_true(void) void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
{ {
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
set_repo_symlink_handling_cap_to(true); cl_repo_set_bool(g_repo, "core.symlinks", true);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
...@@ -178,7 +158,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_false(void) ...@@ -178,7 +158,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_false(void)
{ {
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
set_repo_symlink_handling_cap_to(false); cl_repo_set_bool(g_repo, "core.symlinks", false);
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE; opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
...@@ -372,7 +352,7 @@ void test_checkout_index__wont_notify_of_expected_line_ending_changes(void) ...@@ -372,7 +352,7 @@ void test_checkout_index__wont_notify_of_expected_line_ending_changes(void)
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
cl_git_pass(p_unlink("./testrepo/.gitattributes")); cl_git_pass(p_unlink("./testrepo/.gitattributes"));
set_core_autocrlf_to(true); cl_repo_set_bool(g_repo, "core.autocrlf", true);
cl_git_mkfile("./testrepo/new.txt", "my new file\r\n"); cl_git_mkfile("./testrepo/new.txt", "my new file\r\n");
......
...@@ -452,32 +452,31 @@ void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void) ...@@ -452,32 +452,31 @@ void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void)
git_oid tree_id, commit_id; git_oid tree_id, commit_id;
git_tree *tree = NULL; git_tree *tree = NULL;
git_commit *commit = NULL; git_commit *commit = NULL;
git_repository_index(&index, g_repo); git_repository_index(&index, g_repo);
opts.checkout_strategy = GIT_CHECKOUT_FORCE; opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_pass(git_reference_name_to_id(&commit_id, g_repo, "refs/heads/master")); cl_git_pass(git_reference_name_to_id(&commit_id, g_repo, "refs/heads/master"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id)); cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
cl_git_pass(git_checkout_tree(g_repo, (git_object *)commit, &opts)); cl_git_pass(git_checkout_tree(g_repo, (git_object *)commit, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master")); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
cl_git_pass(p_mkdir("./testrepo/this-is-dir", 0777)); cl_git_pass(p_mkdir("./testrepo/this-is-dir", 0777));
cl_git_mkfile("./testrepo/this-is-dir/contained_file", "content\n"); cl_git_mkfile("./testrepo/this-is-dir/contained_file", "content\n");
cl_git_pass(git_index_add_bypath(index, "this-is-dir/contained_file")); cl_git_pass(git_index_add_bypath(index, "this-is-dir/contained_file"));
git_index_write_tree(&tree_id, index); git_index_write_tree(&tree_id, index);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id)); cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
cl_git_pass(p_unlink("./testrepo/this-is-dir/contained_file")); cl_git_pass(p_unlink("./testrepo/this-is-dir/contained_file"));
opts.checkout_strategy = GIT_CHECKOUT_SAFE; opts.checkout_strategy = GIT_CHECKOUT_SAFE;
opts.checkout_strategy = 1; opts.checkout_strategy = 1;
git_checkout_tree(g_repo, (git_object *)tree, &opts); git_checkout_tree(g_repo, (git_object *)tree, &opts);
git_tree_free(tree); git_tree_free(tree);
git_commit_free(commit); git_commit_free(commit);
git_index_free(index); git_index_free(index);
......
...@@ -331,21 +331,14 @@ clar_test(int argc, char **argv) ...@@ -331,21 +331,14 @@ clar_test(int argc, char **argv)
return _clar.total_errors; return _clar.total_errors;
} }
void void clar__fail(
clar__assert(
int condition,
const char *file, const char *file,
int line, int line,
const char *error_msg, const char *error_msg,
const char *description, const char *description,
int should_abort) int should_abort)
{ {
struct clar_error *error; struct clar_error *error = calloc(1, sizeof(struct clar_error));
if (condition)
return;
error = calloc(1, sizeof(struct clar_error));
if (_clar.errors == NULL) if (_clar.errors == NULL)
_clar.errors = error; _clar.errors = error;
...@@ -380,6 +373,20 @@ clar__assert( ...@@ -380,6 +373,20 @@ clar__assert(
} }
} }
void clar__assert(
int condition,
const char *file,
int line,
const char *error_msg,
const char *description,
int should_abort)
{
if (condition)
return;
clar__fail(file, line, error_msg, description, should_abort);
}
void clar__assert_equal_s( void clar__assert_equal_s(
const char *s1, const char *s1,
const char *s2, const char *s2,
...@@ -392,8 +399,8 @@ void clar__assert_equal_s( ...@@ -392,8 +399,8 @@ void clar__assert_equal_s(
if (!match) { if (!match) {
char buf[4096]; char buf[4096];
snprint_eq(buf, 4096, "'%s' != '%s'", s1, s2); snprint_eq(buf, sizeof(buf), "'%s' != '%s'", s1, s2);
clar__assert(0, file, line, err, buf, should_abort); clar__fail(file, line, err, buf, should_abort);
} }
} }
...@@ -407,8 +414,8 @@ void clar__assert_equal_i( ...@@ -407,8 +414,8 @@ void clar__assert_equal_i(
{ {
if (i1 != i2) { if (i1 != i2) {
char buf[128]; char buf[128];
snprint_eq(buf, 128, "%d != %d", i1, i2); snprint_eq(buf, sizeof(buf), "%d != %d", i1, i2);
clar__assert(0, file, line, err, buf, should_abort); clar__fail(file, line, err, buf, should_abort);
} }
} }
......
...@@ -51,17 +51,29 @@ void cl_fixture_cleanup(const char *fixture_name); ...@@ -51,17 +51,29 @@ void cl_fixture_cleanup(const char *fixture_name);
/** /**
* Forced failure/warning * Forced failure/warning
*/ */
#define cl_fail(desc) clar__assert(0, __FILE__, __LINE__, "Test failed.", desc, 1) #define cl_fail(desc) clar__fail(__FILE__, __LINE__, "Test failed.", desc, 1)
#define cl_warning(desc) clar__assert(0, __FILE__, __LINE__, "Warning during test execution:", desc, 0) #define cl_warning(desc) clar__fail(__FILE__, __LINE__, "Warning during test execution:", desc, 0)
/** /**
* Typed assertion macros * Typed assertion macros
*/ */
#define cl_assert_equal_s(s1,s2) clar__assert_equal_s((s1),(s2),__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2, 1) #define cl_assert_equal_s(s1,s2) clar__assert_equal_s((s1),(s2),__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2, 1)
#define cl_assert_equal_s_(s1,s2,note) clar__assert_equal_s((s1),(s2),__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1)
#define cl_assert_equal_i(i1,i2) clar__assert_equal_i((i1),(i2),__FILE__,__LINE__,#i1 " != " #i2, 1) #define cl_assert_equal_i(i1,i2) clar__assert_equal_i((i1),(i2),__FILE__,__LINE__,#i1 " != " #i2, 1)
#define cl_assert_equal_i_(i1,i2,note) clar__assert_equal_i((i1),(i2),__FILE__,__LINE__,#i1 " != " #i2 " (" #note ")", 1)
#define cl_assert_equal_b(b1,b2) clar__assert_equal_i(!!(b1),!!(b2),__FILE__,__LINE__,#b1 " != " #b2, 1) #define cl_assert_equal_b(b1,b2) clar__assert_equal_i(!!(b1),!!(b2),__FILE__,__LINE__,#b1 " != " #b2, 1)
#define cl_assert_equal_p(p1,p2) cl_assert((p1) == (p2)) #define cl_assert_equal_p(p1,p2) cl_assert((p1) == (p2))
void clar__fail(
const char *file,
int line,
const char *error,
const char *description,
int should_abort);
void clar__assert( void clar__assert(
int condition, int condition,
const char *file, const char *file,
......
...@@ -323,3 +323,11 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename) ...@@ -323,3 +323,11 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
return error; return error;
} }
void cl_repo_set_bool(git_repository *repo, const char *cfg, int value)
{
git_config *config;
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_bool(config, cfg, value != 0));
git_config_free(config);
}
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
void cl_git_report_failure(int, const char *, int, const char *); void cl_git_report_failure(int, const char *, int, const char *);
#define cl_assert_equal_sz(sz1,sz2) cl_assert((sz1) == (sz2)) #define cl_assert_equal_sz(sz1,sz2) cl_assert_equal_i((int)sz1, (int)(sz2))
/* /*
* Some utility macros for building long strings * Some utility macros for building long strings
...@@ -68,4 +68,7 @@ const char* cl_git_path_url(const char *path); ...@@ -68,4 +68,7 @@ const char* cl_git_path_url(const char *path);
/* Test repository cleaner */ /* Test repository cleaner */
int cl_git_remove_placeholders(const char *directory_path, const char *filename); int cl_git_remove_placeholders(const char *directory_path, const char *filename);
/* config setting helpers */
void cl_repo_set_bool(git_repository *repo, const char *cfg, int value);
#endif #endif
...@@ -472,7 +472,6 @@ void test_diff_workdir__to_index_notify_can_be_used_as_filtering_function(void) ...@@ -472,7 +472,6 @@ void test_diff_workdir__to_index_notify_can_be_used_as_filtering_function(void)
void test_diff_workdir__filemode_changes(void) void test_diff_workdir__filemode_changes(void)
{ {
git_config *cfg;
git_diff_list *diff = NULL; git_diff_list *diff = NULL;
diff_expects exp; diff_expects exp;
int use_iterator; int use_iterator;
...@@ -482,8 +481,7 @@ void test_diff_workdir__filemode_changes(void) ...@@ -482,8 +481,7 @@ void test_diff_workdir__filemode_changes(void)
g_repo = cl_git_sandbox_init("issue_592"); g_repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_repository_config(&cfg, g_repo)); cl_repo_set_bool(g_repo, "core.filemode", true);
cl_git_pass(git_config_set_bool(cfg, "core.filemode", true));
/* test once with no mods */ /* test once with no mods */
...@@ -530,12 +528,10 @@ void test_diff_workdir__filemode_changes(void) ...@@ -530,12 +528,10 @@ void test_diff_workdir__filemode_changes(void)
git_diff_list_free(diff); git_diff_list_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt")); cl_assert(cl_toggle_filemode("issue_592/a.txt"));
git_config_free(cfg);
} }
void test_diff_workdir__filemode_changes_with_filemode_false(void) void test_diff_workdir__filemode_changes_with_filemode_false(void)
{ {
git_config *cfg;
git_diff_list *diff = NULL; git_diff_list *diff = NULL;
diff_expects exp; diff_expects exp;
...@@ -544,8 +540,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void) ...@@ -544,8 +540,7 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
g_repo = cl_git_sandbox_init("issue_592"); g_repo = cl_git_sandbox_init("issue_592");
cl_git_pass(git_repository_config(&cfg, g_repo)); cl_repo_set_bool(g_repo, "core.filemode", false);
cl_git_pass(git_config_set_bool(cfg, "core.filemode", false));
/* test once with no mods */ /* test once with no mods */
...@@ -578,7 +573,6 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void) ...@@ -578,7 +573,6 @@ void test_diff_workdir__filemode_changes_with_filemode_false(void)
git_diff_list_free(diff); git_diff_list_free(diff);
cl_assert(cl_toggle_filemode("issue_592/a.txt")); cl_assert(cl_toggle_filemode("issue_592/a.txt"));
git_config_free(cfg);
} }
void test_diff_workdir__head_index_and_workdir_all_differ(void) void test_diff_workdir__head_index_and_workdir_all_differ(void)
......
...@@ -60,7 +60,10 @@ class Module(object): ...@@ -60,7 +60,10 @@ class Module(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
self.mtime = 0
self.enabled = True self.enabled = True
self.modified = False
def clean_name(self): def clean_name(self):
return self.name.replace("_", "::") return self.name.replace("_", "::")
...@@ -102,17 +105,41 @@ class Module(object): ...@@ -102,17 +105,41 @@ class Module(object):
return self.callbacks != [] return self.callbacks != []
def load(self, path): def refresh(self, path):
self.modified = False
try: try:
st = os.stat(path)
# Not modified
if st.st_mtime == self.mtime:
return True
self.modified = True
self.mtime = st.st_mtime
with open(path) as fp: with open(path) as fp:
return self.parse(fp.read()) raw_content = fp.read()
except IOError: except IOError:
return False return False
return self.parse(raw_content)
class TestSuite(object): class TestSuite(object):
def __init__(self, path): def __init__(self, path):
self.path = path self.path = path
def should_generate(self, path):
if not os.path.isfile(path):
return True
if any(module.modified for module in self.modules.values()):
return True
return False
def find_modules(self): def find_modules(self):
modules = [] modules = []
for root, _, files in os.walk(self.path): for root, _, files in os.walk(self.path):
...@@ -129,15 +156,33 @@ class TestSuite(object): ...@@ -129,15 +156,33 @@ class TestSuite(object):
return modules return modules
def load_cache(self):
path = os.path.join(self.path, '.clarcache')
cache = {}
try:
fp = open(path, 'rb')
cache = pickle.load(fp)
fp.close()
except (IOError, ValueError):
pass
return cache
def save_cache(self):
path = os.path.join(self.path, '.clarcache')
with open(path, 'wb') as cache:
pickle.dump(self.modules, cache)
def load(self, force = False): def load(self, force = False):
module_data = self.find_modules() module_data = self.find_modules()
self.modules = {} self.modules = {} if force else self.load_cache()
for path, name in module_data: for path, name in module_data:
if name not in self.modules: if name not in self.modules:
self.modules[name] = Module(name) self.modules[name] = Module(name)
if not self.modules[name].load(path): if not self.modules[name].refresh(path):
del self.modules[name] del self.modules[name]
def disable(self, excluded): def disable(self, excluded):
...@@ -157,6 +202,9 @@ class TestSuite(object): ...@@ -157,6 +202,9 @@ class TestSuite(object):
def write(self): def write(self):
output = os.path.join(self.path, 'clar.suite') output = os.path.join(self.path, 'clar.suite')
if not self.should_generate(output):
return False
with open(output, 'w') as data: with open(output, 'w') as data:
for module in self.modules.values(): for module in self.modules.values():
t = Module.DeclarationTemplate(module) t = Module.DeclarationTemplate(module)
...@@ -175,19 +223,22 @@ class TestSuite(object): ...@@ -175,19 +223,22 @@ class TestSuite(object):
data.write("static const size_t _clar_suite_count = %d;\n" % self.suite_count()) data.write("static const size_t _clar_suite_count = %d;\n" % self.suite_count())
data.write("static const size_t _clar_callback_count = %d;\n" % self.callback_count()) data.write("static const size_t _clar_callback_count = %d;\n" % self.callback_count())
suite.save_cache()
return True
if __name__ == '__main__': if __name__ == '__main__':
from optparse import OptionParser from optparse import OptionParser
parser = OptionParser() parser = OptionParser()
parser.add_option('-f', '--force', dest='force', default=False)
parser.add_option('-x', '--exclude', dest='excluded', action='append', default=[]) parser.add_option('-x', '--exclude', dest='excluded', action='append', default=[])
options, args = parser.parse_args() options, args = parser.parse_args()
for path in args or ['.']: for path in args or ['.']:
suite = TestSuite(path) suite = TestSuite(path)
suite.load() suite.load(options.force)
suite.disable(options.excluded) suite.disable(options.excluded)
suite.write() if suite.write():
print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
print("Written `clar.suite` (%d suites)" % len(suite.modules))
...@@ -66,13 +66,10 @@ static void add_and_check_mode( ...@@ -66,13 +66,10 @@ static void add_and_check_mode(
void test_index_filemodes__untrusted(void) void test_index_filemodes__untrusted(void)
{ {
git_config *cfg;
git_index *index; git_index *index;
bool can_filemode = cl_is_chmod_supported(); bool can_filemode = cl_is_chmod_supported();
cl_git_pass(git_repository_config(&cfg, g_repo)); cl_repo_set_bool(g_repo, "core.filemode", false);
cl_git_pass(git_config_set_bool(cfg, "core.filemode", false));
git_config_free(cfg);
cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_repository_index(&index, g_repo));
cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) != 0); cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) != 0);
...@@ -113,7 +110,6 @@ void test_index_filemodes__untrusted(void) ...@@ -113,7 +110,6 @@ void test_index_filemodes__untrusted(void)
void test_index_filemodes__trusted(void) void test_index_filemodes__trusted(void)
{ {
git_config *cfg;
git_index *index; git_index *index;
/* Only run these tests on platforms where I can actually /* Only run these tests on platforms where I can actually
...@@ -122,9 +118,7 @@ void test_index_filemodes__trusted(void) ...@@ -122,9 +118,7 @@ void test_index_filemodes__trusted(void)
if (!cl_is_chmod_supported()) if (!cl_is_chmod_supported())
return; return;
cl_git_pass(git_repository_config(&cfg, g_repo)); cl_repo_set_bool(g_repo, "core.filemode", true);
cl_git_pass(git_config_set_bool(cfg, "core.filemode", true));
git_config_free(cfg);
cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_repository_index(&index, g_repo));
cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) == 0); cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) == 0);
......
...@@ -23,8 +23,8 @@ void test_network_urlparse__trivial(void) ...@@ -23,8 +23,8 @@ void test_network_urlparse__trivial(void)
"example.com/resource", "8080")); "example.com/resource", "8080"));
cl_assert_equal_s(host, "example.com"); cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080"); cl_assert_equal_s(port, "8080");
cl_assert_equal_sz(user, NULL); cl_assert_equal_p(user, NULL);
cl_assert_equal_sz(pass, NULL); cl_assert_equal_p(pass, NULL);
} }
void test_network_urlparse__user(void) void test_network_urlparse__user(void)
...@@ -34,7 +34,7 @@ void test_network_urlparse__user(void) ...@@ -34,7 +34,7 @@ void test_network_urlparse__user(void)
cl_assert_equal_s(host, "example.com"); cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "8080"); cl_assert_equal_s(port, "8080");
cl_assert_equal_s(user, "user"); cl_assert_equal_s(user, "user");
cl_assert_equal_sz(pass, NULL); cl_assert_equal_p(pass, NULL);
} }
void test_network_urlparse__user_pass(void) void test_network_urlparse__user_pass(void)
...@@ -55,8 +55,8 @@ void test_network_urlparse__port(void) ...@@ -55,8 +55,8 @@ void test_network_urlparse__port(void)
"example.com:9191/resource", "8080")); "example.com:9191/resource", "8080"));
cl_assert_equal_s(host, "example.com"); cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191"); cl_assert_equal_s(port, "9191");
cl_assert_equal_sz(user, NULL); cl_assert_equal_p(user, NULL);
cl_assert_equal_sz(pass, NULL); cl_assert_equal_p(pass, NULL);
} }
void test_network_urlparse__user_port(void) void test_network_urlparse__user_port(void)
...@@ -67,7 +67,7 @@ void test_network_urlparse__user_port(void) ...@@ -67,7 +67,7 @@ void test_network_urlparse__user_port(void)
cl_assert_equal_s(host, "example.com"); cl_assert_equal_s(host, "example.com");
cl_assert_equal_s(port, "9191"); cl_assert_equal_s(port, "9191");
cl_assert_equal_s(user, "user"); cl_assert_equal_s(user, "user");
cl_assert_equal_sz(pass, NULL); cl_assert_equal_p(pass, NULL);
} }
void test_network_urlparse__user_pass_port(void) void test_network_urlparse__user_pass_port(void)
......
...@@ -41,11 +41,8 @@ void test_repo_hashfile__simple(void) ...@@ -41,11 +41,8 @@ void test_repo_hashfile__simple(void)
void test_repo_hashfile__filtered(void) void test_repo_hashfile__filtered(void)
{ {
git_oid a, b; git_oid a, b;
git_config *config;
cl_git_pass(git_repository_config(&config, _repo)); cl_repo_set_bool(_repo, "core.autocrlf", true);
cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
git_config_free(config);
cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n"); cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
......
...@@ -276,11 +276,9 @@ void test_repo_init__reinit_overwrites_filemode(void) ...@@ -276,11 +276,9 @@ void test_repo_init__reinit_overwrites_filemode(void)
cl_set_cleanup(&cleanup_repository, "overwrite.git"); cl_set_cleanup(&cleanup_repository, "overwrite.git");
cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1)); cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
/* Change the "core.filemode" config value to something unlikely */ /* Change the "core.filemode" config value to something unlikely */
git_repository_config(&config, _repo); cl_repo_set_bool(_repo, "core.filemode", !expected);
git_config_set_bool(config, "core.filemode", !expected);
git_config_free(config);
git_repository_free(_repo); git_repository_free(_repo);
_repo = NULL; _repo = NULL;
......
...@@ -470,15 +470,14 @@ void test_status_worktree__filemode_changes(void) ...@@ -470,15 +470,14 @@ void test_status_worktree__filemode_changes(void)
git_repository *repo = cl_git_sandbox_init("filemodes"); git_repository *repo = cl_git_sandbox_init("filemodes");
status_entry_counts counts; status_entry_counts counts;
git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
git_config *cfg;
/* overwrite stored filemode with platform appropriate value */ /* overwrite stored filemode with platform appropriate value */
cl_git_pass(git_repository_config(&cfg, repo));
if (cl_is_chmod_supported()) if (cl_is_chmod_supported())
cl_git_pass(git_config_set_bool(cfg, "core.filemode", true)); cl_repo_set_bool(repo, "core.filemode", true);
else { else {
int i; int i;
cl_git_pass(git_config_set_bool(cfg, "core.filemode", false));
cl_repo_set_bool(repo, "core.filemode", false);
/* won't trust filesystem mode diffs, so these will appear unchanged */ /* won't trust filesystem mode diffs, so these will appear unchanged */
for (i = 0; i < filemode_count; ++i) for (i = 0; i < filemode_count; ++i)
...@@ -502,8 +501,6 @@ void test_status_worktree__filemode_changes(void) ...@@ -502,8 +501,6 @@ void test_status_worktree__filemode_changes(void)
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path); cl_assert_equal_i(0, counts.wrong_sorted_path);
git_config_free(cfg);
} }
static int cb_status__interrupt(const char *p, unsigned int s, void *payload) static int cb_status__interrupt(const char *p, unsigned int s, void *payload)
...@@ -533,12 +530,9 @@ void test_status_worktree__interruptable_foreach(void) ...@@ -533,12 +530,9 @@ void test_status_worktree__interruptable_foreach(void)
void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void) void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void)
{ {
git_repository *repo = cl_git_sandbox_init("status"); git_repository *repo = cl_git_sandbox_init("status");
git_config *config;
unsigned int status; unsigned int status;
cl_git_pass(git_repository_config(&config, repo)); cl_repo_set_bool(repo, "core.autocrlf", true);
cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
git_config_free(config);
cl_git_rewritefile("status/current_file", "current_file\r\n"); cl_git_rewritefile("status/current_file", "current_file\r\n");
...@@ -621,7 +615,6 @@ static void assert_ignore_case( ...@@ -621,7 +615,6 @@ static void assert_ignore_case(
int expected_lower_cased_file_status, int expected_lower_cased_file_status,
int expected_camel_cased_file_status) int expected_camel_cased_file_status)
{ {
git_config *config;
unsigned int status; unsigned int status;
git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT; git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT;
git_repository *repo, *repo2; git_repository *repo, *repo2;
...@@ -629,9 +622,7 @@ static void assert_ignore_case( ...@@ -629,9 +622,7 @@ static void assert_ignore_case(
repo = cl_git_sandbox_init("empty_standard_repo"); repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt"); cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");
cl_git_pass(git_repository_config(&config, repo)); cl_repo_set_bool(repo, "core.ignorecase", should_ignore_case);
cl_git_pass(git_config_set_bool(config, "core.ignorecase", should_ignore_case));
git_config_free(config);
cl_git_pass(git_buf_joinpath(&lower_case_path, cl_git_pass(git_buf_joinpath(&lower_case_path,
git_repository_workdir(repo), "plop")); git_repository_workdir(repo), "plop"));
......
...@@ -316,15 +316,13 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void) ...@@ -316,15 +316,13 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
{ {
git_repository *repo; git_repository *repo;
git_index *index; git_index *index;
git_config *config;
unsigned int status; unsigned int status;
cl_set_cleanup(&cleanup_new_repo, "getting_started"); cl_set_cleanup(&cleanup_new_repo, "getting_started");
cl_git_pass(git_repository_init(&repo, "getting_started", 0)); cl_git_pass(git_repository_init(&repo, "getting_started", 0));
// Ensure that repo has core.autocrlf=true // Ensure that repo has core.autocrlf=true
cl_git_pass(git_repository_config(&config, repo)); cl_repo_set_bool(repo, "core.autocrlf", true);
cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF
...@@ -335,7 +333,6 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void) ...@@ -335,7 +333,6 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
cl_git_pass(git_status_file(&status, repo, "testfile.txt")); cl_git_pass(git_status_file(&status, repo, "testfile.txt"));
cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status); cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status);
git_config_free(config);
git_index_free(index); git_index_free(index);
git_repository_free(repo); git_repository_free(repo);
} }
......
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