From 52bf075317a6cd2cc6e000a058c7ed9889fcb6da Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 1 May 2018 23:59:28 +0200 Subject: [PATCH] Move creation of srcdirref and testfiles dir to BasicConfig Those make testing more convenient and are also useful when there's no test target, eg. when testing syncthingtray with mocked configuration. --- cmake/modules/BasicConfig.cmake | 6 ++++++ cmake/modules/TestTarget.cmake | 6 ------ tests/testutils.cpp | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmake/modules/BasicConfig.cmake b/cmake/modules/BasicConfig.cmake index 4d354d6..2d3c18b 100644 --- a/cmake/modules/BasicConfig.cmake +++ b/cmake/modules/BasicConfig.cmake @@ -208,6 +208,12 @@ if(HAS_PARENT) message(STATUS "For the check target to work, it is required to call enable_testing() on the source directory root.") endif() +# make testing more convenient (not only useful if there's a test target; this is for instance also used in mocked configuration of syncthingtray) +# -> add a file called "srcdirref" to the build directory; this file contains the path of the sources so tests can easily find test files contained in the source directory +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/srcdirref" "${CMAKE_CURRENT_SOURCE_DIR}") +# -> ensure the directory "testfiles" exists in the build directory; tests will create the directory for working copies of testfiles there by default +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testfiles") + # add target for tidying with clang-format if(NOT META_NO_TIDY AND EXISTS "${CLANG_FORMAT_RULES}") option(CLANG_FORMAT_ENABLED "enables creation of tidy target using clang-format" OFF) diff --git a/cmake/modules/TestTarget.cmake b/cmake/modules/TestTarget.cmake index 4614f5a..9bdd578 100644 --- a/cmake/modules/TestTarget.cmake +++ b/cmake/modules/TestTarget.cmake @@ -352,12 +352,6 @@ if(CPP_UNIT_LIB OR META_NO_CPP_UNIT) endif() endif() - # add a file called "srcdirref" to the build directory; this file contains the path of the sources so tests can easily find test files contained in the source directory - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/srcdirref" "${CMAKE_CURRENT_SOURCE_DIR}") - - # ensure the directory "testfiles" exists in the build directory; tests will create the directory for working copies of testfiles there by default - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/testfiles") - set(META_HAVE_TESTS YES) else() diff --git a/tests/testutils.cpp b/tests/testutils.cpp index b3a2569..b5a4826 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -478,7 +478,8 @@ string TestApplication::readTestfilePathFromSrcRef() return srcDirContent += "/testfiles/"; } catch (...) { - // the "srcdirref" file likely just does not exist, so ignore the error case for now + cerr << Phrases::Warning << "The file \"srcdirref\" can not be opened. It likely just doesn't exist in the working directory." + << Phrases::EndFlush; catchIoFailure(); } return string();