summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2024-08-19 01:23:42 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2024-08-20 22:24:16 (GMT)
commitcc20644c712b5a24ea7c7db83fde3dfde61250d3 (patch)
tree47217d77149a7b4d67e768e196bfd3348b99b821
parent8fae37d99fb3a27c40cd2f5271b92e3f99c3dcd6 (diff)
downloadCMake-cc20644c712b5a24ea7c7db83fde3dfde61250d3.zip
CMake-cc20644c712b5a24ea7c7db83fde3dfde61250d3.tar.gz
CMake-cc20644c712b5a24ea7c7db83fde3dfde61250d3.tar.bz2
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`!
-rw-r--r--Tests/CMakeLib/CMakeLists.txt1
-rw-r--r--Tests/CMakeLib/testArgumentParser.cxx3
-rw-r--r--Tests/CMakeLib/testAssert.cxx56
-rw-r--r--Tests/CMakeLib/testCMFilesystemPath.cxx1
-rw-r--r--Tests/CMakeLib/testCMakePath.cxx1
-rw-r--r--Tests/CMakeLib/testCommon.h17
-rw-r--r--Tests/CMakeLib/testDebuggerAdapter.cxx1
-rw-r--r--Tests/CMakeLib/testDebuggerAdapterPipe.cxx1
-rw-r--r--Tests/CMakeLib/testDebuggerVariables.cxx1
-rw-r--r--Tests/CMakeLib/testJSONHelpers.cxx1
-rw-r--r--Tests/CMakeLib/testList.cxx1
-rw-r--r--Tests/CMakeLib/testOptional.cxx1
-rw-r--r--Tests/CMakeLib/testString.cxx1
13 files changed, 71 insertions, 15 deletions
diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt
index 008a7d9..5b189e7 100644
--- a/Tests/CMakeLib/CMakeLists.txt
+++ b/Tests/CMakeLib/CMakeLists.txt
@@ -9,6 +9,7 @@ include_directories(
)
set(CMakeLib_TESTS
+ testAssert.cxx
testArgumentParser.cxx
testCTestBinPacker.cxx
testCTestResourceAllocator.cxx
diff --git a/Tests/CMakeLib/testArgumentParser.cxx b/Tests/CMakeLib/testArgumentParser.cxx
index 880f3ee..d4e2bd2 100644
--- a/Tests/CMakeLib/testArgumentParser.cxx
+++ b/Tests/CMakeLib/testArgumentParser.cxx
@@ -1,9 +1,6 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
-#include <functional>
-#include <initializer_list>
-#include <iostream>
#include <map>
#include <string>
#include <utility>
diff --git a/Tests/CMakeLib/testAssert.cxx b/Tests/CMakeLib/testAssert.cxx
new file mode 100644
index 0000000..3d2e839
--- /dev/null
+++ b/Tests/CMakeLib/testAssert.cxx
@@ -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 });
+}
diff --git a/Tests/CMakeLib/testCMFilesystemPath.cxx b/Tests/CMakeLib/testCMFilesystemPath.cxx
index 1da5925..66d2c18 100644
--- a/Tests/CMakeLib/testCMFilesystemPath.cxx
+++ b/Tests/CMakeLib/testCMFilesystemPath.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include <algorithm>
-#include <iostream>
#include <sstream>
#include <string>
#include <vector>
diff --git a/Tests/CMakeLib/testCMakePath.cxx b/Tests/CMakeLib/testCMakePath.cxx
index 9b11286..d2f6661 100644
--- a/Tests/CMakeLib/testCMakePath.cxx
+++ b/Tests/CMakeLib/testCMakePath.cxx
@@ -3,7 +3,6 @@
#include "cmConfigure.h" // IWYU pragma: keep
-#include <iostream>
#include <string>
#include <utility>
diff --git a/Tests/CMakeLib/testCommon.h b/Tests/CMakeLib/testCommon.h
index c1d2b3c..de4a689 100644
--- a/Tests/CMakeLib/testCommon.h
+++ b/Tests/CMakeLib/testCommon.h
@@ -2,9 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
-#include <functional>
-#include <initializer_list>
-#include <iostream>
+#include <functional> // IWYU pragma: export
+#include <initializer_list> // IWYU pragma: export
+#include <iostream> // IWYU pragma: export
#define ASSERT_TRUE(x) \
do { \
@@ -14,6 +14,17 @@
} \
} 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")
namespace {
diff --git a/Tests/CMakeLib/testDebuggerAdapter.cxx b/Tests/CMakeLib/testDebuggerAdapter.cxx
index d585250..a055cb7 100644
--- a/Tests/CMakeLib/testDebuggerAdapter.cxx
+++ b/Tests/CMakeLib/testDebuggerAdapter.cxx
@@ -3,7 +3,6 @@
#include <chrono>
#include <cstdio>
-#include <functional>
#include <future>
#include <memory>
#include <string>
diff --git a/Tests/CMakeLib/testDebuggerAdapterPipe.cxx b/Tests/CMakeLib/testDebuggerAdapterPipe.cxx
index 5b41be9..3647088 100644
--- a/Tests/CMakeLib/testDebuggerAdapterPipe.cxx
+++ b/Tests/CMakeLib/testDebuggerAdapterPipe.cxx
@@ -4,7 +4,6 @@
#include <chrono>
#include <cstdio>
#include <future>
-#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
diff --git a/Tests/CMakeLib/testDebuggerVariables.cxx b/Tests/CMakeLib/testDebuggerVariables.cxx
index 1193778..ca8bf39 100644
--- a/Tests/CMakeLib/testDebuggerVariables.cxx
+++ b/Tests/CMakeLib/testDebuggerVariables.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include <cstdint>
-#include <functional>
#include <memory>
#include <string>
#include <unordered_set>
diff --git a/Tests/CMakeLib/testJSONHelpers.cxx b/Tests/CMakeLib/testJSONHelpers.cxx
index 05404fa..8dbfc5e 100644
--- a/Tests/CMakeLib/testJSONHelpers.cxx
+++ b/Tests/CMakeLib/testJSONHelpers.cxx
@@ -1,4 +1,3 @@
-#include <functional>
#include <map>
#include <string>
#include <vector>
diff --git a/Tests/CMakeLib/testList.cxx b/Tests/CMakeLib/testList.cxx
index 4bff217..2864c91 100644
--- a/Tests/CMakeLib/testList.cxx
+++ b/Tests/CMakeLib/testList.cxx
@@ -1,7 +1,6 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
-#include <iostream>
#include <stdexcept>
#include <string>
#include <utility>
diff --git a/Tests/CMakeLib/testOptional.cxx b/Tests/CMakeLib/testOptional.cxx
index eba2dd5..0276ed3 100644
--- a/Tests/CMakeLib/testOptional.cxx
+++ b/Tests/CMakeLib/testOptional.cxx
@@ -1,4 +1,3 @@
-#include <iostream>
#include <vector>
#include <cm/optional>
diff --git a/Tests/CMakeLib/testString.cxx b/Tests/CMakeLib/testString.cxx
index a6489ab..b6723f5 100644
--- a/Tests/CMakeLib/testString.cxx
+++ b/Tests/CMakeLib/testString.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include <cstring>
-#include <iostream>
#include <iterator>
#include <sstream>
#include <stdexcept>