Update clar to latest version
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
diff --git a/tests-clar/clar.c b/tests-clar/clar.c
index 0eae81b..fb10dd3 100644
--- a/tests-clar/clar.c
+++ b/tests-clar/clar.c
@@ -183,10 +183,10 @@ clar_run_test(
}
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;
- size_t i, namelen;
+ size_t i, matchlen;
if (!suite->enabled)
return;
@@ -200,21 +200,21 @@ clar_run_suite(const struct clar_suite *suite, const char *name)
_clar.active_suite = suite->name;
_clar.suite_errors = 0;
- if (name) {
+ if (filter) {
size_t suitelen = strlen(suite->name);
- namelen = strlen(name);
- if (namelen <= suitelen) {
- name = NULL;
+ matchlen = strlen(filter);
+ if (matchlen <= suitelen) {
+ filter = NULL;
} else {
- name += suitelen;
- while (*name == ':')
- ++name;
- namelen = strlen(name);
+ filter += suitelen;
+ while (*filter == ':')
+ ++filter;
+ matchlen = strlen(filter);
}
}
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;
_clar.active_test = test[i].name;
@@ -230,7 +230,7 @@ clar_usage(const char *arg)
{
printf("Usage: %s [options]\n\n", arg);
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(" -xname\tExclude the suite with `name`\n");
printf(" -q \tOnly report tests that had an error\n");
@@ -256,21 +256,20 @@ clar_parse_args(int argc, char **argv)
case 'x': { /* given suite name */
int offset = (argument[2] == '=') ? 3 : 2, found = 0;
char action = argument[1];
- size_t j, len, cmplen;
+ size_t j, arglen, suitelen, cmplen;
argument += offset;
- len = strlen(argument);
+ arglen = strlen(argument);
- if (len == 0)
+ if (arglen == 0)
clar_usage(argv[0]);
for (j = 0; j < _clar_suite_count; ++j) {
- cmplen = strlen(_clar_suites[j].name);
- if (cmplen > len)
- cmplen = len;
+ suitelen = strlen(_clar_suites[j].name);
+ cmplen = (arglen < suitelen) ? arglen : suitelen;
if (strncmp(argument, _clar_suites[j].name, cmplen) == 0) {
- int exact = !strcmp(argument, _clar_suites[j].name);
+ int exact = (arglen >= suitelen);
++found;
@@ -419,7 +418,16 @@ void clar__assert_equal_s(
if (!match) {
char buf[4096];
- snprint_eq(buf, sizeof(buf), "'%s' != '%s'", s1, s2);
+
+ 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);
+ }
+
clar__fail(file, line, err, buf, should_abort);
}
}
diff --git a/tests-clar/clar/sandbox.h b/tests-clar/clar/sandbox.h
index bed3011..1ca6fca 100644
--- a/tests-clar/clar/sandbox.h
+++ b/tests-clar/clar/sandbox.h
@@ -18,9 +18,9 @@ static int
find_tmp_path(char *buffer, size_t length)
{
#ifndef _WIN32
- static const size_t var_count = 4;
+ static const size_t var_count = 5;
static const char *env_vars[] = {
- "TMPDIR", "TMP", "TEMP", "USERPROFILE"
+ "CLAR_TMP", "TMPDIR", "TMP", "TEMP", "USERPROFILE"
};
size_t i;
@@ -43,6 +43,12 @@ find_tmp_path(char *buffer, size_t length)
}
#else
+ DWORD env_len;
+
+ if ((env_len = GetEnvironmentVariable("CLAR_TMP", buffer, length)) > 0 &&
+ env_len < length)
+ return 0;
+
if (GetTempPath((DWORD)length, buffer))
return 0;
#endif
@@ -61,9 +67,7 @@ static void clar_unsandbox(void)
if (_clar_path[0] == '\0')
return;
-#ifdef _WIN32
chdir("..");
-#endif
fs_rm(_clar_path);
}