mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-01 03:29:18 -05:00
testCommon.h: Introduce ASSERT_EQUAL(actual, expected) macro
Performs `==` on given arguments and print an error if they are not equal also printing their values. Both arguments must be printable to `std::ostream`!
This commit is contained in:
@@ -9,6 +9,7 @@ include_directories(
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(CMakeLib_TESTS
|
set(CMakeLib_TESTS
|
||||||
|
testAssert.cxx
|
||||||
testArgumentParser.cxx
|
testArgumentParser.cxx
|
||||||
testCTestBinPacker.cxx
|
testCTestBinPacker.cxx
|
||||||
testCTestResourceAllocator.cxx
|
testCTestResourceAllocator.cxx
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <initializer_list>
|
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "testCommon.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class WrapFailureInBlockFixture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WrapFailureInBlockFixture()
|
||||||
|
{
|
||||||
|
std::cout << "---[ BEGIN Expected Failure Output]---\n";
|
||||||
|
}
|
||||||
|
~WrapFailureInBlockFixture()
|
||||||
|
{
|
||||||
|
std::cout << "---[ END Expected Failure Output]---\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool testASSERT_EQUAL()
|
||||||
|
{
|
||||||
|
ASSERT_EQUAL(7 == 7, 42 == 42);
|
||||||
|
{
|
||||||
|
std::string actual = "Hello Africa!";
|
||||||
|
ASSERT_EQUAL(actual, "Hello Africa!");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool testASSERT_EQUALFail()
|
||||||
|
{
|
||||||
|
WrapFailureInBlockFixture fx;
|
||||||
|
static_cast<void>(fx);
|
||||||
|
|
||||||
|
auto fail_int = [](const int unexpected) -> bool {
|
||||||
|
ASSERT_EQUAL(unexpected, 42);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto fail_string = [](const std::string& unexpected) -> bool {
|
||||||
|
ASSERT_EQUAL(unexpected, "Hello Africa!");
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
return !(fail_int(7) || fail_string("Habari Afrika!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
int testAssert(int /*unused*/, char* /*unused*/[])
|
||||||
|
{
|
||||||
|
return runTests({ testASSERT_EQUAL, testASSERT_EQUALFail });
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional> // IWYU pragma: export
|
||||||
#include <initializer_list>
|
#include <initializer_list> // IWYU pragma: export
|
||||||
#include <iostream>
|
#include <iostream> // IWYU pragma: export
|
||||||
|
|
||||||
#define ASSERT_TRUE(x) \
|
#define ASSERT_TRUE(x) \
|
||||||
do { \
|
do { \
|
||||||
@@ -14,6 +14,17 @@
|
|||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
#define ASSERT_EQUAL(actual, expected) \
|
||||||
|
do { \
|
||||||
|
if (!((actual) == (expected))) { \
|
||||||
|
std::cout << "ASSERT_EQUAL(" #actual ", " #expected ") failed on line " \
|
||||||
|
<< __LINE__ << '\n'; \
|
||||||
|
std::cout << " Actual: '" << (actual) << "'\n"; \
|
||||||
|
std::cout << "Expected: '" << (expected) << "'\n"; \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
#define BOOL_STRING(b) ((b) ? "TRUE" : "FALSE")
|
#define BOOL_STRING(b) ((b) ? "TRUE" : "FALSE")
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <functional>
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <functional>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <cm/optional>
|
#include <cm/optional>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|||||||
Reference in New Issue
Block a user