summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2024-08-13 01:56:30 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2024-08-13 21:31:46 (GMT)
commitc553be501de68ec7357014b23463ac5accaac30a (patch)
tree8fa0c16f1d05e633b9d8739ae2835624ee1cf7ce
parent0146fca12d8ba053a22d30e7089fc673a5d63089 (diff)
downloadCMake-c553be501de68ec7357014b23463ac5accaac30a.zip
CMake-c553be501de68ec7357014b23463ac5accaac30a.tar.gz
CMake-c553be501de68ec7357014b23463ac5accaac30a.tar.bz2
CMakeLibTests: Use `runTests`
Also, improve it a little.
-rw-r--r--Tests/CMakeLib/testCMFilesystemPath.cxx41
-rw-r--r--Tests/CMakeLib/testCMakePath.cxx20
-rw-r--r--Tests/CMakeLib/testCommon.h28
-rw-r--r--Tests/CMakeLib/testDebuggerAdapter.cxx7
-rw-r--r--Tests/CMakeLib/testDebuggerAdapterPipe.cxx6
-rw-r--r--Tests/CMakeLib/testDebuggerBreakpointManager.cxx9
-rw-r--r--Tests/CMakeLib/testDebuggerThread.cxx5
-rw-r--r--Tests/CMakeLib/testDebuggerVariables.cxx10
-rw-r--r--Tests/CMakeLib/testDebuggerVariablesHelper.cxx21
-rw-r--r--Tests/CMakeLib/testDebuggerVariablesManager.cxx5
-rw-r--r--Tests/CMakeLib/testJSONHelpers.cxx47
-rw-r--r--Tests/CMakeLib/testList.cxx47
-rw-r--r--Tests/CMakeLib/testString.cxx245
13 files changed, 119 insertions, 372 deletions
diff --git a/Tests/CMakeLib/testCMFilesystemPath.cxx b/Tests/CMakeLib/testCMFilesystemPath.cxx
index 52cb43a..1da5925 100644
--- a/Tests/CMakeLib/testCMFilesystemPath.cxx
+++ b/Tests/CMakeLib/testCMFilesystemPath.cxx
@@ -9,6 +9,8 @@
#include <cm/filesystem>
+#include "testCommon.h"
+
namespace {
namespace fs = cm::filesystem;
@@ -971,38 +973,9 @@ bool testNonMemberFunctions()
int testCMFilesystemPath(int /*unused*/, char* /*unused*/[])
{
- int result = 0;
-
- if (!testConstructors()) {
- result = 1;
- }
- if (!testConcatenation()) {
- result = 1;
- }
- if (!testModifiers()) {
- result = 1;
- }
- if (!testObservers()) {
- result = 1;
- }
- if (!testCompare()) {
- result = 1;
- }
- if (!testGeneration()) {
- result = 1;
- }
- if (!testDecomposition()) {
- result = 1;
- }
- if (!testQueries()) {
- result = 1;
- }
- if (!testIterators()) {
- result = 1;
- }
- if (!testNonMemberFunctions()) {
- result = 1;
- }
-
- return result;
+ return runTests({ testConstructors, testConcatenation, testModifiers,
+ testObservers, testCompare, testGeneration,
+ testDecomposition, testQueries, testIterators,
+ testNonMemberFunctions },
+ false);
}
diff --git a/Tests/CMakeLib/testCMakePath.cxx b/Tests/CMakeLib/testCMakePath.cxx
index aa17e50..9b11286 100644
--- a/Tests/CMakeLib/testCMakePath.cxx
+++ b/Tests/CMakeLib/testCMakePath.cxx
@@ -12,6 +12,8 @@
#include "cmCMakePath.h"
+#include "testCommon.h"
+
namespace {
void checkResult(bool success)
@@ -422,20 +424,6 @@ bool testAppend()
int testCMakePath(int /*unused*/, char* /*unused*/[])
{
- int result = 0;
-
- if (!testConstructors()) {
- result = 1;
- }
- if (!testAssign()) {
- result = 1;
- }
- if (!testConcat()) {
- result = 1;
- }
- if (!testAppend()) {
- result = 1;
- }
-
- return result;
+ return runTests({ testConstructors, testAssign, testConcat, testAppend },
+ false);
}
diff --git a/Tests/CMakeLib/testCommon.h b/Tests/CMakeLib/testCommon.h
index bd2d54e..c1d2b3c 100644
--- a/Tests/CMakeLib/testCommon.h
+++ b/Tests/CMakeLib/testCommon.h
@@ -3,28 +3,38 @@
#pragma once
#include <functional>
+#include <initializer_list>
#include <iostream>
-#include <vector>
#define ASSERT_TRUE(x) \
do { \
if (!(x)) { \
- std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \
+ std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << '\n'; \
return false; \
} \
} while (false)
-inline int runTests(std::vector<std::function<bool()>> const& tests)
+#define BOOL_STRING(b) ((b) ? "TRUE" : "FALSE")
+
+namespace {
+
+inline int runTests(std::initializer_list<std::function<bool()>> const& tests,
+ const bool fail_fast = true)
{
+ int result = 0;
for (auto const& test : tests) {
if (!test()) {
- return 1;
+ result = 1;
+ if (fail_fast) {
+ break;
+ }
}
- std::cout << ".";
+ std::cout << '.';
}
-
- std::cout << " Passed" << std::endl;
- return 0;
+ if (!result) {
+ std::cout << " Passed\n";
+ }
+ return result;
}
-#define BOOL_STRING(b) ((b) ? "TRUE" : "FALSE")
+}
diff --git a/Tests/CMakeLib/testDebuggerAdapter.cxx b/Tests/CMakeLib/testDebuggerAdapter.cxx
index e66d990..d585250 100644
--- a/Tests/CMakeLib/testDebuggerAdapter.cxx
+++ b/Tests/CMakeLib/testDebuggerAdapter.cxx
@@ -7,7 +7,6 @@
#include <future>
#include <memory>
#include <string>
-#include <vector>
#include <cm3p/cppdap/future.h>
#include <cm3p/cppdap/io.h>
@@ -194,8 +193,6 @@ bool testThreadsRequestAfterThreadExitedEvent()
int testDebuggerAdapter(int, char*[])
{
- return runTests(std::vector<std::function<bool()>>{
- testBasicProtocol,
- testThreadsRequestAfterThreadExitedEvent,
- });
+ return runTests(
+ { testBasicProtocol, testThreadsRequestAfterThreadExitedEvent });
}
diff --git a/Tests/CMakeLib/testDebuggerAdapterPipe.cxx b/Tests/CMakeLib/testDebuggerAdapterPipe.cxx
index c0f2e9b..5b41be9 100644
--- a/Tests/CMakeLib/testDebuggerAdapterPipe.cxx
+++ b/Tests/CMakeLib/testDebuggerAdapterPipe.cxx
@@ -3,13 +3,11 @@
#include <chrono>
#include <cstdio>
-#include <functional>
#include <future>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <string>
-#include <vector>
#include <cm3p/cppdap/future.h>
#include <cm3p/cppdap/io.h>
@@ -180,7 +178,5 @@ bool testProtocolWithPipes()
int testDebuggerAdapterPipe(int, char*[])
{
- return runTests(std::vector<std::function<bool()>>{
- testProtocolWithPipes,
- });
+ return runTests({ testProtocolWithPipes });
}
diff --git a/Tests/CMakeLib/testDebuggerBreakpointManager.cxx b/Tests/CMakeLib/testDebuggerBreakpointManager.cxx
index f654442..3973826 100644
--- a/Tests/CMakeLib/testDebuggerBreakpointManager.cxx
+++ b/Tests/CMakeLib/testDebuggerBreakpointManager.cxx
@@ -3,7 +3,6 @@
#include <atomic>
#include <chrono>
-#include <functional>
#include <future>
#include <memory>
#include <string>
@@ -177,9 +176,7 @@ static bool testSourceFileLoadedAfterHandleBreakpointRequest()
int testDebuggerBreakpointManager(int, char*[])
{
- return runTests(std::vector<std::function<bool()>>{
- testHandleBreakpointRequestBeforeFileIsLoaded,
- testHandleBreakpointRequestAfterFileIsLoaded,
- testSourceFileLoadedAfterHandleBreakpointRequest,
- });
+ return runTests({ testHandleBreakpointRequestBeforeFileIsLoaded,
+ testHandleBreakpointRequestAfterFileIsLoaded,
+ testSourceFileLoadedAfterHandleBreakpointRequest });
}
diff --git a/Tests/CMakeLib/testDebuggerThread.cxx b/Tests/CMakeLib/testDebuggerThread.cxx
index 0ea95b6..3b7fe6e 100644
--- a/Tests/CMakeLib/testDebuggerThread.cxx
+++ b/Tests/CMakeLib/testDebuggerThread.cxx
@@ -1,4 +1,3 @@
-#include <functional>
#include <memory>
#include <string>
#include <vector>
@@ -27,7 +26,5 @@ static bool testStackFrameFunctionName()
int testDebuggerThread(int, char*[])
{
- return runTests(std::vector<std::function<bool()>>{
- testStackFrameFunctionName,
- });
+ return runTests({ testStackFrameFunctionName });
}
diff --git a/Tests/CMakeLib/testDebuggerVariables.cxx b/Tests/CMakeLib/testDebuggerVariables.cxx
index bb3f14d..1193778 100644
--- a/Tests/CMakeLib/testDebuggerVariables.cxx
+++ b/Tests/CMakeLib/testDebuggerVariables.cxx
@@ -204,11 +204,7 @@ static bool testNoSupportsVariableType()
int testDebuggerVariables(int, char*[])
{
- return runTests(std::vector<std::function<bool()>>{
- testUniqueIds,
- testConstructors,
- testIgnoreEmptyStringEntries,
- testSortTheResult,
- testNoSupportsVariableType,
- });
+ return runTests({ testUniqueIds, testConstructors,
+ testIgnoreEmptyStringEntries, testSortTheResult,
+ testNoSupportsVariableType });
}
diff --git a/Tests/CMakeLib/testDebuggerVariablesHelper.cxx b/Tests/CMakeLib/testDebuggerVariablesHelper.cxx
index d61b73b..5fe1c63 100644
--- a/Tests/CMakeLib/testDebuggerVariablesHelper.cxx
+++ b/Tests/CMakeLib/testDebuggerVariablesHelper.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 <functional>
#include <memory>
#include <set>
#include <string>
@@ -571,18 +570,10 @@ static bool testCreateFromFileSets()
int testDebuggerVariablesHelper(int, char*[])
{
- return runTests(std::vector<std::function<bool()>>{
- testCreateFromPolicyMap,
- testCreateFromPairVector,
- testCreateFromSet,
- testCreateFromStringVector,
- testCreateFromTarget,
- testCreateFromGlobalGenerator,
- testCreateFromMakefile,
- testCreateFromStackFrame,
- testCreateFromTests,
- testCreateFromBTStringVector,
- testCreateFromFileSet,
- testCreateFromFileSets,
- });
+ return runTests({ testCreateFromPolicyMap, testCreateFromPairVector,
+ testCreateFromSet, testCreateFromStringVector,
+ testCreateFromTarget, testCreateFromGlobalGenerator,
+ testCreateFromMakefile, testCreateFromStackFrame,
+ testCreateFromTests, testCreateFromBTStringVector,
+ testCreateFromFileSet, testCreateFromFileSets });
}
diff --git a/Tests/CMakeLib/testDebuggerVariablesManager.cxx b/Tests/CMakeLib/testDebuggerVariablesManager.cxx
index 3013b9f..a1881c0 100644
--- a/Tests/CMakeLib/testDebuggerVariablesManager.cxx
+++ b/Tests/CMakeLib/testDebuggerVariablesManager.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 <functional>
#include <memory>
#include <vector>
@@ -44,7 +43,5 @@ static bool testVariablesRegistration()
int testDebuggerVariablesManager(int, char*[])
{
- return runTests(std::vector<std::function<bool()>>{
- testVariablesRegistration,
- });
+ return runTests({ testVariablesRegistration });
}
diff --git a/Tests/CMakeLib/testJSONHelpers.cxx b/Tests/CMakeLib/testJSONHelpers.cxx
index 68237ac..05404fa 100644
--- a/Tests/CMakeLib/testJSONHelpers.cxx
+++ b/Tests/CMakeLib/testJSONHelpers.cxx
@@ -465,47 +465,8 @@ bool testRequired()
int testJSONHelpers(int /*unused*/, char* /*unused*/[])
{
- if (!testInt()) {
- return 1;
- }
- if (!testUInt()) {
- return 1;
- }
- if (!testBool()) {
- return 1;
- }
- if (!testString()) {
- return 1;
- }
- if (!testObject()) {
- return 1;
- }
- if (!testObjectInherited()) {
- return 1;
- }
- if (!testObjectNoExtra()) {
- return 1;
- }
- if (!testObjectOptional()) {
- return 1;
- }
- if (!testVector()) {
- return 1;
- }
- if (!testVectorFilter()) {
- return 1;
- }
- if (!testMap()) {
- return 1;
- }
- if (!testMapFilter()) {
- return 1;
- }
- if (!testOptional()) {
- return 1;
- }
- if (!testRequired()) {
- return 1;
- }
- return 0;
+ return runTests({ testInt, testUInt, testBool, testString, testObject,
+ testObjectInherited, testObjectNoExtra, testObjectOptional,
+ testVector, testVectorFilter, testMap, testMapFilter,
+ testOptional, testRequired });
}
diff --git a/Tests/CMakeLib/testList.cxx b/Tests/CMakeLib/testList.cxx
index 8822806..4bff217 100644
--- a/Tests/CMakeLib/testList.cxx
+++ b/Tests/CMakeLib/testList.cxx
@@ -11,6 +11,8 @@
#include "cmList.h"
+#include "testCommon.h"
+
namespace {
void checkResult(bool success)
@@ -951,44 +953,9 @@ bool testStaticModifiers()
int testList(int /*unused*/, char* /*unused*/[])
{
- int result = 0;
-
- if (!testConstructors()) {
- result = 1;
- }
- if (!testAssign()) {
- result = 1;
- }
- if (!testConversions()) {
- result = 1;
- }
- if (!testAccess()) {
- result = 1;
- }
- if (!testModifiers()) {
- result = 1;
- }
- if (!testRemoveItems()) {
- result = 1;
- }
- if (!testRemoveDuplicates()) {
- result = 1;
- }
- if (!testFilter()) {
- result = 1;
- }
- if (!testReverse()) {
- result = 1;
- }
- if (!testSort()) {
- result = 1;
- }
- if (!testTransform()) {
- result = 1;
- }
- if (!testStaticModifiers()) {
- result = 1;
- }
-
- return result;
+ return runTests({ testConstructors, testAssign, testConversions, testAccess,
+ testModifiers, testRemoveItems, testRemoveDuplicates,
+ testFilter, testReverse, testSort, testTransform,
+ testStaticModifiers },
+ false);
}
diff --git a/Tests/CMakeLib/testString.cxx b/Tests/CMakeLib/testString.cxx
index d49f65f..a6489ab 100644
--- a/Tests/CMakeLib/testString.cxx
+++ b/Tests/CMakeLib/testString.cxx
@@ -1157,188 +1157,65 @@ static bool testStability()
int testString(int /*unused*/, char* /*unused*/[])
{
- if (!testConstructDefault()) {
- return 1;
- }
- if (!testConstructFromNullPtr()) {
- return 1;
- }
- if (!testConstructFromCStrNull()) {
- return 1;
- }
- if (!testConstructFromCharArray()) {
- return 1;
- }
- if (!testConstructFromCStr()) {
- return 1;
- }
- if (!testConstructFromStdString()) {
- return 1;
- }
- if (!testConstructFromView()) {
- return 1;
- }
- if (!testConstructFromChar()) {
- return 1;
- }
- if (!testConstructFromInitList()) {
- return 1;
- }
- if (!testConstructFromBuffer()) {
- return 1;
- }
- if (!testConstructFromInputIterator()) {
- return 1;
- }
- if (!testConstructFromN()) {
- return 1;
- }
- if (!testConstructFromStaticStringView()) {
- return 1;
- }
- if (!testConstructCopy()) {
- return 1;
- }
- if (!testConstructMove()) {
- return 1;
- }
- if (!testAssignCopy()) {
- return 1;
- }
- if (!testAssignMove()) {
- return 1;
- }
- if (!testAssignFromChar()) {
- return 1;
- }
- if (!testAssignFromView()) {
- return 1;
- }
- if (!testAssignFromStdString()) {
- return 1;
- }
- if (!testAssignFromCStr()) {
- return 1;
- }
- if (!testAssignFromCharArray()) {
- return 1;
- }
- if (!testAssignFromCStrNull()) {
- return 1;
- }
- if (!testAssignFromNullPtr()) {
- return 1;
- }
- if (!testAssignFromInitList()) {
- return 1;
- }
- if (!testAssignFromStaticStringView()) {
- return 1;
- }
- if (!testOperatorBool()) {
- return 1;
- }
- if (!testOperatorIndex()) {
- return 1;
- }
- if (!testOperatorPlusEqual()) {
- return 1;
- }
- if (!testOperatorCompare()) {
- return 1;
- }
- if (!testOperatorStream()) {
- return 1;
- }
- if (!testOperatorStdStringPlusEqual()) {
- return 1;
- }
- if (!testMethod_borrow()) {
- return 1;
- }
- if (!testMethod_view()) {
- return 1;
- }
- if (!testMethod_empty()) {
- return 1;
- }
- if (!testMethod_length()) {
- return 1;
- }
- if (!testMethod_at()) {
- return 1;
- }
- if (!testMethod_front_back()) {
- return 1;
- }
- if (!testMethod_clear()) {
- return 1;
- }
- if (!testMethod_insert()) {
- return 1;
- }
- if (!testMethod_erase()) {
- return 1;
- }
- if (!testMethod_push_back()) {
- return 1;
- }
- if (!testMethod_pop_back()) {
- return 1;
- }
- if (!testMethod_replace()) {
- return 1;
- }
- if (!testMethod_copy()) {
- return 1;
- }
- if (!testMethod_resize()) {
- return 1;
- }
- if (!testMethod_swap()) {
- return 1;
- }
- if (!testMethodIterators()) {
- return 1;
- }
- if (!testMethod_substr_AtEndBorrowed()) {
- return 1;
- }
- if (!testMethod_substr_AtEndOwned()) {
- return 1;
- }
- if (!testMethod_substr_AtStartBorrowed()) {
- return 1;
- }
- if (!testMethod_substr_AtStartOwned()) {
- return 1;
- }
- if (!testMethod_compare()) {
- return 1;
- }
- if (!testMethod_find()) {
- return 1;
- }
- if (!testMethod_rfind()) {
- return 1;
- }
- if (!testMethod_find_first_of()) {
- return 1;
- }
- if (!testMethod_find_first_not_of()) {
- return 1;
- }
- if (!testMethod_find_last_of()) {
- return 1;
- }
- if (!testMethod_find_last_not_of()) {
- return 1;
- }
- if (!testAddition()) {
- return 1;
- }
- if (!testStability()) {
- return 1;
- }
- return 0;
+ return runTests({ testConstructDefault,
+ testConstructFromNullPtr,
+ testConstructFromCStrNull,
+ testConstructFromCharArray,
+ testConstructFromCStr,
+ testConstructFromStdString,
+ testConstructFromView,
+ testConstructFromChar,
+ testConstructFromInitList,
+ testConstructFromBuffer,
+ testConstructFromInputIterator,
+ testConstructFromN,
+ testConstructFromStaticStringView,
+ testConstructCopy,
+ testConstructMove,
+ testAssignCopy,
+ testAssignMove,
+ testAssignFromChar,
+ testAssignFromView,
+ testAssignFromStdString,
+ testAssignFromCStr,
+ testAssignFromCharArray,
+ testAssignFromCStrNull,
+ testAssignFromNullPtr,
+ testAssignFromInitList,
+ testAssignFromStaticStringView,
+ testOperatorBool,
+ testOperatorIndex,
+ testOperatorPlusEqual,
+ testOperatorCompare,
+ testOperatorStream,
+ testOperatorStdStringPlusEqual,
+ testMethod_borrow,
+ testMethod_view,
+ testMethod_empty,
+ testMethod_length,
+ testMethod_at,
+ testMethod_front_back,
+ testMethod_clear,
+ testMethod_insert,
+ testMethod_erase,
+ testMethod_push_back,
+ testMethod_pop_back,
+ testMethod_replace,
+ testMethod_copy,
+ testMethod_resize,
+ testMethod_swap,
+ testMethodIterators,
+ testMethod_substr_AtEndBorrowed,
+ testMethod_substr_AtEndOwned,
+ testMethod_substr_AtStartBorrowed,
+ testMethod_substr_AtStartOwned,
+ testMethod_compare,
+ testMethod_find,
+ testMethod_rfind,
+ testMethod_find_first_of,
+ testMethod_find_first_not_of,
+ testMethod_find_last_of,
+ testMethod_find_last_not_of,
+ testAddition,
+ testStability });
}