Commit e8a92fe10711fdb5e746a7918ad580991e7d1265

Russell Belfer 2013-01-21T13:39:53

Update clar to a80e7f30

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