diff options
author | Brad King <brad.king@kitware.com> | 2010-12-28 20:25:49 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2010-12-28 20:25:49 (GMT) |
commit | 97c5171d6c1eb0b201662067e9c041003415ae93 (patch) | |
tree | 19ef7903aafb37f634f1dbf740d633e1355a3e00 /Tests | |
parent | 8b73f54bc63f50c48d9356c108eec44bb5e0dbc3 (diff) | |
parent | 667a90a0844a2b00a046e9597811c06905b6347d (diff) | |
download | CMake-97c5171d6c1eb0b201662067e9c041003415ae93.zip CMake-97c5171d6c1eb0b201662067e9c041003415ae93.tar.gz CMake-97c5171d6c1eb0b201662067e9c041003415ae93.tar.bz2 |
Merge topic 'dev/add_test-working-directory'
667a90a Fix sentence break in add_test documentation
96309fc Make TestsWorkingDirectory test a C file
a4a5e37 Use iostream to make Borland happy
cfe53cd Fully specify the path to old-signature add_test
017d4e9 Group adding tests with its properties
561cc33 Only test the default cwd with Makefiles
d87bae7 Simplify the _default_cwd derivation
992c74f Use --><-- markers to denote the path
5249551 Flip slashes around on Windows
0a014da Add ctype.h include for toupper()
af12f83 Fix header includes for C++ and Visual Studio
5597aa2 Rename the project to match the test
9bf4165 Add tests for WORKING_DIRECTORY arg to add_test
42de5d0 Add WORKING_DIRECTORY argument to add_test
7679f9f Rename WorkingDirectory test
d95f817 Add the WORKING_DIRECTORY property to tests
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Tests/TestsWorkingDirectory/CMakeLists.txt | 52 | ||||
-rw-r--r-- | Tests/TestsWorkingDirectory/main.c | 66 |
3 files changed, 131 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 7409b0b..289e632 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1114,6 +1114,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(TestsWorkingDirectory ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/TestsWorkingDirectory" + "${CMake_BINARY_DIR}/Tests/TestsWorkingDirectory" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project TestsWorkingDirectoryProj + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-exe-dir "${CMake_BINARY_DIR}/Tests/TestsWorkingDirectory" + --force-new-ctest-process + --test-command ${CMAKE_CTEST_COMMAND} -V + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/TestsWorkingDirectory") + # 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/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt new file mode 100644 index 0000000..01e6650 --- /dev/null +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 2.6) +project(TestsWorkingDirectoryProj) + +add_executable(WorkingDirectory main.c) + +enable_testing() + +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") + +add_test(NAME WorkingDirectory1 COMMAND 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}") + +add_test(NAME WorkingDirectory2 COMMAND WorkingDirectory) +set_tests_properties(WorkingDirectory2 PROPERTIES + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/.." + PASS_REGULAR_EXPRESSION "Working directory: -->${_parent_dir}<--" +) + +get_filename_component(_default_cwd "${EXECUTABLE_OUTPUT_PATH}" PATH) + +# FIXME: How to deal with /debug, /release, etc. with VS or XCode? +if(${CMAKE_GENERATOR} MATCHES "Makefiles") +add_test(WorkingDirectory3 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory) +set_tests_properties(WorkingDirectory3 PROPERTIES + PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" +) +endif() + +add_test(NAME WorkingDirectory4 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND WorkingDirectory) +set_tests_properties(WorkingDirectory4 PROPERTIES + PASS_REGULAR_EXPRESSION "Working directory: -->${CMAKE_BINARY_DIR}<--" +) + +string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_BINARY_DIR}") + +add_test(NAME WorkingDirectory5 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/.. COMMAND WorkingDirectory) +set_tests_properties(WorkingDirectory5 PROPERTIES + PASS_REGULAR_EXPRESSION "Working directory: -->${_parent_dir}<--" +) + +# FIXME: How to deal with /debug, /release, etc. with VS or XCode? +if(${CMAKE_GENERATOR} MATCHES "Makefiles") +add_test(WorkingDirectory6 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) +set_tests_properties(WorkingDirectory6 PROPERTIES + PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" +) +endif() diff --git a/Tests/TestsWorkingDirectory/main.c b/Tests/TestsWorkingDirectory/main.c new file mode 100644 index 0000000..ad5eb30 --- /dev/null +++ b/Tests/TestsWorkingDirectory/main.c @@ -0,0 +1,66 @@ +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.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 + +static const char* Getcwd(char* buf, unsigned int len) +{ + const char* ret = _getcwd(buf, len); + char* p = NULL; + 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]); + } + for(p = buf; *p; ++p) + { + if(*p == '\\') + { + *p = '/'; + } + } + return ret; +} + +#else +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> + +static 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<--", cwd); + + return 0; +} |