Merge topic 'imprve-CMakeLibTests'

c553be501d CMakeLibTests: Use `runTests`
0146fca12d CMakeLibTests: include `testCommon.h` for `ASSERT_TRUE`
3d9c018f31 CMakeLibTests: Generate `testConfig.h` with source/build paths defined

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9724
This commit is contained in:
Brad King
2024-08-19 14:17:04 +00:00
committed by Kitware Robot
22 changed files with 142 additions and 430 deletions
+3 -2
View File
@@ -1,3 +1,6 @@
# Render the header file with source path macro
configure_file(testConfig.h.in testConfig.h @ONLY)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMake_BINARY_DIR}/Source
@@ -65,10 +68,8 @@ if(WIN32)
list(APPEND CMakeLib_TESTS
testVisualStudioSlnParser.cxx
)
configure_file(testVisualStudioSlnParser.h.in testVisualStudioSlnParser.h @ONLY)
endif()
configure_file(testXMLParser.h.in testXMLParser.h @ONLY)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/testUVProcessChainInput.txt" "HELLO WORLD!")
create_test_sourcelist(CMakeLib_TEST_SRCS CMakeLibTests.cxx ${CMakeLib_TESTS})
+2 -8
View File
@@ -16,6 +16,8 @@
#include "cmArgumentParser.h"
#include "cmArgumentParserTypes.h"
#include "testCommon.h"
namespace {
struct Result : public ArgumentParser::ParseResult
@@ -182,14 +184,6 @@ bool verifyResult(Result const& result,
static std::vector<std::string> const unparsed = { "pos2", "bar", "ign1",
"ign2", "ign4" };
#define ASSERT_TRUE(x) \
do { \
if (!(x)) { \
std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \
return false; \
} \
} while (false)
ASSERT_TRUE(!result);
ASSERT_TRUE(result.Option1);
+7 -34
View File
@@ -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);
}
+4 -16
View File
@@ -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);
}
+19 -9
View File
@@ -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")
}
+7
View File
@@ -0,0 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
#define SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
#define BUILD_DIR "@CMAKE_CURRENT_BINARY_DIR@"
+2 -5
View File
@@ -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 });
}
+1 -5
View File
@@ -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 });
}
@@ -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 });
}
+1 -4
View File
@@ -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 });
}
+3 -7
View File
@@ -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 });
}
+6 -15
View File
@@ -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 });
}
@@ -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 });
}
+5 -51
View File
@@ -1,5 +1,4 @@
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
@@ -12,13 +11,7 @@
#include "cmJSONHelpers.h"
#include "cmJSONState.h"
#define ASSERT_TRUE(x) \
do { \
if (!(x)) { \
std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \
return false; \
} \
} while (false)
#include "testCommon.h"
namespace {
struct ObjectStruct
@@ -472,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 });
}
+7 -40
View File
@@ -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);
}
+2 -8
View File
@@ -4,6 +4,8 @@
#include <cm/optional>
#include <cm/utility>
#include "testCommon.h"
class EventLogger;
class Event
@@ -93,14 +95,6 @@ public:
NoMoveAssignEventLogger& operator=(NoMoveAssignEventLogger&&) = delete;
};
#define ASSERT_TRUE(x) \
do { \
if (!(x)) { \
std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \
return false; \
} \
} while (false)
// Certain builds of GCC generate false -Wmaybe-uninitialized warnings when
// doing a release build with the system version of std::optional. These
// warnings do not manifest when using our own cm::optional implementation.
+1 -8
View File
@@ -1,19 +1,12 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include <iostream>
#include <string>
#include <vector>
#include "cmRange.h"
#define ASSERT_TRUE(x) \
do { \
if (!(x)) { \
std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \
return -1; \
} \
} while (false)
#include "testCommon.h"
int testRange(int /*unused*/, char* /*unused*/[])
{
+62 -191
View File
@@ -14,13 +14,7 @@
#include "cmString.hxx"
#define ASSERT_TRUE(x) \
do { \
if (!(x)) { \
std::cout << "ASSERT_TRUE(" #x ") failed on line " << __LINE__ << "\n"; \
return false; \
} \
} while (false)
#include "testCommon.h"
static bool testConstructDefault()
{
@@ -1163,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 });
}
+4 -2
View File
@@ -1,10 +1,12 @@
#include "testVisualStudioSlnParser.h"
#include <iostream>
#include "cmVisualStudioSlnData.h"
#include "cmVisualStudioSlnParser.h"
#include "testConfig.h"
#define SLN_EXTENSION "sln-file"
static bool parsedRight(cmVisualStudioSlnParser& parser,
const std::string& file, cmSlnData& data,
cmVisualStudioSlnParser::ParseResult expected =
@@ -1,7 +0,0 @@
#ifndef testVisualStudioSlnParser_h
#define testVisualStudioSlnParser_h
#define SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
#define SLN_EXTENSION "sln-file"
#endif
+2 -2
View File
@@ -1,9 +1,9 @@
#include "testXMLParser.h"
#include <iostream>
#include "cmXMLParser.h"
#include "testConfig.h"
int testXMLParser(int /*unused*/, char* /*unused*/[])
{
// TODO: Derive from parser and check attributes.
-6
View File
@@ -1,6 +0,0 @@
#ifndef testXMLParser_h
#define testXMLParser_h
#define SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@"
#endif