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:
parent
7d1cd11ba9
commit
1e98cc6c3b
9 changed files with 28 additions and 16 deletions
|
@ -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>
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -513,6 +513,7 @@ else ()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_component_dir(testing
|
add_component_dir(testing
|
||||||
|
expecterror
|
||||||
util
|
util
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
20
components/testing/expecterror.hpp
Normal file
20
components/testing/expecterror.hpp
Normal 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
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue