1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 13:15:34 +00:00

Move EXPECT_ERROR macro to a separate header

To include it only where it's required.
This commit is contained in:
elsid 2024-06-09 14:55:08 +02:00
parent 7d1cd11ba9
commit 1e98cc6c3b
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
9 changed files with 28 additions and 16 deletions

View file

@ -1,7 +1,7 @@
#include <components/esm/refid.hpp> #include <components/esm/refid.hpp>
#include <components/esm3/esmreader.hpp> #include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp> #include <components/esm3/esmwriter.hpp>
#include <components/testing/util.hpp> #include <components/testing/expecterror.hpp>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>

View file

@ -3,12 +3,11 @@
#include <components/lua/asyncpackage.hpp> #include <components/lua/asyncpackage.hpp>
#include <components/lua/luastate.hpp> #include <components/lua/luastate.hpp>
#include <components/testing/util.hpp> #include <components/testing/expecterror.hpp>
namespace namespace
{ {
using namespace testing; using namespace testing;
using namespace TestingOpenMW;
struct LuaCoroutineCallbackTest : Test struct LuaCoroutineCallbackTest : Test
{ {

View file

@ -9,6 +9,7 @@
#include <components/esm3/readerscache.hpp> #include <components/esm3/readerscache.hpp>
#include <components/lua/configuration.hpp> #include <components/lua/configuration.hpp>
#include <components/lua/serialization.hpp> #include <components/lua/serialization.hpp>
#include <components/testing/expecterror.hpp>
#include <components/testing/util.hpp> #include <components/testing/util.hpp>
namespace namespace

View file

@ -2,6 +2,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <components/lua/luastate.hpp> #include <components/lua/luastate.hpp>
#include <components/testing/expecterror.hpp>
#include <components/testing/util.hpp> #include <components/testing/util.hpp>
namespace namespace

View file

@ -13,7 +13,7 @@
#include <components/misc/color.hpp> #include <components/misc/color.hpp>
#include <components/misc/endianness.hpp> #include <components/misc/endianness.hpp>
#include <components/testing/util.hpp> #include <components/testing/expecterror.hpp>
namespace namespace
{ {

View file

@ -3,7 +3,7 @@
#include <components/lua/luastate.hpp> #include <components/lua/luastate.hpp>
#include <components/lua/utilpackage.hpp> #include <components/lua/utilpackage.hpp>
#include <components/testing/util.hpp> #include <components/testing/expecterror.hpp>
namespace namespace
{ {

View file

@ -513,6 +513,7 @@ else ()
endif() endif()
add_component_dir(testing add_component_dir(testing
expecterror
util util
) )

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

View file

@ -3,6 +3,7 @@
#include <filesystem> #include <filesystem>
#include <initializer_list> #include <initializer_list>
#include <memory>
#include <sstream> #include <sstream>
#include <components/misc/strings/conversion.hpp> #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 #endif