Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CMakeLib/testCommon.h
3148 views
1
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
file LICENSE.rst or https://cmake.org/licensing for details. */
3
#pragma once
4
5
#include <functional> // IWYU pragma: export
6
#include <initializer_list> // IWYU pragma: export
7
#include <iostream> // IWYU pragma: export
8
9
#define ASSERT_TRUE(x) \
10
do { \
11
if (!(x)) { \
12
std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << '\n'; \
13
return false; \
14
} \
15
} while (false)
16
17
#define ASSERT_EQUAL(actual, expected) \
18
do { \
19
if (!((actual) == (expected))) { \
20
std::cout << "ASSERT_EQUAL(" #actual ", " #expected ") failed on line " \
21
<< __LINE__ << '\n'; \
22
std::cout << " Actual: '" << (actual) << "'\n"; \
23
std::cout << "Expected: '" << (expected) << "'\n"; \
24
return false; \
25
} \
26
} while (false)
27
28
#define BOOL_STRING(b) ((b) ? "TRUE" : "FALSE")
29
30
namespace {
31
32
inline int runTests(std::initializer_list<std::function<bool()>> tests,
33
bool const fail_fast = true)
34
{
35
int result = 0;
36
for (auto const& test : tests) {
37
if (!test()) {
38
result = 1;
39
if (fail_fast) {
40
break;
41
}
42
}
43
}
44
if (result == 0) {
45
std::cout << "Passed\n";
46
}
47
return result;
48
}
49
50
}
51
52