aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/gtest/gtest.h
blob: 115d23dd92578d4088d0df0467ce3841800aea64 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <gtest/gtest.h>
#include <vespa/vespalib/stllike/string.h>
#include <iostream>

namespace vespalib {
// Tell google test how to print vespalib::string values:
static inline void PrintTo(const vespalib::string & value, std::ostream * os) {
    *os << value;
}
}

/**
 * Macro for creating a main function that runs all gtests.
 */
#define GTEST_MAIN_RUN_ALL_TESTS()          \
int                                         \
main(int argc, char* argv[])                \
{                                           \
    ::testing::InitGoogleTest(&argc, argv); \
    return RUN_ALL_TESTS();                 \
}

#define VESPA_EXPECT_EXCEPTION(TRY_BLOCK, EXCEPTION_TYPE, MESSAGE) \
    try {                                                                 \
        TRY_BLOCK;                                                        \
        FAIL() << "exception '" << MESSAGE << "' not thrown at all!";     \
    } catch(EXCEPTION_TYPE& e) {                                          \
        EXPECT_TRUE(contains(stringref(e.what()), stringref(MESSAGE))) << \
            " e.what(): " << e.what() << "\n";                            \
    } catch(...) {                                                        \
        FAIL() << "wrong exception type thrown";                          \
        throw;                                                            \
    }