]> sjero.net Git - wget/commitdiff
[svn] Added basic support for unit testing
authormtortonesi <devnull@localhost>
Thu, 27 Oct 2005 14:13:40 +0000 (07:13 -0700)
committermtortonesi <devnull@localhost>
Thu, 27 Oct 2005 14:13:40 +0000 (07:13 -0700)
ChangeLog
Makefile.in
src/ChangeLog
src/Makefile.in
src/main.c
src/test.c [new file with mode: 0644]
src/test.h [new file with mode: 0644]

index 5b41094bb8e724b1d63a789a2ae03dbf8e298098..f1566ebba76d0ea3a1c72e6d8c8d450453ca33af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-10-27  Mauro Tortonesi  <mauro@ferrara.linux.it>
+
+       * Makefile.in: Added basic support for unit testing.
+       
 2005-08-26  Stepan Kasal  <kasal@ucw.cz>
 
        * configure.in: Abort configure if --with-ssl given but SSL
index f9722a833de544855c4db987bf095a39b68f4600..22c03d2a4fcdebceeb98b4d0534edb84077156e9 100644 (file)
@@ -80,12 +80,20 @@ CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' LIBS='$(LIBS)' \
 prefix='$(prefix)' exec_prefix='$(exec_prefix)' bindir='$(bindir)' \
 infodir='$(infodir)' mandir='$(mandir)' manext='$(manext)'
 
+TESTDEFS = CC='$(CC)' CPPFLAGS='$(CPPFLAGS) -DTESTING' DEFS='$(DEFS)' \
+CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' LIBS='$(LIBS)' \
+prefix='$(prefix)' exec_prefix='$(exec_prefix)' bindir='$(bindir)' \
+infodir='$(infodir)' mandir='$(mandir)' manext='$(manext)'
+
 # subdirectories in the distribution
 SUBDIRS = src doc po util windows
 
 # default target
 all: src/config.h Makefile $(SUBDIRS)
 
+test: src/config.h Makefile 
+       cd src && $(MAKE) $(TESTDEFS) clean && $(MAKE) $(TESTDEFS) test$(exeext)
+       
 check: all
 
 $(SUBDIRS): FORCE
index bf96c92ed184040dca3590be5ebda8afc6d4b203..295ab622921ab9f0317ef01f2b068c0fc9380030 100644 (file)
@@ -1,3 +1,11 @@
+2005-10-27  Mauro Tortonesi  <mauro@ferrara.linux.it>
+
+       * Makefile.in: Added basic support for unit testing.
+
+       * test.c: Ditto.
+       
+       * test.h: Ditto.
+       
 2005-10-13  Daniel Stenberg  <daniel@haxx.se>
 
        * http-ntlm.c (ntlm_output): Fixed buffer overflow vulnerability.
index e031322094e0f6ef4218cf81191452eb850c55b0..5a857ed502c6ab9fc7f7fd9a245649c6bdd9172f 100644 (file)
@@ -102,6 +102,26 @@ $(OBJ): config-post.h config.h connect.h convert.h cookies.h ftp.h   \
         progress.h ptimer.h recur.h res.h retr.h safe-ctype.h ssl.h  \
         sysdep.h url.h utils.h wget.h xmalloc.h
 
+#
+# Dependencies for test binary
+#
+
+TESTOBJ = $(ALLOCA) cmpt.o connect.o convert.o cookies.o              \
+          ftp.o ftp-basic.o ftp-ls.o $(OPIE_OBJ) $(GETOPT_OBJ) hash.o \
+          host.o html-parse.o html-url.o http.o $(NTLM_OBJ) init.o    \
+          log.o main.o $(MD5_OBJ) netrc.o progress.o ptimer.o recur.o \
+          res.o retr.o safe-ctype.o snprintf.o $(SSL_OBJ) test.o      \
+         url.o utils.o version.o xmalloc.o
+
+$(TESTOBJ): config-post.h config.h connect.h convert.h cookies.h ftp.h   \
+            gen-md5.h getopt.h gnu-md5.h hash.h host.h html-parse.h      \
+            http-ntlm.h init.h log.h mswindows.h netrc.h options.h       \
+            progress.h ptimer.h recur.h res.h retr.h safe-ctype.h ssl.h  \
+            sysdep.h test.h url.h utils.h wget.h xmalloc.h
+
+test$(exeext): $(TESTOBJ)
+       $(LINK) $(TESTOBJ) $(LIBS)
+
 #
 # Dependencies for installing
 #
index 0fc5b3d70b17412b34981e7e5c07efb7b051eaa4..fe9c8f33403ed0034b21f0eb0697f6988b430a91 100644 (file)
@@ -670,6 +670,7 @@ GNU General Public License for more details.\n"), stdout);
   exit (0);
 }
 \f
+#ifndef TESTING
 int
 main (int argc, char *const *argv)
 {
@@ -1007,6 +1008,7 @@ Can't timestamp and not clobber old files at the same time.\n"));
   else
     return 1;
 }
+#endif /* TESTING */
 \f
 #if defined(SIGHUP) || defined(SIGUSR1)
 
diff --git a/src/test.c b/src/test.c
new file mode 100644 (file)
index 0000000..a124eea
--- /dev/null
@@ -0,0 +1,73 @@
+/* Unit testing.
+   Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Wget.
+
+GNU Wget is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GNU Wget is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Wget; if not, write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+In addition, as a special exception, the Free Software Foundation
+gives permission to link the code of its release of Wget with the
+OpenSSL project's "OpenSSL" library (or with modified versions of it
+that use the same license as the "OpenSSL" library), and distribute
+the linked executables.  You must obey the GNU General Public License
+in all respects for all of the code used other than "OpenSSL".  If you
+modify this file, you may extend this exception to your version of the
+file, but you are not obligated to do so.  If you do not wish to do
+so, delete this exception statement from your version.  */
+
+#include <stdio.h>
+
+#include "test.h"
+
+#ifndef TESTING
+#error "TESTING not set!!!"
+#endif
+
+int tests_run;
+
+// char *test_ccache();
+
+static char *
+all_tests()
+{
+  // mu_run_test (test_ccache);
+  
+  return NULL;
+}
+
+
+int
+main (void) 
+{
+  char *result = all_tests();
+  
+  if (result != NULL) 
+    {
+      puts (result);
+    }
+  else 
+    {
+      printf ("ALL TESTS PASSED\n");
+    }
+  
+  printf ("Tests run: %d\n", tests_run);
+  return result != 0;
+}
+
+/*
+ * vim: et ts=2 sw=2
+ */
+
diff --git a/src/test.h b/src/test.h
new file mode 100644 (file)
index 0000000..60e03c7
--- /dev/null
@@ -0,0 +1,45 @@
+/* Unit testing declarations.
+   Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Wget.
+
+GNU Wget is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GNU Wget is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Wget; if not, write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+In addition, as a special exception, the Free Software Foundation
+gives permission to link the code of its release of Wget with the
+OpenSSL project's "OpenSSL" library (or with modified versions of it
+that use the same license as the "OpenSSL" library), and distribute
+the linked executables.  You must obey the GNU General Public License
+in all respects for all of the code used other than "OpenSSL".  If you
+modify this file, you may extend this exception to your version of the
+file, but you are not obligated to do so.  If you do not wish to do
+so, delete this exception statement from your version.  */
+
+#ifndef TEST_H
+#define TEST_H
+
+/* from MinUnit */
+#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
+#define mu_run_test(test) do { char *message = test(); tests_run++; \
+                               if (message) return message; } while (0)
+
+extern int tests_run;
+
+#endif /* TEST_H */
+
+/*
+ * vim: et ts=2 sw=2
+ */
+