diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2010-10-26 10:06:15 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2010-12-16 21:23:18 (GMT) |
commit | d95f817f77378021a067f9f2b4f286a12acb6cd8 (patch) | |
tree | 2e7d15a6e5d72a3d2f994316c0ff39ecff0c46e3 /Tests | |
parent | 72ebd4ee12fc99b5302c18619f120bd9c285b474 (diff) | |
download | CMake-d95f817f77378021a067f9f2b4f286a12acb6cd8.zip CMake-d95f817f77378021a067f9f2b4f286a12acb6cd8.tar.gz CMake-d95f817f77378021a067f9f2b4f286a12acb6cd8.tar.bz2 |
Add the WORKING_DIRECTORY property to tests
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/WorkingDirectory/CMakeLists.txt | 29 | ||||
-rw-r--r-- | Tests/WorkingDirectory/main.cxx | 56 |
3 files changed, 98 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 04f0774..8c89be5 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1084,6 +1084,19 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleGeneratorTest") ENDIF(APPLE AND CTEST_TEST_CPACK) + ADD_TEST(WorkingDirectory ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/WorkingDirectory" + "${CMake_BINARY_DIR}/Tests/WorkingDirectory" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project WorkingDirectoryProj + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-exe-dir "${CMake_BINARY_DIR}/Tests/WorkingDirectory" + --force-new-ctest-process + --test-command ${CMAKE_CTEST_COMMAND} -V + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/WorkingDirectory") + # Make sure CTest can handle a test with no newline in output. ADD_TEST(CTest.NoNewline ${CMAKE_CMAKE_COMMAND} -E echo_append "This line has no newline!") diff --git a/Tests/WorkingDirectory/CMakeLists.txt b/Tests/WorkingDirectory/CMakeLists.txt new file mode 100644 index 0000000..5fbcd2a --- /dev/null +++ b/Tests/WorkingDirectory/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 2.6) +project(WorkingDirectoryProj) + +add_executable(WorkingDirectory main.cxx) + +enable_testing() + +add_test(NAME WorkingDirectory1 COMMAND WorkingDirectory) +add_test(NAME WorkingDirectory2 COMMAND WorkingDirectory) +add_test(WorkingDirectory3 WorkingDirectory) + +set_tests_properties(WorkingDirectory1 PROPERTIES + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + PASS_REGULAR_EXPRESSION "Working directory: ${CMAKE_BINARY_DIR}" +) + +string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_BINARY_DIR}") + +set_tests_properties(WorkingDirectory2 PROPERTIES + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/.." + PASS_REGULAR_EXPRESSION "Working directory: ${_parent_dir}" +) + +string(REGEX REPLACE "/[^/]*$" "" _wd_exe "${CMAKE_BINARY_DIR}") +get_filename_component(_default_cwd "${_wd_exe}" ABSOLUTE) + +set_tests_properties(WorkingDirectory3 PROPERTIES + PASS_REGULAR_EXPRESSION "Working directory: ${_default_cwd}" +) diff --git a/Tests/WorkingDirectory/main.cxx b/Tests/WorkingDirectory/main.cxx new file mode 100644 index 0000000..6636da0 --- /dev/null +++ b/Tests/WorkingDirectory/main.cxx @@ -0,0 +1,56 @@ +#include <stdio.h> +#include <stdlib.h> + +#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) + +#include <io.h> +#include <direct.h> + +#if defined(__WATCOMC__) +#include <direct.h> +#define _getcwd getcwd +#endif + +inline const char* Getcwd(char* buf, unsigned int len) +{ + const char* ret = _getcwd(buf, len); + if(!ret) + { + fprintf(stderr, "No current working directory.\n"); + abort(); + } + // make sure the drive letter is capital + if(strlen(buf) > 1 && buf[1] == ':') + { + buf[0] = toupper(buf[0]); + } + return ret; +} + +#else +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> + +inline const char* Getcwd(char* buf, unsigned int len) +{ + const char* ret = getcwd(buf, len); + if(!ret) + { + fprintf(stderr, "No current working directory\n"); + abort(); + } + return ret; +} + +#endif + +int main(int argc, char *argv[]) +{ + char buf[2048]; + const char *cwd = Getcwd(buf, sizeof(buf)); + + fprintf(stdout, "Working directory: %s\n", cwd); + + return 0; +} |