Move EXPECT_ERROR macro to a separate header

To include it only where it's required.
This commit is contained in:
elsid
2024-06-10 23:12:15 +02:00
parent 7d1cd11ba9
commit 1e98cc6c3b
9 changed files with 28 additions and 16 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
#include <components/esm/refid.hpp>
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
#include <components/testing/util.hpp>
#include <components/testing/expecterror.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+1 -2
View File
@@ -3,12 +3,11 @@
#include <components/lua/asyncpackage.hpp>
#include <components/lua/luastate.hpp>
#include <components/testing/util.hpp>
#include <components/testing/expecterror.hpp>
namespace
{
using namespace testing;
using namespace TestingOpenMW;
struct LuaCoroutineCallbackTest : Test
{
@@ -9,6 +9,7 @@
#include <components/esm3/readerscache.hpp>
#include <components/lua/configuration.hpp>
#include <components/lua/serialization.hpp>
#include <components/testing/expecterror.hpp>
#include <components/testing/util.hpp>
namespace
+1
View File
@@ -2,6 +2,7 @@
#include <gtest/gtest.h>
#include <components/lua/luastate.hpp>
#include <components/testing/expecterror.hpp>
#include <components/testing/util.hpp>
namespace
@@ -13,7 +13,7 @@
#include <components/misc/color.hpp>
#include <components/misc/endianness.hpp>
#include <components/testing/util.hpp>
#include <components/testing/expecterror.hpp>
namespace
{
@@ -3,7 +3,7 @@
#include <components/lua/luastate.hpp>
#include <components/lua/utilpackage.hpp>
#include <components/testing/util.hpp>
#include <components/testing/expecterror.hpp>
namespace
{
+1
View File
@@ -513,6 +513,7 @@ else ()
endif()
add_component_dir(testing
expecterror
util
)
+20
View File
@@ -0,0 +1,20 @@
#ifndef OPENMW_COMPONENTS_TESTING_EXPECTERROR_H
#define OPENMW_COMPONENTS_TESTING_EXPECTERROR_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <exception>
#define EXPECT_ERROR(X, ERR_SUBSTR) \
try \
{ \
X; \
FAIL() << "Expected error"; \
} \
catch (const std::exception& e) \
{ \
EXPECT_THAT(e.what(), ::testing::HasSubstr(ERR_SUBSTR)); \
}
#endif
+1 -11
View File
@@ -3,6 +3,7 @@
#include <filesystem>
#include <initializer_list>
#include <memory>
#include <sstream>
#include <components/misc/strings/conversion.hpp>
@@ -80,15 +81,4 @@ namespace TestingOpenMW
}
}
#define EXPECT_ERROR(X, ERR_SUBSTR) \
try \
{ \
X; \
FAIL() << "Expected error"; \
} \
catch (const std::exception& e) \
{ \
EXPECT_THAT(e.what(), ::testing::HasSubstr(ERR_SUBSTR)); \
}
#endif