]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/ms-gsl/tests/assertion_tests.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / ms-gsl / tests / assertion_tests.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2015 Microsoft Corporation. All rights reserved.
4 //
5 // This code is licensed under the MIT License (MIT).
6 //
7 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13 // THE SOFTWARE.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16
17 #include <gtest/gtest.h>
18 #include <gsl/gsl_assert> // for fail_fast (ptr only), Ensures, Expects
19
20 using namespace gsl;
21
22 namespace
23 {
24 static constexpr char deathstring[] = "Expected Death";
25
26 int f(int i)
27 {
28 Expects(i > 0 && i < 10);
29 return i;
30 }
31
32 int g(int i)
33 {
34 i++;
35 Ensures(i > 0 && i < 10);
36 return i;
37 }
38 } // namespace
39
40 TEST(assertion_tests, expects)
41 {
42 std::set_terminate([] {
43 std::cerr << "Expected Death. expects";
44 std::abort();
45 });
46
47 EXPECT_TRUE(f(2) == 2);
48 EXPECT_DEATH(f(10), deathstring);
49 }
50
51
52 TEST(assertion_tests, ensures)
53 {
54 std::set_terminate([] {
55 std::cerr << "Expected Death. ensures";
56 std::abort();
57 });
58
59 EXPECT_TRUE(g(2) == 3);
60 EXPECT_DEATH(g(9), deathstring);
61 }