Browse Source

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.
consistent_macro_prefix
Martchus 4 years ago
parent
commit
52bf075317
  1. 6
      cmake/modules/BasicConfig.cmake
  2. 6
      cmake/modules/TestTarget.cmake
  3. 3
      tests/testutils.cpp

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

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

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

Loading…
Cancel
Save