From aff10f34231d61e22376ac4e6e966a4c1b753cd0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 26 Jul 2021 15:12:43 +0200
Subject: [PATCH] Set AssertError to inherit from std::runtime_error

The main interest is that one can now check more precisely the type of
raised errors in unit tests
---
 src/utils/PugsAssert.hpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/utils/PugsAssert.hpp b/src/utils/PugsAssert.hpp
index 7ac521a51..7793a9fc6 100644
--- a/src/utils/PugsAssert.hpp
+++ b/src/utils/PugsAssert.hpp
@@ -9,7 +9,7 @@
 #include <string>
 #include <tuple>
 
-class AssertError
+class AssertError : public std::runtime_error
 {
  private:
   const std::string m_file;
@@ -41,7 +41,8 @@ class AssertError
               const std::string& function,
               const std::tuple<Args...>& tuple_args,
               const std::string_view args_string)
-    : m_file{filename},
+    : std::runtime_error(""),
+      m_file{filename},
       m_line{line},
       m_function{function},
       m_test{[&] {
@@ -64,7 +65,11 @@ class AssertError
         }
       }()}
   {
-    ;
+    if (m_message.empty()) {
+      std::runtime_error::operator=(std::runtime_error(m_test.c_str()));
+    } else {
+      std::runtime_error::operator=(std::runtime_error(m_message.c_str()));
+    }
   }
 };
 
-- 
GitLab