Browse Source

[trac542] Set default for cacthing exceptions based on compiler

The default is to catch exceptions if compiling using clang, and not
to catch them for everything else.
Stephen Morris 14 years ago
parent
commit
6a9f0125c6
1 changed files with 32 additions and 1 deletions
  1. 32 1
      src/lib/util/unittests/run_all.cc

+ 32 - 1
src/lib/util/unittests/run_all.cc

@@ -29,7 +29,38 @@ int
 run_all() {
 run_all() {
     int ret = 0;
     int ret = 0;
 
 
-    if (getenv("B10TEST_CATCH_EXCEPTION") != NULL) {
+    // The catching of exceptions generated in tests is controlled by the
+    // B10TEST_CATCH_EXCEPTIONS environment variable.  Setting this to
+    // 1 enables the cacthing of exceptions; setting it to 0 disables it.
+    // Anything else causes a message to be printed to stderr and the default
+    // taken.  (The default is to catch exceptions if compiling with clang
+    // and false if not.)
+#ifdef __clang__
+    bool catch_exception = true;
+#else
+    bool catch_exception = false;
+#endif
+
+    const char* b10test_catch_exception = getenv("B10TEST_CATCH_EXCEPTION");
+    if (b10test_catch_exception != NULL) {
+        if (strcmp(b10test_catch_exception, "1") == 0) {
+            catch_exception = true;
+        } else if (strcmp(b10test_catch_exception, "0") == 0) {
+            catch_exception = false;
+        } else {
+            std::cerr << "***ERROR: B10TEST_CATCH_EXCEPTION is '"
+                         << b10test_catch_exception
+                         << "': allowed values are '1' or '0'.\n"
+                      << "          The default value of "
+                         << (catch_exception ?
+                                "1 (exception catching enabled)":
+                                "0 (exception catching disabled)")
+                         << " will be used.\n";
+        }
+    }
+
+    // Actually run the code
+    if (catch_exception) {
         try {
         try {
             ret = RUN_ALL_TESTS();
             ret = RUN_ALL_TESTS();
         } catch (const isc::Exception& ex) {
         } catch (const isc::Exception& ex) {