This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch hotfix/promise_exception_test
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/hotfix/promise_exception_test 
by this push:
     new c6bcb27  Updates exception test to ensure a predictable 
exception.what()
c6bcb27 is described below

commit c6bcb27c61033ccbe360e2188756e30c62860faf
Author: Pepijn Noltes <[email protected]>
AuthorDate: Tue Sep 14 22:17:09 2021 +0200

    Updates exception test to ensure a predictable exception.what()
---
 libs/promises/api/celix/impl/SharedPromiseState.h |  4 ++--
 libs/promises/gtest/src/PromisesTestSuite.cc      | 10 +++++++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libs/promises/api/celix/impl/SharedPromiseState.h 
b/libs/promises/api/celix/impl/SharedPromiseState.h
index b0491bb..ebe39d7 100644
--- a/libs/promises/api/celix/impl/SharedPromiseState.h
+++ b/libs/promises/api/celix/impl/SharedPromiseState.h
@@ -944,7 +944,7 @@ void 
celix::impl::SharedPromiseState<T>::addOnFailureConsumeCallback(std::functi
             } catch (const std::exception &e) {
                 callback(e);
             } catch (...) {
-                //NOTE not a exception based on std::exception, "repacking" it 
to logical error
+                //NOTE not an exception based on std::exception, "repacking" 
it to logical error
                 std::logic_error logicError{"Unknown exception throw for the 
failure of A celix::Promise"};
                 callback(logicError);
             }
@@ -961,7 +961,7 @@ inline void 
celix::impl::SharedPromiseState<void>::addOnFailureConsumeCallback(s
             } catch (const std::exception &e) {
                 callback(e);
             } catch (...) {
-                //NOTE not a exception based on std::exception, "repacking" it 
to logical error
+                //NOTE not an exception based on std::exception, "repacking" 
it to logical error
                 std::logic_error logicError{"Unknown exception throw for the 
failure of A celix::Promise"};
                 callback(logicError);
             }
diff --git a/libs/promises/gtest/src/PromisesTestSuite.cc 
b/libs/promises/gtest/src/PromisesTestSuite.cc
index 025af0f..5546a61 100644
--- a/libs/promises/gtest/src/PromisesTestSuite.cc
+++ b/libs/promises/gtest/src/PromisesTestSuite.cc
@@ -172,6 +172,10 @@ TEST_F(PromiseTestSuite, onSuccessHandling) {
     EXPECT_EQ(true, resolveCalled);
 }
 
+static void test_throwing_function() {
+    throw celix::PromiseInvocationException{"PromiseInvocationException test"};
+}
+
 TEST_F(PromiseTestSuite, onFailureHandling) {
     auto deferred =  factory->deferred<long>();
     std::atomic<bool> successCalled = false;
@@ -183,14 +187,14 @@ TEST_F(PromiseTestSuite, onFailureHandling) {
             })
             .onFailure([&](const std::exception &e) {
                 failureCalled = true;
-                ASSERT_TRUE(0 == strcmp("basic_string::at: __n (which is 1) >= 
this->size() (which is 0)",  e.what())) << std::string(e.what());
+                auto what = e.what();
+                ASSERT_STREQ(what, "PromiseInvocationException test");
             })
             .onResolve([&]() {
                 resolveCalled = true;
             });
     try {
-        std::string{}.at(1); // this generates an std::out_of_range
-        //or use std::make_exception_ptr
+        test_throwing_function(); // this generates a 
celix::PromiseInvocationException
     } catch (...) {
         deferred.fail(std::current_exception());
     }

Reply via email to