Update clar to a80e7f30
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
diff --git a/tests-clar/clar.c b/tests-clar/clar.c
index a7d8d30..10bea87 100644
--- a/tests-clar/clar.c
+++ b/tests-clar/clar.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (c) Vicent Marti. All rights reserved.
+ *
+ * This file is part of clar, distributed under the ISC license.
+ * For full terms see the included COPYING file.
+ */
#include <assert.h>
#include <setjmp.h>
#include <stdlib.h>
@@ -75,6 +81,7 @@ static struct {
int report_errors_only;
int exit_on_error;
+ int report_suite_names;
struct clar_error *errors;
struct clar_error *last_error;
@@ -207,12 +214,12 @@ clar_usage(const char *arg)
{
printf("Usage: %s [options]\n\n", arg);
printf("Options:\n");
- printf(" -sname\t\tRun only the suite with `name`\n");
- printf(" -iname\t\tInclude the suite with `name`\n");
- printf(" -xname\t\tExclude the suite with `name`\n");
- printf(" -q \t\tOnly report tests that had an error\n");
- printf(" -Q \t\tQuit as soon as a test fails\n");
- printf(" -l \t\tPrint suite names\n");
+ printf(" -sname\tRun only the suite with `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");
+ printf(" -Q \tQuit as soon as a test fails\n");
+ printf(" -l \tPrint suite names\n");
exit(-1);
}
@@ -231,7 +238,7 @@ clar_parse_args(int argc, char **argv)
case 's':
case 'i':
case 'x': { /* given suite name */
- int offset = (argument[2] == '=') ? 3 : 2;
+ int offset = (argument[2] == '=') ? 3 : 2, found = 0;
char action = argument[1];
size_t j, len;
@@ -243,16 +250,25 @@ clar_parse_args(int argc, char **argv)
for (j = 0; j < _clar_suite_count; ++j) {
if (strncmp(argument, _clar_suites[j].name, len) == 0) {
+ int exact = !strcmp(argument, _clar_suites[j].name);
+
+ ++found;
+
+ if (!exact)
+ _clar.report_suite_names = 1;
+
switch (action) {
case 's': clar_run_suite(&_clar_suites[j]); break;
case 'i': _clar_suites[j].enabled = 1; break;
case 'x': _clar_suites[j].enabled = 0; break;
}
- break;
+
+ if (exact)
+ break;
}
}
- if (j == _clar_suite_count) {
+ if (!found) {
clar_print_onabort("No suite matching '%s' found.\n", argument);
exit(-1);
}
diff --git a/tests-clar/clar.h b/tests-clar/clar.h
index 8258741..2ba6416 100644
--- a/tests-clar/clar.h
+++ b/tests-clar/clar.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (c) Vicent Marti. All rights reserved.
+ *
+ * This file is part of clar, distributed under the ISC license.
+ * For full terms see the included COPYING file.
+ */
#ifndef __CLAR_TEST_H__
#define __CLAR_TEST_H__
diff --git a/tests-clar/clar/print.h b/tests-clar/clar/print.h
index db9da91..368016f 100644
--- a/tests-clar/clar/print.h
+++ b/tests-clar/clar/print.h
@@ -45,9 +45,10 @@ static void clar_print_ontest(const char *test_name, int test_number, int failed
static void clar_print_onsuite(const char *suite_name, int suite_index)
{
- /* noop */
+ if (_clar.report_suite_names)
+ printf("\n%s", suite_name);
+
(void)suite_index;
- (void)suite_name;
}
static void clar_print_onabort(const char *msg, ...)
diff --git a/tests-clar/generate.py b/tests-clar/generate.py
index 9d5c117..1c96f9b 100644
--- a/tests-clar/generate.py
+++ b/tests-clar/generate.py
@@ -1,4 +1,10 @@
#!/usr/bin/env python
+#
+# Copyright (c) Vicent Marti. All rights reserved.
+#
+# This file is part of clar, distributed under the ISC license.
+# For full terms see the included COPYING file.
+#
from __future__ import with_statement
from string import Template
@@ -11,12 +17,12 @@ class Module(object):
def _render_callback(self, cb):
if not cb:
- return '{ NULL, NULL }'
- return '{ "%s", &%s }' % (cb['short_name'], cb['symbol'])
+ return ' { NULL, NULL }'
+ return ' { "%s", &%s }' % (cb['short_name'], cb['symbol'])
class DeclarationTemplate(Template):
def render(self):
- out = "\n".join("extern %s;" % cb['declaration'] for cb in self.module.callbacks)
+ out = "\n".join("extern %s;" % cb['declaration'] for cb in self.module.callbacks) + "\n"
if self.module.initialize:
out += "extern %s;\n" % self.module.initialize['declaration']
@@ -36,12 +42,13 @@ class Module(object):
class InfoTemplate(Template):
def render(self):
return Template(
- r"""{
- "${clean_name}",
- ${initialize},
- ${cleanup},
- ${cb_ptr}, ${cb_count}, ${enabled}
- }"""
+ r"""
+ {
+ "${clean_name}",
+ ${initialize},
+ ${cleanup},
+ ${cb_ptr}, ${cb_count}, ${enabled}
+ }"""
).substitute(
clean_name = self.module.clean_name(),
initialize = self._render_callback(self.module.initialize),
@@ -208,13 +215,13 @@ class TestSuite(object):
data.write(t.render())
suites = "static struct clar_suite _clar_suites[] = {" + ','.join(
- Module.InfoTemplate(module).render() for module in self.modules.values()
- ) + "};"
+ Module.InfoTemplate(module).render() for module in sorted(self.modules.values(), key=lambda module: module.name)
+ ) + "\n};\n"
data.write(suites)
- data.write("static const size_t _clar_suite_count = %d;" % self.suite_count())
- data.write("static const size_t _clar_callback_count = %d;" % self.callback_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())
suite.save_cache()
return True