c865add821
googletest (gtest) is more feature rich than the current implementation which only provides expect() which is basically an assertion. It is also quite intuitive to use, this can be seen in the rewrite of the command_line test where EXPECT_THROW replaces a whole try-catch block. I have also moved the source files the test depend on to be linked in CMakeLists.txt instead of including them directly because include .cpp files is bad. The two x11 tests were removed because they were written two years ago and a lot of the things they depend on, don't actually exist anymore in polybar (I think we switched to xpp after those tests were written) Tests are now compiled with the gcov lib which can be used to provide test coverage in a second step
40 lines
941 B
C++
40 lines
941 B
C++
//
|
|
// Copyright (c) 2016 Krzysztof Jusiak (krzysztof at jusiak dot net)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
#pragma once
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <gtest/gtest.h>
|
|
|
|
#define expect(...) \
|
|
(void)((__VA_ARGS__) || (expect_fail__(#__VA_ARGS__, __FILE__, __LINE__), 0))
|
|
#define static_expect(...) static_assert((__VA_ARGS__), "fail")
|
|
|
|
void expect_fail__(const char* msg, const char* file, int line) {
|
|
std::printf("%s:%d:%s\n", file, line, msg);
|
|
std::exit(-1);
|
|
}
|
|
|
|
template <char...>
|
|
struct test {
|
|
template <class Test>
|
|
bool operator=(const Test& test) {
|
|
test();
|
|
return true;
|
|
}
|
|
};
|
|
|
|
#if defined(__clang__)
|
|
#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
|
|
#endif
|
|
|
|
template <class T, T... Chars>
|
|
constexpr auto operator""_test() {
|
|
return test<Chars...>{};
|
|
}
|