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.
This commit is contained in:
Martchus 2018-05-01 23:59:28 +02:00
parent 94e76f5a1a
commit 52bf075317
3 changed files with 8 additions and 7 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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();