forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_xexception.cpp
45 lines (41 loc) · 1.53 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
/***************************************************************************
* Copyright (c) 2017, Ullrich Koethe *
* *
* 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 "gtest/gtest.h"
#include "xtensor/xexception.hpp"
namespace xt
{
TEST(xexception, assert)
{
try
{
XTENSOR_ASSERT_MSG(false, "Intentional error");
FAIL() << "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");
FAIL() << "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())));
}
}
} // namespace xt