added validateCFG and checkcfg targets to CMake / some refactorings (#2687)
This commit is contained in:
parent
4a2082e3c5
commit
488813d00f
|
@ -19,6 +19,16 @@ file(GLOB addons "addons/*.py")
|
||||||
file(GLOB cfgs "cfg/*.cfg")
|
file(GLOB cfgs "cfg/*.cfg")
|
||||||
file(GLOB platforms "platforms/*.xml")
|
file(GLOB platforms "platforms/*.xml")
|
||||||
|
|
||||||
|
find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
|
||||||
|
if (LIBXML2_XMLLINT_EXECUTABLE)
|
||||||
|
add_custom_target(validateCFG ${LIBXML2_XMLLINT_EXECUTABLE} --noout ${CMAKE_SOURCE_DIR}/cfg/cppcheck-cfg.rng)
|
||||||
|
foreach(cfg ${cfgs})
|
||||||
|
get_filename_component(cfgname ${cfg} NAME_WE)
|
||||||
|
add_custom_target(validateCFG-${cfgname} ${LIBXML2_XMLLINT_EXECUTABLE} --noout --relaxng ${CMAKE_SOURCE_DIR}/cfg/cppcheck-cfg.rng ${cfg})
|
||||||
|
add_dependencies(validateCFG validateCFG-${cfgname})
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
if (BUILD_TESTS)
|
if (BUILD_TESTS)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -33,6 +33,7 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(BUILD_TESTS "Build tests" OFF)
|
option(BUILD_TESTS "Build tests" OFF)
|
||||||
|
option(REGISTER_TESTS "Register tests in CTest" ON)
|
||||||
option(ENABLE_CHECK_INTERNAL "Enable internal checks" OFF)
|
option(ENABLE_CHECK_INTERNAL "Enable internal checks" OFF)
|
||||||
option(ENABLE_OSS_FUZZ "Enable the OSS-Fuzz related targets" ON)
|
option(ENABLE_OSS_FUZZ "Enable the OSS-Fuzz related targets" ON)
|
||||||
option(BUILD_GUI "Build the qt application" OFF)
|
option(BUILD_GUI "Build the qt application" OFF)
|
||||||
|
|
|
@ -31,7 +31,11 @@ if(NOT DEFINED BUILD_SHARED_LIBS)
|
||||||
else()
|
else()
|
||||||
message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
|
message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
|
||||||
endif(NOT DEFINED BUILD_SHARED_LIBS)
|
endif(NOT DEFINED BUILD_SHARED_LIBS)
|
||||||
|
message( STATUS "LIBXML2_XMLLINT_EXECUTABLE = ${LIBXML2_XMLLINT_EXECUTABLE}" )
|
||||||
message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" )
|
message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" )
|
||||||
|
if(BUILD_TESTS)
|
||||||
|
message( STATUS "REGISTER_TESTS = ${REGISTER_TESTS}" )
|
||||||
|
endif()
|
||||||
message( STATUS "ENABLE_CHECK_INTERNAL = ${ENABLE_CHECK_INTERNAL}" )
|
message( STATUS "ENABLE_CHECK_INTERNAL = ${ENABLE_CHECK_INTERNAL}" )
|
||||||
message( STATUS "ENABLE_OSS_FUZZ = ${ENABLE_OSS_FUZZ}" )
|
message( STATUS "ENABLE_OSS_FUZZ = ${ENABLE_OSS_FUZZ}" )
|
||||||
message( STATUS )
|
message( STATUS )
|
||||||
|
|
|
@ -3239,7 +3239,7 @@ void CheckOther::knownArgumentError(const Token *tok, const Token *ftok, const V
|
||||||
const std::string &expr = tok->expressionString();
|
const std::string &expr = tok->expressionString();
|
||||||
const std::string &fun = ftok->str();
|
const std::string &fun = ftok->str();
|
||||||
|
|
||||||
const char *id;;
|
const char *id;
|
||||||
std::string errmsg = "Argument '" + expr + "' to function " + fun + " is always " + std::to_string(intvalue) + ". ";
|
std::string errmsg = "Argument '" + expr + "' to function " + fun + " is always " + std::to_string(intvalue) + ". ";
|
||||||
if (!isVariableExpressionHidden) {
|
if (!isVariableExpressionHidden) {
|
||||||
id = "knownArgument";
|
id = "knownArgument";
|
||||||
|
|
|
@ -1,17 +1,4 @@
|
||||||
if (BUILD_TESTS)
|
if (BUILD_TESTS)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.4) # cmake_policy(SET CMP0064 NEW)
|
|
||||||
cmake_policy(SET CMP0064 NEW)
|
|
||||||
cmake_policy(SET CMP0057 NEW)
|
|
||||||
|
|
||||||
include(CTest)
|
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
|
||||||
include(ProcessorCount)
|
|
||||||
ProcessorCount(N)
|
|
||||||
set(CTEST_PARALLEL_LEVEL ${N} CACHE STRING "CTest parallel level")
|
|
||||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${CTEST_PARALLEL_LEVEL} -C ${CMAKE_CFG_INTDIR} --timeout 90)
|
|
||||||
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
|
include_directories(${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
|
||||||
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml)
|
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
|
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
|
||||||
|
@ -26,24 +13,41 @@ if (BUILD_TESTS)
|
||||||
if (USE_Z3)
|
if (USE_Z3)
|
||||||
target_link_libraries(testrunner ${Z3_LIBRARIES})
|
target_link_libraries(testrunner ${Z3_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
if (WIN32 AND NOT BORLAND)
|
||||||
|
target_link_libraries(testrunner Shlwapi.lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
|
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
|
||||||
target_precompile_headers(testrunner PRIVATE precompiled.h)
|
target_precompile_headers(testrunner PRIVATE precompiled.h)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_target(copy_cfg ALL
|
add_custom_target(copy_cfg ALL
|
||||||
|
${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/cfg"
|
||||||
|
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cfg"
|
||||||
COMMENT "Copying cfg files")
|
COMMENT "Copying cfg files")
|
||||||
add_custom_command(
|
add_dependencies(testrunner copy_cfg)
|
||||||
TARGET copy_cfg
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/cfg"
|
|
||||||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cfg")
|
|
||||||
|
|
||||||
if (WIN32 AND NOT BORLAND)
|
if (LIBXML2_XMLLINT_EXECUTABLE)
|
||||||
target_link_libraries(testrunner Shlwapi.lib)
|
# TODO: get rid of the copy
|
||||||
|
add_custom_target(checkcfg ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cppcheck> ${CMAKE_SOURCE_DIR}
|
||||||
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cfg/runtests.sh
|
||||||
|
DEPENDS cppcheck validateCFG
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cfg)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_dependencies(testrunner copy_cfg)
|
if (REGISTER_TESTS)
|
||||||
add_dependencies(check testrunner cppcheck)
|
cmake_minimum_required(VERSION 3.4) # cmake_policy(SET CMP0064 NEW)
|
||||||
|
cmake_policy(SET CMP0064 NEW)
|
||||||
|
cmake_policy(SET CMP0057 NEW)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
include(ProcessorCount)
|
||||||
|
ProcessorCount(N)
|
||||||
|
set(CTEST_PARALLEL_LEVEL ${N} CACHE STRING "CTest parallel level")
|
||||||
|
add_custom_target(check ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${CTEST_PARALLEL_LEVEL} -C ${CMAKE_CFG_INTDIR} --timeout 90
|
||||||
|
DEPENDS testrunner cppcheck)
|
||||||
|
|
||||||
set(SKIP_TESTS "" CACHE STRING "A list of tests to skip")
|
set(SKIP_TESTS "" CACHE STRING "A list of tests to skip")
|
||||||
|
|
||||||
|
@ -71,6 +75,7 @@ if (BUILD_TESTS)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# TODO: what is this?
|
||||||
add_fixture(TestSamples WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
add_fixture(TestSamples WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||||
foreach(SRC ${srcs})
|
foreach(SRC ${srcs})
|
||||||
file(STRINGS ${SRC} FIXTURE_LINE REGEX "TestFixture\\(" LIMIT_COUNT 1)
|
file(STRINGS ${SRC} FIXTURE_LINE REGEX "TestFixture\\(" LIMIT_COUNT 1)
|
||||||
|
@ -78,6 +83,7 @@ if (BUILD_TESTS)
|
||||||
add_fixture(${CMAKE_MATCH_1})
|
add_fixture(${CMAKE_MATCH_1})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
# TODO: parse files for REGISTER_TEST macro
|
||||||
add_fixture(TestLeakAutoVarStrcpy)
|
add_fixture(TestLeakAutoVarStrcpy)
|
||||||
add_fixture(TestLeakAutoVarWindows)
|
add_fixture(TestLeakAutoVarWindows)
|
||||||
add_fixture(TestMemleakInFunction)
|
add_fixture(TestMemleakInFunction)
|
||||||
|
@ -111,6 +117,7 @@ if (BUILD_TESTS)
|
||||||
endif()
|
endif()
|
||||||
if (${TEST_NAME} IN_LIST SKIP_TESTS)
|
if (${TEST_NAME} IN_LIST SKIP_TESTS)
|
||||||
else()
|
else()
|
||||||
|
# TODO: add syntax check
|
||||||
add_test(NAME cfg-${TEST_NAME}
|
add_test(NAME cfg-${TEST_NAME}
|
||||||
COMMAND $<TARGET_FILE:cppcheck>
|
COMMAND $<TARGET_FILE:cppcheck>
|
||||||
--check-library
|
--check-library
|
||||||
|
@ -121,29 +128,35 @@ if (BUILD_TESTS)
|
||||||
--error-exitcode=1
|
--error-exitcode=1
|
||||||
--suppress=missingIncludeSystem
|
--suppress=missingIncludeSystem
|
||||||
--inline-suppr
|
--inline-suppr
|
||||||
|
--template="{file}:{line}:{severity}:{id}:{message}"
|
||||||
${INCONCLUSIVE}
|
${INCONCLUSIVE}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/cfg/${CFG_TEST}
|
${CMAKE_CURRENT_SOURCE_DIR}/cfg/${CFG_TEST}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
add_cfg(boost.cpp INCONCLUSIVE)
|
|
||||||
add_cfg(bsd.c)
|
|
||||||
add_cfg(gnu.c LIBRARY posix gnu)
|
|
||||||
add_cfg(googletest.cpp)
|
|
||||||
add_cfg(gtk.c INCONCLUSIVE)
|
|
||||||
add_cfg(libcurl.c)
|
|
||||||
add_cfg(lua.c)
|
|
||||||
add_cfg(openmp.c)
|
|
||||||
add_cfg(posix.c)
|
add_cfg(posix.c)
|
||||||
add_cfg(python.c)
|
add_cfg(gnu.c LIBRARY posix;gnu)
|
||||||
add_cfg(qt.cpp)
|
add_cfg(qt.cpp INCONCLUSIVE)
|
||||||
add_cfg(sqlite3.c INCONCLUSIVE)
|
add_cfg(bsd.c)
|
||||||
add_cfg(std.c INCONCLUSIVE)
|
add_cfg(std.c INCONCLUSIVE)
|
||||||
add_cfg(std.cpp INCONCLUSIVE)
|
add_cfg(std.cpp INCONCLUSIVE)
|
||||||
add_cfg(windows.cpp INCONCLUSIVE NAME windows32A PLATFORM win32A)
|
add_cfg(windows.cpp INCONCLUSIVE NAME windows32A PLATFORM win32A)
|
||||||
add_cfg(windows.cpp INCONCLUSIVE NAME windows32W PLATFORM win32W)
|
add_cfg(windows.cpp INCONCLUSIVE NAME windows32W PLATFORM win32W)
|
||||||
add_cfg(windows.cpp INCONCLUSIVE NAME windows64 PLATFORM win64)
|
add_cfg(windows.cpp INCONCLUSIVE NAME windows64 PLATFORM win64)
|
||||||
add_cfg(wxwidgets.cpp INCONCLUSIVE)
|
add_cfg(wxwidgets.cpp INCONCLUSIVE)
|
||||||
|
add_cfg(gtk.c INCONCLUSIVE)
|
||||||
|
add_cfg(boost.cpp INCONCLUSIVE)
|
||||||
|
add_cfg(sqlite3.c INCONCLUSIVE)
|
||||||
|
add_cfg(openmp.c)
|
||||||
|
add_cfg(python.c)
|
||||||
|
add_cfg(lua.c)
|
||||||
|
add_cfg(libcurl.c)
|
||||||
|
add_cfg(cairo.c)
|
||||||
|
add_cfg(googletest.cpp INCONCLUSIVE)
|
||||||
|
add_cfg(kde.cpp INCONCLUSIVE)
|
||||||
|
add_cfg(libsigc++.cpp)
|
||||||
|
add_cfg(openssl.c)
|
||||||
|
add_cfg(opencv2.cpp)
|
||||||
|
|
||||||
# Set cost of the more expensive tests to help improve parallel scheduling
|
# Set cost of the more expensive tests to help improve parallel scheduling
|
||||||
# of tests
|
# of tests
|
||||||
|
@ -152,4 +165,5 @@ if (BUILD_TESTS)
|
||||||
fixture_cost(TestThreadExecutor 5)
|
fixture_cost(TestThreadExecutor 5)
|
||||||
fixture_cost(TestLeakAutoVar 4)
|
fixture_cost(TestLeakAutoVar 4)
|
||||||
fixture_cost(TestTokenizer 4)
|
fixture_cost(TestTokenizer 4)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -84,6 +84,7 @@ private:
|
||||||
exec.check(7, argv);
|
exec.check(7, argv);
|
||||||
std::string expected_filename = Path::getPathFromFilename(i->first) + "out.txt";
|
std::string expected_filename = Path::getPathFromFilename(i->first) + "out.txt";
|
||||||
std::ifstream ifs(expected_filename);
|
std::ifstream ifs(expected_filename);
|
||||||
|
// TODO: this contains stray \n at the start of each line when the out.txt files have CRLF
|
||||||
std::string expected((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
std::string expected((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
|
||||||
std::string actual = GET_REDIRECT_ERROUT;
|
std::string actual = GET_REDIRECT_ERROUT;
|
||||||
// We need some uniformization to make this work on Unix and Windows
|
// We need some uniformization to make this work on Unix and Windows
|
||||||
|
|
Loading…
Reference in New Issue