forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_xexception.cpp
58 lines (50 loc) · 1.94 KB
/
test_xexception.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* Copyright (c) QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XTENSOR_ENABLE_ASSERT
#define XTENSOR_ENABLE_ASSERT
#endif
#include <string>
#include "test_common_macros.hpp"
#include "xtensor/xexception.hpp"
#include "test_common_macros.hpp"
namespace xt
{
TEST(xexception, macros)
{
XT_EXPECT_THROW(XTENSOR_ASSERT_MSG(false, "Intentional error"), std::runtime_error);
XT_EXPECT_THROW(XTENSOR_PRECONDITION(false, "Intentional error"), std::runtime_error);
}
#if !defined(XTENSOR_DISABLE_EXCEPTIONS)
TEST(xexception, assert)
{
try
{
XTENSOR_ASSERT_MSG(false, "Intentional error");
CHECK_MESSAGE(false, "no exception thrown");
}
catch (std::runtime_error& e)
{
std::string expected("Assertion error!\nIntentional error");
std::string message(e.what());
EXPECT_TRUE(0 == expected.compare(message.substr(0, expected.size())));
}
try
{
XTENSOR_PRECONDITION(false, "Intentional error");
CHECK_MESSAGE(false, "no exception thrown");
}
catch (std::runtime_error& e)
{
std::string expected("Precondition violation!\nIntentional error");
std::string message(e.what());
EXPECT_TRUE(0 == expected.compare(message.substr(0, expected.size())));
}
}
#endif
} // namespace xt