Index: doxer/ChangeLog
===================================================================
--- doxer/ChangeLog	(revision 4376)
+++ doxer/ChangeLog	(working copy)
@@ -1,3 +1,15 @@
+Sat Sep 15 20:29:37 2007  Stefan Westerfeld  <stefan@space.twc.de>
+
+	* Config.py: Implemented doxer_warn_if_fail() and
+	doxer_warn_if_reached(), as alternative to assertions. For details on
+	why using these is better than assert(), see #477211.
+
+	* warntest.py: Added a small program which tests doxer_warn_if_fail()
+	and doxer_warn_if_reached().
+
+	* doxer.py: Handle --fatal-warnings which makes the program abort on
+	doxer_warn() warnings, so that a full stacktrace is shown.
+
 2007-09-08 04:00:42  Tim Janik  <timj@gtk.org>
 
 	* DoxiParser.py (doxer_setget): catch missing git-log or git repo.
Index: doxer/Config.py
===================================================================
--- doxer/Config.py	(revision 4376)
+++ doxer/Config.py	(working copy)
@@ -2,6 +2,7 @@
 #
 # Doxer - Software documentation system
 # Copyright (C) 2005-2006 Tim Janik
+# Copyright (C) 2007 Stefan Westerfeld
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -72,6 +73,26 @@ class ConstDict:
           line += " "
         line += str (s)
       sys.stderr.write ("|> " + line + "\n")
+  # doxer warnings
+  def doxer_warn (self, msg, stacklevel=1):
+    class DoxerWarning (UserWarning):
+      """
+        Doxer's own warnings (we subclass to not conflict with installed warning filters)
+      """
+    import warnings
+    if self.__dict__.has_key ("fatal_warnings"):
+      raise msg
+    else:
+      warnings.warn (msg + ": ", DoxerWarning, stacklevel=stacklevel+1)
+  def doxer_warn_if_reached (self):
+    import inspect
+    frame_info = inspect.getframeinfo (inspect.currentframe (1))
+    self.doxer_warn ("doxer_warn_if_reached() encountered in function %s" % (frame_info[2]), 2)
+  def doxer_warn_if_fail (self, condition):
+    import inspect
+    if not condition:
+      frame_info = inspect.getframeinfo (inspect.currentframe (1))
+      self.doxer_warn ("doxer_warn_if_fail() failed in function %s" % (frame_info[2]), 2)
 
 # --- module interface ---
 sys.modules[__name__] = ConstDict (init_dict)
Index: doxer/warntest.py
===================================================================
--- doxer/warntest.py	(revision 0)
+++ doxer/warntest.py	(revision 0)
@@ -0,0 +1,34 @@
+#!/usr/bin/env python2.4
+#
+# Doxer - Software documentation system
+# Copyright (C) 2007 Stefan Westerfeld
+#
+# This program 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.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+
+import Config
+from Config import doxer_warn_if_fail, doxer_warn_if_reached
+
+def foo():
+  # ... suppose here is code that should always return ...
+  doxer_warn_if_reached()             # programmers mistake
+
+def bar():
+  doxer_warn_if_fail (20 == 10 + 10)
+  doxer_warn_if_fail (42 == 20 + 20)  # programmers mistake
+
+# Config.fatal_warnings = True
+
+foo()
+bar()
Index: doxer/doxer.py
===================================================================
--- doxer/doxer.py	(revision 4376)
+++ doxer/doxer.py	(working copy)
@@ -412,6 +412,8 @@ def parse_command_and_args():
     if arg == '--debug':
       Config.debug = True
       Config.print_traceback = True
+    elif arg == '--fatal-warnings':
+      Config.fatal_warnings = True
     elif arg == '--help' or arg == '-h':
       print_help ()
       sys.exit (0)
@@ -484,6 +486,7 @@ def print_help (with_help = True):
   print "  --help, -h                print this help message"
   print "  --version, -v             print version info"
   print "  --debug                   print debug information"
+  print "  --fatal-warnings          abort program on doxer_warn()"
   print "  -d OUTPUTDIR              write output to OUTPUTDIR/ (defaults to ./)"
   print "  -D name value             define 'name' to 'value'"
   print "  -I DIRECTORY              add DIRECTORY to include path"
