Commit f4183347 by Russell Belfer

Update clar to latest version

parent de0555a3
...@@ -183,10 +183,10 @@ clar_run_test( ...@@ -183,10 +183,10 @@ clar_run_test(
} }
static void static void
clar_run_suite(const struct clar_suite *suite, const char *name) clar_run_suite(const struct clar_suite *suite, const char *filter)
{ {
const struct clar_func *test = suite->tests; const struct clar_func *test = suite->tests;
size_t i, namelen; size_t i, matchlen;
if (!suite->enabled) if (!suite->enabled)
return; return;
...@@ -200,21 +200,21 @@ clar_run_suite(const struct clar_suite *suite, const char *name) ...@@ -200,21 +200,21 @@ clar_run_suite(const struct clar_suite *suite, const char *name)
_clar.active_suite = suite->name; _clar.active_suite = suite->name;
_clar.suite_errors = 0; _clar.suite_errors = 0;
if (name) { if (filter) {
size_t suitelen = strlen(suite->name); size_t suitelen = strlen(suite->name);
namelen = strlen(name); matchlen = strlen(filter);
if (namelen <= suitelen) { if (matchlen <= suitelen) {
name = NULL; filter = NULL;
} else { } else {
name += suitelen; filter += suitelen;
while (*name == ':') while (*filter == ':')
++name; ++filter;
namelen = strlen(name); matchlen = strlen(filter);
} }
} }
for (i = 0; i < suite->test_count; ++i) { for (i = 0; i < suite->test_count; ++i) {
if (name && strncmp(test[i].name, name, namelen)) if (filter && strncmp(test[i].name, filter, matchlen))
continue; continue;
_clar.active_test = test[i].name; _clar.active_test = test[i].name;
...@@ -230,7 +230,7 @@ clar_usage(const char *arg) ...@@ -230,7 +230,7 @@ clar_usage(const char *arg)
{ {
printf("Usage: %s [options]\n\n", arg); printf("Usage: %s [options]\n\n", arg);
printf("Options:\n"); printf("Options:\n");
printf(" -sname\tRun only the suite with `name`\n"); printf(" -sname\tRun only the suite with `name` (can go to individual test name)\n");
printf(" -iname\tInclude the suite with `name`\n"); printf(" -iname\tInclude the suite with `name`\n");
printf(" -xname\tExclude the suite with `name`\n"); printf(" -xname\tExclude the suite with `name`\n");
printf(" -q \tOnly report tests that had an error\n"); printf(" -q \tOnly report tests that had an error\n");
...@@ -256,21 +256,20 @@ clar_parse_args(int argc, char **argv) ...@@ -256,21 +256,20 @@ clar_parse_args(int argc, char **argv)
case 'x': { /* given suite name */ case 'x': { /* given suite name */
int offset = (argument[2] == '=') ? 3 : 2, found = 0; int offset = (argument[2] == '=') ? 3 : 2, found = 0;
char action = argument[1]; char action = argument[1];
size_t j, len, cmplen; size_t j, arglen, suitelen, cmplen;
argument += offset; argument += offset;
len = strlen(argument); arglen = strlen(argument);
if (len == 0) if (arglen == 0)
clar_usage(argv[0]); clar_usage(argv[0]);
for (j = 0; j < _clar_suite_count; ++j) { for (j = 0; j < _clar_suite_count; ++j) {
cmplen = strlen(_clar_suites[j].name); suitelen = strlen(_clar_suites[j].name);
if (cmplen > len) cmplen = (arglen < suitelen) ? arglen : suitelen;
cmplen = len;
if (strncmp(argument, _clar_suites[j].name, cmplen) == 0) { if (strncmp(argument, _clar_suites[j].name, cmplen) == 0) {
int exact = !strcmp(argument, _clar_suites[j].name); int exact = (arglen >= suitelen);
++found; ++found;
...@@ -419,7 +418,16 @@ void clar__assert_equal_s( ...@@ -419,7 +418,16 @@ void clar__assert_equal_s(
if (!match) { if (!match) {
char buf[4096]; char buf[4096];
if (s1 && s2) {
int pos;
for (pos = 0; s1[pos] == s2[pos] && s1[pos] && s2[pos]; ++pos)
/* find differing byte offset */;
snprint_eq(buf, sizeof(buf), "'%s' != '%s' (at byte %d)", s1, s2, pos);
} else {
snprint_eq(buf, sizeof(buf), "'%s' != '%s'", s1, s2); snprint_eq(buf, sizeof(buf), "'%s' != '%s'", s1, s2);
}
clar__fail(file, line, err, buf, should_abort); clar__fail(file, line, err, buf, should_abort);
} }
} }
......
...@@ -18,9 +18,9 @@ static int ...@@ -18,9 +18,9 @@ static int
find_tmp_path(char *buffer, size_t length) find_tmp_path(char *buffer, size_t length)
{ {
#ifndef _WIN32 #ifndef _WIN32
static const size_t var_count = 4; static const size_t var_count = 5;
static const char *env_vars[] = { static const char *env_vars[] = {
"TMPDIR", "TMP", "TEMP", "USERPROFILE" "CLAR_TMP", "TMPDIR", "TMP", "TEMP", "USERPROFILE"
}; };
size_t i; size_t i;
...@@ -43,6 +43,12 @@ find_tmp_path(char *buffer, size_t length) ...@@ -43,6 +43,12 @@ find_tmp_path(char *buffer, size_t length)
} }
#else #else
DWORD env_len;
if ((env_len = GetEnvironmentVariable("CLAR_TMP", buffer, length)) > 0 &&
env_len < length)
return 0;
if (GetTempPath((DWORD)length, buffer)) if (GetTempPath((DWORD)length, buffer))
return 0; return 0;
#endif #endif
...@@ -61,9 +67,7 @@ static void clar_unsandbox(void) ...@@ -61,9 +67,7 @@ static void clar_unsandbox(void)
if (_clar_path[0] == '\0') if (_clar_path[0] == '\0')
return; return;
#ifdef _WIN32
chdir(".."); chdir("..");
#endif
fs_rm(_clar_path); fs_rm(_clar_path);
} }
......
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