]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Implemented selective debugs() output for unit tests
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 19 Feb 2015 14:52:14 +0000 (15:52 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 19 Feb 2015 14:52:14 +0000 (15:52 +0100)
include/unitTestMain.h
src/Debug.h
src/tests/stub_debug.cc

index dfd8e35492c02b8f9d986f9cba8050c8b37c0720..840b32da92addca23d64adcf3be274ea0c91210f 100644 (file)
@@ -9,6 +9,10 @@
 #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;
 
index 596d3d55e3b060d7160f2a18c172526ca9e78996..ff7f25cab0791fd50f4200c1b641731d6fb24199 100644 (file)
@@ -88,7 +88,12 @@ extern FILE *debug_log;
 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]) { \
index 6064641daa877e7c3840b748a87762240e3ea925..5cd6f178e48cd5d243ad160ade54a8062675d70e 100644 (file)
@@ -91,15 +91,8 @@ Debug::OutStream *Debug::CurrentDebug(NULL);
 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);
     }
@@ -113,26 +106,16 @@ Debug::parseOptions(char const *)
 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();
 }