#ifndef SQUID_INCLUDE_UNITTESTMAIN_H
#define SQUID_INCLUDE_UNITTESTMAIN_H
+#if ENABLE_DEBUG_SECTION
+#include "Debug.h"
+#endif /* ENABLE_DEBUG_SECTION */
+
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/TextTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
int
main( int argc, char* argv[] )
{
+#if ENABLE_DEBUG_SECTION
+ Debug::Levels[ENABLE_DEBUG_SECTION] = 99;
+#endif
+
// Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
size_t BuildPrefixInit();
const char * SkipBuildPrefix(const char* path);
-/* Debug stream */
+/* Debug stream
+ *
+ * Unit tests can enable full debugging to stderr for one
+ * debug section; to enable this, #define ENABLE_DEBUG_SECTION to the
+ * section number before any header
+ */
#define debugs(SECTION, LEVEL, CONTENT) \
do { \
if ((Debug::level = (LEVEL)) <= Debug::Levels[SECTION]) { \
std::ostream &
Debug::getDebugOut()
{
- assert(TheDepth >= 0);
- ++TheDepth;
- if (TheDepth > 1) {
- assert(CurrentDebug);
- *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{";
- } else {
- assert(!CurrentDebug);
+ if (!CurrentDebug) {
CurrentDebug = new Debug::OutStream;
- // set default formatting flags
CurrentDebug->setf(std::ios::fixed);
CurrentDebug->precision(2);
}
void
Debug::finishDebug()
{
- assert(TheDepth >= 0);
- assert(CurrentDebug);
- if (TheDepth > 1) {
- *CurrentDebug << "}-" << TheDepth << std::endl;
- } else {
- assert(TheDepth == 1);
- _db_print("%s\n", CurrentDebug->str().c_str());
- delete CurrentDebug;
- CurrentDebug = NULL;
- }
- --TheDepth;
+ std::cerr << "debugs: " << CurrentDebug->str() << std::endl;
+ delete CurrentDebug;
+ CurrentDebug = NULL;
}
void
Debug::xassert(const char *msg, const char *file, int line)
{
- if (CurrentDebug) {
- *CurrentDebug << "assertion failed: " << file << ":" << line <<
- ": \"" << msg << "\"";
- }
+ getDebugOut() << "assertion failed: " << file << ":" << line <<
+ ": \"" << msg << "\"";
abort();
}