diff --git a/ChangeLog b/ChangeLog index 5b41094b..f1566ebb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-10-27 Mauro Tortonesi + + * Makefile.in: Added basic support for unit testing. + 2005-08-26 Stepan Kasal * configure.in: Abort configure if --with-ssl given but SSL diff --git a/Makefile.in b/Makefile.in index f9722a83..22c03d2a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 diff --git a/src/ChangeLog b/src/ChangeLog index bf96c92e..295ab622 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2005-10-27 Mauro Tortonesi + + * Makefile.in: Added basic support for unit testing. + + * test.c: Ditto. + + * test.h: Ditto. + 2005-10-13 Daniel Stenberg * http-ntlm.c (ntlm_output): Fixed buffer overflow vulnerability. diff --git a/src/Makefile.in b/src/Makefile.in index e0313220..5a857ed5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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 # diff --git a/src/main.c b/src/main.c index 0fc5b3d7..fe9c8f33 100644 --- a/src/main.c +++ b/src/main.c @@ -670,6 +670,7 @@ GNU General Public License for more details.\n"), stdout); exit (0); } +#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 */ #if defined(SIGHUP) || defined(SIGUSR1) diff --git a/src/test.c b/src/test.c new file mode 100644 index 00000000..a124eeaa --- /dev/null +++ b/src/test.c @@ -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 + +#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 index 00000000..60e03c79 --- /dev/null +++ b/src/test.h @@ -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 + */ +