On Mon, 3 Jan 2011, Amr Shahin wrote:

Are we still on deciding ? If so i can try compiling with a C98

No, we're not deciding anymore, I've put down my large dictator foot and made my choice. The answer might still be interesting to someone but I find the response telling enough. If they don't put efforts into being C89 compliant they surely will not be that in the long run.

(This should not be read as any sort of criticism against the Check project or software, it looks neat but isn't really suitable for this project at this point.)

Right now I'm fiddling with a way to build a separate (static) library to use for the unit tests and I'm attaching my work so far on that (to be applied on top of the previous patch).

I tried to build libcurl with -Dstatic= passed to the compiler for the fun of it, and it shows that when we want to add unit tests for any function that is currently declared static, we should:

A) use a define for that function's static, perhaps UNITSTATIC or something so
   that we can move one function at a time to this and the functions that we
   won't bother to unittest we can leave as-is

B) provide prototypes internally for the UNITSTATIC functions as otherwise we
   get warnings from picky compilers

Having a separate define also is good as it shows to the reader of the code that the function is unit-tested so when it is to be changed, the tests might need to get adjusted.

--

 / daniel.haxx.se
From 53640a3ce09a433a92d88d864b2b062b0a684c59 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <[email protected]>
Date: Mon, 3 Jan 2011 22:16:16 +0100
Subject: [PATCH] unittesting: build a separate static lib

When configure --enable-debug has been used, all files in lib/ are now
built twice and a separate static library crafted for unit-testing will
be linked. The unit tests in the tests/unit subdir will use that
library.
---
 lib/Makefile.am        |   17 ++++++++++++++---
 tests/unit/Makefile.am |   13 +++++++++++--
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 4a35c72..0c7497f 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,7 +5,7 @@
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 1998 - 2010, Daniel Stenberg, <[email protected]>, et al.
+# Copyright (C) 1998 - 2011, Daniel Stenberg, <[email protected]>, et al.
 #
 # This software is licensed as described in the file COPYING, which
 # you should have received as part of this distribution. The terms
@@ -46,7 +46,7 @@ lib_LTLIBRARIES = libcurl.la
 LIBCURL_LIBS = @LIBCURL_LIBS@
 
 # This might hold -Werror
-CFLAGS += @CURL_CFLAG_EXTRAS@
+libcurl_la_CFLAGS = $(CFLAGS) @CURL_CFLAG_EXTRAS@
 
 # Specify our include paths here, and do it relative to $(top_srcdir) and
 # $(top_builddir), to ensure that these paths which belong to the library
@@ -116,12 +116,23 @@ if MIMPURE
 MIMPURE = -mimpure-text
 endif
 
-libcurl_la_LDFLAGS = $(UNDEF) $(VERSIONINFO) $(MIMPURE) $(LIBCURL_LIBS)
+LINKFLAGS=$(UNDEF) $(MIMPURE) $(LIBCURL_LIBS)
+
+libcurl_la_LDFLAGS = $(LINKFLAGS) $(VERSIONINFO)
+
+# as unit testing will compile and link everything an extra time, we only
+# do it if debug is enabled
+if CURLDEBUG
+noinst_LTLIBRARIES = libcurlu.la
+libcurlu_la_CFLAGS = -DUNITTESTS
+libcurlu_la_LDFLAGS = -static $(LINKFLAGS)
+endif
 
 # Makefile.inc provides the CSOURCES and HHEADERS defines
 include Makefile.inc
 
 libcurl_la_SOURCES = $(CSOURCES) $(HHEADERS)
+libcurlu_la_SOURCES = $(CSOURCES) $(HHEADERS)
 
 WIN32SOURCES = $(CSOURCES)
 WIN32HEADERS = $(HHEADERS) config-win32.h
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 6979228..501ddeb 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -52,11 +52,13 @@ INCLUDES = -I$(top_builddir)/include/curl \
 	   -I$(top_srcdir)/tests/libtest
 endif
 
+if CURLDEBUG
+
 EXTRA_DIST = Makefile.inc
 
-LDADD = $(top_srcdir)/tests/libtest/first.o $(top_builddir)/lib/libcurl.la \
+LDADD = $(top_srcdir)/tests/libtest/first.o $(top_builddir)/lib/libcurlu.la \
 	@CURL_LIBS@
-DEPENDENCIES = $(top_builddir)/lib/libcurl.la
+DEPENDENCIES = $(top_builddir)/lib/libcurlu.la
 
 # Makefile.inc provides the source defines (TESTUTIL, SUPPORTFILES,
 # noinst_PROGRAMS, lib*_SOURCES, and lib*_CFLAGS)
@@ -66,3 +68,10 @@ if NO_UNDEFINED
 # The -no-undefined flag is crucial to build fine on some platforms
 UNDEF = -no-undefined
 endif
+
+
+else
+# do nothing if debug was not enabled
+all:
+
+endif
\ No newline at end of file
-- 
1.7.2.3

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to