From b2f50e2c5f8267ebe75c95898a95e3000d72526e Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Wed, 18 Aug 2021 17:09:33 +0200
Subject: [PATCH] ENH: New GTest macro, fixed typo.

---
 test/caosdb_test_utility.h.in | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/test/caosdb_test_utility.h.in b/test/caosdb_test_utility.h.in
index baac638..b53ea62 100644
--- a/test/caosdb_test_utility.h.in
+++ b/test/caosdb_test_utility.h.in
@@ -29,20 +29,38 @@
  * @author Timm Fitschen
  * @date 2021-07-07
  */
-#define EXPECT_THROW_MESSAGE(statement, exeption_type, message)                \
+#define EXPECT_THROW_MESSAGE(statement, exception_type, message)               \
   EXPECT_THROW(                                                                \
-    try { statement; } catch (const exeption_type &e) {                        \
+    try { statement; } catch (const exception_type &e) {                       \
       EXPECT_EQ(std::string(e.what()), message);                               \
       throw;                                                                   \
     },                                                                         \
-    exeption_type)
-#define ASSERT_THROW_MESSAGE(statement, exeption_type, message)                \
+    exception_type)
+#define ASSERT_THROW_MESSAGE(statement, exception_type, message)               \
   ASSERT_THROW(                                                                \
-    try { statement; } catch (const exeption_type &e) {                        \
+    try { statement; } catch (const exception_type &e) {                       \
       ASSERT_EQ(std::string(e.what()), message);                               \
       throw;                                                                   \
     },                                                                         \
-    exeption_type)
+    exception_type)
+#define EXPECT_THROW_STARTS_WITH(statement, exception_type, pattern)           \
+  EXPECT_THROW(                                                                \
+    try { statement; } catch (const exception_type &e) {                       \
+      auto pat_s = std::string(pattern);                                       \
+      EXPECT_EQ(std::string(e.what()).substr(0, pat_s.size()),                 \
+                pat_s);                                                        \
+      throw;                                                                   \
+    },                                                                         \
+    exception_type)
+#define ASSERT_THROW_STARTS_WITH(statement, exception_type, message)           \
+  ASSERT_THROW(                                                                \
+    try { statement; } catch (const exception_type &e) {                       \
+      auto pat_s = std::string(pattern);                                       \
+      ASSERT_EQ(std::string(e.what()).substr(0, pat_s.size()),                 \
+                pat_s);                                                        \
+      throw;                                                                   \
+    },                                                                         \
+    exception_type)
 #define EXPECT_NULL(statement)                                                 \
   if (statement != nullptr) {                                                  \
     FAIL() << "Should be a nullptr";                                           \
-- 
GitLab