Parcourir la 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 il y a 14 ans
Parent
commit
6a9f0125c6
1 fichiers modifiés avec 32 ajouts et 1 suppressions
  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() {
     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 {
             ret = RUN_ALL_TESTS();
         } catch (const isc::Exception& ex) {