Quellcode durchsuchen

libdpkg: Make test main function a TEST_ENTRY macro

This avoids confusing coverage programs, as the file that actually
contains the main function is the test itself.
Guillem Jover vor 10 Jahren
Ursprung
Commit
0f599ea0ae

+ 4 - 0
debian/changelog

@@ -82,6 +82,10 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
       verify digests too. Prompted by Johannes Schauer <josch@debian.org>.
     - Document the behavior for consecutive calls to Dpkg perl module parse()
       methods. Prompted by Johannes Schauer <josch@debian.org>.
+  * Test suite:
+    - Make test main function a TEST_ENTRY macro. This avoids confusing
+      coverage programs, as the file that actually contains the main function
+      is the test itself.
   * Build system:
     - Add support for profiling perl modules.
     - Clean up compiler and linker automatic flag usage in configure.

+ 1 - 2
lib/dpkg/t/t-ar.c

@@ -50,8 +50,7 @@ test_ar_member_is_illegal(void)
 	test_fail(dpkg_ar_member_is_illegal(&arh));
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(4);
 

+ 1 - 2
lib/dpkg/t/t-arch.c

@@ -209,8 +209,7 @@ test_dpkg_arch_describe(void)
 	test_str(dpkg_arch_describe(arch), ==, ARCHITECTURE);
 }
 
-void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(60);
 

+ 1 - 2
lib/dpkg/t/t-buffer.c

@@ -71,8 +71,7 @@ test_fdio_hash(void)
 	test_pass(unlink(test_file) == 0);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(10);
 

+ 1 - 2
lib/dpkg/t/t-c-ctype.c

@@ -97,8 +97,7 @@ test_casing(void)
 	test_pass(c_tolower(-1) == -1);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(2063);
 

+ 1 - 2
lib/dpkg/t/t-command.c

@@ -243,8 +243,7 @@ test_command_pager(void)
 	test_str(pager, ==, CAT);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(52);
 

+ 1 - 2
lib/dpkg/t/t-deb-version.c

@@ -62,8 +62,7 @@ test_deb_version_parse(void)
 	/* FIXME: Complete. */
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(21);
 

+ 1 - 2
lib/dpkg/t/t-error.c

@@ -72,8 +72,7 @@ test_dpkg_error_destroy(void)
 	test_pass(err.str == NULL);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(19);
 

+ 1 - 2
lib/dpkg/t/t-macros.c

@@ -24,8 +24,7 @@
 #include <dpkg/test.h>
 #include <dpkg/macros.h>
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(12);
 

+ 1 - 2
lib/dpkg/t/t-mod-db.c

@@ -49,8 +49,7 @@ test_db_dir(void)
 	free(dir);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(5);
 

+ 1 - 2
lib/dpkg/t/t-path.c

@@ -169,8 +169,7 @@ test_path_quote(void)
 	free(dst);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(41);
 

+ 1 - 2
lib/dpkg/t/t-pkg-list.c

@@ -81,8 +81,7 @@ test_pkg_list_prepend(void)
 	pkg_list_free(head);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(14);
 

+ 1 - 2
lib/dpkg/t/t-pkg-queue.c

@@ -107,8 +107,7 @@ test_pkg_queue_push_pop(void)
 	pkg_queue_destroy(&q);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(38);
 

+ 1 - 2
lib/dpkg/t/t-pkginfo.c

@@ -141,8 +141,7 @@ test_pkginfo_instance_tracking(void)
 	test_pass(pkgset_installed_instances(&set) == 0);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(28);
 

+ 1 - 2
lib/dpkg/t/t-progname.c

@@ -45,8 +45,7 @@ test_progname(void)
 	test_str(dpkg_get_progname(), ==, "newprogname");
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(3);
 

+ 1 - 2
lib/dpkg/t/t-string.c

@@ -195,8 +195,7 @@ test_str_strip_quotes(void)
 	test_str(str, ==, "completely quoted text");
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(50);
 

+ 1 - 2
lib/dpkg/t/t-subproc.c

@@ -84,8 +84,7 @@ test_subproc_fork(void)
 	test_pass(ret == -1);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	int fd;
 

+ 1 - 2
lib/dpkg/t/t-test-skip.c

@@ -23,8 +23,7 @@
 
 #include <dpkg/test.h>
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_skip_all("ignore all tests");
 

+ 1 - 2
lib/dpkg/t/t-test.c

@@ -23,8 +23,7 @@
 
 #include <dpkg/test.h>
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(20);
 

+ 1 - 2
lib/dpkg/t/t-trigger.c

@@ -41,8 +41,7 @@ test_trig_name_is_illegal(void)
 	test_pass(trig_name_is_illegal("/file/trigger") == NULL);
 }
 
-void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(9);
 

+ 1 - 2
lib/dpkg/t/t-varbuf.c

@@ -348,8 +348,7 @@ test_varbuf_detach(void)
 	free(str);
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(120);
 

+ 1 - 2
lib/dpkg/t/t-version.c

@@ -285,8 +285,7 @@ test_version_parse(void)
 	/* FIXME: Complete. */
 }
 
-static void
-test(void)
+TEST_ENTRY(test)
 {
 	test_plan(190);
 

+ 17 - 18
lib/dpkg/test.h

@@ -25,8 +25,10 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#ifndef TEST_MAIN_PROVIDED
+#ifndef TEST_MAIN_CTOR
 #include <dpkg/ehandle.h>
+#define TEST_MAIN_CTOR push_error_context()
+#define TEST_MAIN_DTOR pop_error_context(ehflag_normaltidy)
 #endif
 
 /**
@@ -121,22 +123,19 @@ static const char *test_skip_reason;
 
 /** @} */
 
-#ifndef TEST_MAIN_PROVIDED
-static void test(void);
-
-int
-main(int argc, char **argv)
-{
-	setvbuf(stdout, NULL, _IOLBF, 0);
-
-	push_error_context();
-
-	test();
-
-	pop_error_context(ehflag_normaltidy);
-
-	return 0;
-}
-#endif
+#define TEST_ENTRY(name) \
+static void name(void); \
+int \
+main(int argc, char **argv) \
+{ \
+	setvbuf(stdout, NULL, _IOLBF, 0); \
+ \
+	TEST_MAIN_CTOR; \
+	name(); \
+	TEST_MAIN_DTOR; \
+	return 0; \
+} \
+static void \
+name(void)
 
 #endif