Fix tests dying if an exception is thrown.
authorCharles Giessen <charles@lunarg.com>
Sat, 6 May 2023 05:42:28 +0000 (23:42 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Mon, 29 May 2023 23:45:08 +0000 (17:45 -0600)
The test framework will generate an exception if any googletest assertion fails.
However, if there already is an ongoing exception, we do not want to throw
another one. Thus, we check if std::current_exception() is nullptr, and only
throw our own exception if it is nullptr.

tests/loader_testing_main.cpp

index 01b61bc72dc6e7a87d5a13bd4aac6ae742fc1325..6b5a44082e4c9dda0f8044a0f263063268aff8a0 100644 (file)
 class ThrowListener : public testing::EmptyTestEventListener {
     void OnTestPartResult(const testing::TestPartResult& result) override {
         if (result.type() == testing::TestPartResult::kFatalFailure) {
+            // We need to make sure an exception wasn't already thrown so we dont throw another exception at the same time
+            std::exception_ptr ex = std::current_exception();
+            if (ex) {
+                return;
+            }
             throw testing::AssertionException(result);
         }
     }