From d95f817f77378021a067f9f2b4f286a12acb6cd8 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Tue, 26 Oct 2010 12:06:15 +0200 Subject: Add the WORKING_DIRECTORY property to tests --- Source/CTest/cmCTestTestHandler.cxx | 5 +++- Source/cmTest.cxx | 6 ++++ Tests/CMakeLists.txt | 13 ++++++++ Tests/WorkingDirectory/CMakeLists.txt | 29 ++++++++++++++++++ Tests/WorkingDirectory/main.cxx | 56 +++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 Tests/WorkingDirectory/CMakeLists.txt create mode 100644 Tests/WorkingDirectory/main.cxx diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 6dd348d..b8e38fb 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -2190,7 +2190,6 @@ bool cmCTestTestHandler::SetTestsProperties( { rtit->Labels.push_back(*crit); } - } if ( key == "MEASUREMENT" ) { @@ -2219,6 +2218,10 @@ bool cmCTestTestHandler::SetTestsProperties( std::string(crit->c_str()))); } } + if ( key == "WORKING_DIRECTORY" ) + { + rtit->Directory = val; + } } } } diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx index 4e9b973..c25a8b6 100644 --- a/Source/cmTest.cxx +++ b/Source/cmTest.cxx @@ -196,4 +196,10 @@ void cmTest::DefineProperties(cmake *cm) "If set to true, this will invert the pass/fail flag of the test.", "This property can be used for tests that are expected to fail and " "return a non zero return code."); + + cm->DefineProperty + ("WORKING_DIRECTORY", cmProperty::TEST, + "The directory from which the test executable will be called.", + "If this is not set it is called from the directory the test executable " + "is located in."); } 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 +#include + +#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) + +#include +#include + +#if defined(__WATCOMC__) +#include +#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 +#include +#include + +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; +} -- cgit v0.12 From 7679f9fab099e729b61320927a9e0b8d03546f7f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 16 Dec 2010 16:50:16 -0500 Subject: Rename WorkingDirectory test --- Tests/CMakeLists.txt | 12 +++---- Tests/TestsWorkingDirectory/CMakeLists.txt | 29 ++++++++++++++++ Tests/TestsWorkingDirectory/main.cxx | 56 ++++++++++++++++++++++++++++++ Tests/WorkingDirectory/CMakeLists.txt | 29 ---------------- Tests/WorkingDirectory/main.cxx | 56 ------------------------------ 5 files changed, 91 insertions(+), 91 deletions(-) create mode 100644 Tests/TestsWorkingDirectory/CMakeLists.txt create mode 100644 Tests/TestsWorkingDirectory/main.cxx delete mode 100644 Tests/WorkingDirectory/CMakeLists.txt delete mode 100644 Tests/WorkingDirectory/main.cxx diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 8c89be5..0e1edfc 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1084,18 +1084,18 @@ ${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} + ADD_TEST(TestsWorkingDirectory ${CMAKE_CTEST_COMMAND} --build-and-test - "${CMake_SOURCE_DIR}/Tests/WorkingDirectory" - "${CMake_BINARY_DIR}/Tests/WorkingDirectory" + "${CMake_SOURCE_DIR}/Tests/TestsWorkingDirectory" + "${CMake_BINARY_DIR}/Tests/TestsWorkingDirectory" --build-generator ${CMAKE_TEST_GENERATOR} - --build-project WorkingDirectoryProj + --build-project TestsWorkingDirectoryProj --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} - --build-exe-dir "${CMake_BINARY_DIR}/Tests/WorkingDirectory" + --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/WorkingDirectory") + 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 diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt new file mode 100644 index 0000000..5fbcd2a --- /dev/null +++ b/Tests/TestsWorkingDirectory/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/TestsWorkingDirectory/main.cxx b/Tests/TestsWorkingDirectory/main.cxx new file mode 100644 index 0000000..6636da0 --- /dev/null +++ b/Tests/TestsWorkingDirectory/main.cxx @@ -0,0 +1,56 @@ +#include +#include + +#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) + +#include +#include + +#if defined(__WATCOMC__) +#include +#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 +#include +#include + +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; +} diff --git a/Tests/WorkingDirectory/CMakeLists.txt b/Tests/WorkingDirectory/CMakeLists.txt deleted file mode 100644 index 5fbcd2a..0000000 --- a/Tests/WorkingDirectory/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 6636da0..0000000 --- a/Tests/WorkingDirectory/main.cxx +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) - -#include -#include - -#if defined(__WATCOMC__) -#include -#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 -#include -#include - -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; -} -- cgit v0.12 From 42de5d02dddec69ee045b423fbd58751f210839d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 16 Dec 2010 16:48:27 -0500 Subject: Add WORKING_DIRECTORY argument to add_test --- Source/cmAddTestCommand.cxx | 17 +++++++++++++++++ Source/cmAddTestCommand.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/Source/cmAddTestCommand.cxx b/Source/cmAddTestCommand.cxx index 923206d..11ca9e7 100644 --- a/Source/cmAddTestCommand.cxx +++ b/Source/cmAddTestCommand.cxx @@ -74,6 +74,7 @@ bool cmAddTestCommand::HandleNameMode(std::vector const& args) { std::string name; std::vector configurations; + std::string working_directory; std::vector command; // Read the arguments. @@ -81,6 +82,7 @@ bool cmAddTestCommand::HandleNameMode(std::vector const& args) DoingName, DoingCommand, DoingConfigs, + DoingWorkingDirectory, DoingNone }; Doing doing = DoingName; @@ -104,6 +106,15 @@ bool cmAddTestCommand::HandleNameMode(std::vector const& args) } doing = DoingConfigs; } + else if(args[i] == "WORKING_DIRECTORY") + { + if(!working_directory.empty()) + { + this->SetError(" may be given at most one WORKING_DIRECTORY."); + return false; + } + doing = DoingWorkingDirectory; + } else if(doing == DoingName) { name = args[i]; @@ -117,6 +128,11 @@ bool cmAddTestCommand::HandleNameMode(std::vector const& args) { configurations.push_back(args[i]); } + else if(doing == DoingWorkingDirectory) + { + working_directory = args[i]; + doing = DoingNone; + } else { cmOStringStream e; @@ -154,6 +170,7 @@ bool cmAddTestCommand::HandleNameMode(std::vector const& args) cmTest* test = this->Makefile->CreateTest(name.c_str()); test->SetOldStyle(false); test->SetCommand(command); + test->SetProperty("WORKING_DIRECTORY", working_directory.c_str()); this->Makefile->AddTestGenerator(new cmTestGenerator(test, configurations)); return true; diff --git a/Source/cmAddTestCommand.h b/Source/cmAddTestCommand.h index 79fb481..9eb4e9f 100644 --- a/Source/cmAddTestCommand.h +++ b/Source/cmAddTestCommand.h @@ -68,12 +68,15 @@ public: "in the binary tree.\n" "\n" " add_test(NAME [CONFIGURATIONS [Debug|Release|...]]\n" + " [WORKING_DIRECTORY dir]\n" " COMMAND [arg1 [arg2 ...]])\n" "If COMMAND specifies an executable target (created by " "add_executable) it will automatically be replaced by the location " "of the executable created at build time. " "If a CONFIGURATIONS option is given then the test will be executed " "only when testing under one of the named configurations." + "If a WORKING_DIRECTORY option is given then the test will be executed " + "in the given directory." "\n" "Arguments after COMMAND may use \"generator expressions\" with the " "syntax \"$<...>\". " -- cgit v0.12 From 9bf4165437ed3ba4480b39cc9000f08f86fbe186 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 16 Dec 2010 16:50:34 -0500 Subject: Add tests for WORKING_DIRECTORY arg to add_test --- Tests/TestsWorkingDirectory/CMakeLists.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index 5fbcd2a..d5c786b 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -27,3 +27,24 @@ get_filename_component(_default_cwd "${_wd_exe}" ABSOLUTE) set_tests_properties(WorkingDirectory3 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: ${_default_cwd}" ) + +add_test(NAME WorkingDirectory4 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND WorkingDirectory) +add_test(NAME WorkingDirectory5 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/.. COMMAND WorkingDirectory) +add_test(WorkingDirectory6 WorkingDirectory WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) + +set_tests_properties(WorkingDirectory4 PROPERTIES + PASS_REGULAR_EXPRESSION "Working directory: ${CMAKE_BINARY_DIR}" +) + +string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_BINARY_DIR}") + +set_tests_properties(WorkingDirectory5 PROPERTIES + 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(WorkingDirectory6 PROPERTIES + PASS_REGULAR_EXPRESSION "Working directory: ${_default_cwd}" +) -- cgit v0.12 From 5597aa24f1e4c00aab39d1dd3a8d3d9ff0a8f582 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 16 Dec 2010 17:29:19 -0500 Subject: Rename the project to match the test --- Tests/TestsWorkingDirectory/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index d5c786b..73b8997 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.6) -project(WorkingDirectoryProj) +project(TestsWorkingDirectoryProj) add_executable(WorkingDirectory main.cxx) -- cgit v0.12 From af12f83d80412141117a0e84614a06af9bae68ae Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 09:14:25 -0500 Subject: Fix header includes for C++ and Visual Studio --- Tests/TestsWorkingDirectory/main.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tests/TestsWorkingDirectory/main.cxx b/Tests/TestsWorkingDirectory/main.cxx index 6636da0..eacd7ee 100644 --- a/Tests/TestsWorkingDirectory/main.cxx +++ b/Tests/TestsWorkingDirectory/main.cxx @@ -1,5 +1,6 @@ -#include -#include +#include +#include +#include #if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) -- cgit v0.12 From 0a014dab5c9566b63783986d98f398efb2fadcb8 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 09:23:59 -0500 Subject: Add ctype.h include for toupper() --- Tests/TestsWorkingDirectory/main.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/TestsWorkingDirectory/main.cxx b/Tests/TestsWorkingDirectory/main.cxx index eacd7ee..6c4802d 100644 --- a/Tests/TestsWorkingDirectory/main.cxx +++ b/Tests/TestsWorkingDirectory/main.cxx @@ -1,6 +1,7 @@ #include #include #include +#include #if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) -- cgit v0.12 From 5249551f9fd11016fffae0cb44581ae3daa2169c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 09:45:39 -0500 Subject: Flip slashes around on Windows --- Tests/TestsWorkingDirectory/main.cxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Tests/TestsWorkingDirectory/main.cxx b/Tests/TestsWorkingDirectory/main.cxx index 6c4802d..e1c24ba 100644 --- a/Tests/TestsWorkingDirectory/main.cxx +++ b/Tests/TestsWorkingDirectory/main.cxx @@ -26,6 +26,13 @@ inline const char* Getcwd(char* buf, unsigned int len) { buf[0] = toupper(buf[0]); } + for(char* p = buf; *p; ++p) + { + if(*p == '\\') + { + *p = '/'; + } + } return ret; } -- cgit v0.12 From 992c74f3e0747e806c3fc7708fea68cb2c376247 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 10:23:24 -0500 Subject: Use --><-- markers to denote the path --- Tests/TestsWorkingDirectory/CMakeLists.txt | 12 ++++++------ Tests/TestsWorkingDirectory/main.cxx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index 73b8997..c0e780c 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -11,21 +11,21 @@ add_test(WorkingDirectory3 WorkingDirectory) set_tests_properties(WorkingDirectory1 PROPERTIES WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" - PASS_REGULAR_EXPRESSION "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}" + 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}" + PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) add_test(NAME WorkingDirectory4 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND WorkingDirectory) @@ -33,18 +33,18 @@ add_test(NAME WorkingDirectory5 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/.. COMMAND add_test(WorkingDirectory6 WorkingDirectory WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) set_tests_properties(WorkingDirectory4 PROPERTIES - PASS_REGULAR_EXPRESSION "Working directory: ${CMAKE_BINARY_DIR}" + PASS_REGULAR_EXPRESSION "Working directory: -->${CMAKE_BINARY_DIR}<--" ) string(REGEX REPLACE "/[^/]*$" "" _parent_dir "${CMAKE_BINARY_DIR}") set_tests_properties(WorkingDirectory5 PROPERTIES - PASS_REGULAR_EXPRESSION "Working directory: ${_parent_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(WorkingDirectory6 PROPERTIES - PASS_REGULAR_EXPRESSION "Working directory: ${_default_cwd}" + PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) diff --git a/Tests/TestsWorkingDirectory/main.cxx b/Tests/TestsWorkingDirectory/main.cxx index e1c24ba..6a3a6be 100644 --- a/Tests/TestsWorkingDirectory/main.cxx +++ b/Tests/TestsWorkingDirectory/main.cxx @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) char buf[2048]; const char *cwd = Getcwd(buf, sizeof(buf)); - fprintf(stdout, "Working directory: %s\n", cwd); + fprintf(stdout, "Working directory: -->%s<--", cwd); return 0; } -- cgit v0.12 From d87bae7f742e5ea4d99dfd3691b6de335c6c0758 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 10:23:54 -0500 Subject: Simplify the _default_cwd derivation --- Tests/TestsWorkingDirectory/CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index c0e780c..d1c40d6 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -5,6 +5,8 @@ add_executable(WorkingDirectory main.cxx) enable_testing() +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") + add_test(NAME WorkingDirectory1 COMMAND WorkingDirectory) add_test(NAME WorkingDirectory2 COMMAND WorkingDirectory) add_test(WorkingDirectory3 WorkingDirectory) @@ -21,8 +23,7 @@ set_tests_properties(WorkingDirectory2 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_parent_dir}<--" ) -string(REGEX REPLACE "/[^/]*$" "" _wd_exe "${CMAKE_BINARY_DIR}") -get_filename_component(_default_cwd "${_wd_exe}" ABSOLUTE) +get_filename_component(_default_cwd "${EXECUTABLE_OUTPUT_PATH}" PATH) set_tests_properties(WorkingDirectory3 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" @@ -42,9 +43,6 @@ set_tests_properties(WorkingDirectory5 PROPERTIES 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(WorkingDirectory6 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) -- cgit v0.12 From 561cc3359cca42749f797dd5ea908531740a873d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 10:24:14 -0500 Subject: Only test the default cwd with Makefiles XCode and Visual Studio generators can run from ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE} and determining this at testing time is not feasible without adding in more PASS_REGULAR_EXPRESSION's which may create false positives. Since the parsing code is in cross-platform, generator-agnostic code, if it passes with Makefiles, it should work with other generators on other platforms. --- Tests/TestsWorkingDirectory/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index d1c40d6..bd52cd6 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -25,9 +25,12 @@ set_tests_properties(WorkingDirectory2 PROPERTIES 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") set_tests_properties(WorkingDirectory3 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) +endif() add_test(NAME WorkingDirectory4 WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND WorkingDirectory) add_test(NAME WorkingDirectory5 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/.. COMMAND WorkingDirectory) @@ -43,6 +46,9 @@ 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") set_tests_properties(WorkingDirectory6 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) +endif() -- cgit v0.12 From 017d4e9d2ce1544aab44f87204b5195e0c062812 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 11:06:59 -0500 Subject: Group adding tests with its properties --- Tests/TestsWorkingDirectory/CMakeLists.txt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index bd52cd6..1bc0705 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -8,9 +8,6 @@ enable_testing() set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") 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}<--" @@ -18,6 +15,7 @@ set_tests_properties(WorkingDirectory1 PROPERTIES 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}<--" @@ -27,27 +25,27 @@ 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 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) -add_test(NAME WorkingDirectory5 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/.. COMMAND WorkingDirectory) -add_test(WorkingDirectory6 WorkingDirectory WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) - 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 WorkingDirectory WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) set_tests_properties(WorkingDirectory6 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) -- cgit v0.12 From cfe53cddbde124864ffb0500475bc1c1cbd3ddbc Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 11:07:19 -0500 Subject: Fully specify the path to old-signature add_test --- Tests/TestsWorkingDirectory/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index 1bc0705..24dc5e6 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -25,7 +25,7 @@ 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 WorkingDirectory) +add_test(WorkingDirectory3 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory) set_tests_properties(WorkingDirectory3 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) @@ -45,7 +45,7 @@ set_tests_properties(WorkingDirectory5 PROPERTIES # FIXME: How to deal with /debug, /release, etc. with VS or XCode? if(${CMAKE_GENERATOR} MATCHES "Makefiles") -add_test(WorkingDirectory6 WorkingDirectory WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) +add_test(WorkingDirectory6 ${EXECUTABLE_OUTPUT_PATH}/WorkingDirectory WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) set_tests_properties(WorkingDirectory6 PROPERTIES PASS_REGULAR_EXPRESSION "Working directory: -->${_default_cwd}<--" ) -- cgit v0.12 From a4a5e375685adcfe765c45be086706720a96dbea Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 11:07:40 -0500 Subject: Use iostream to make Borland happy It seems as though cstdio doesn't bring in stdio.h with the Borland compilers. --- Tests/TestsWorkingDirectory/main.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Tests/TestsWorkingDirectory/main.cxx b/Tests/TestsWorkingDirectory/main.cxx index 6a3a6be..42c3d34 100644 --- a/Tests/TestsWorkingDirectory/main.cxx +++ b/Tests/TestsWorkingDirectory/main.cxx @@ -1,8 +1,9 @@ -#include #include #include #include +#include + #if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) #include @@ -18,7 +19,7 @@ inline const char* Getcwd(char* buf, unsigned int len) const char* ret = _getcwd(buf, len); if(!ret) { - fprintf(stderr, "No current working directory.\n"); + std::cerr << "No current working directory." << std::endl; abort(); } // make sure the drive letter is capital @@ -46,7 +47,7 @@ inline const char* Getcwd(char* buf, unsigned int len) const char* ret = getcwd(buf, len); if(!ret) { - fprintf(stderr, "No current working directory\n"); + std::cerr << "No current working directory" << std::endl; abort(); } return ret; @@ -59,7 +60,7 @@ int main(int argc, char *argv[]) char buf[2048]; const char *cwd = Getcwd(buf, sizeof(buf)); - fprintf(stdout, "Working directory: -->%s<--", cwd); + std::cout << "Working directory: -->" << cwd << "<--"; return 0; } -- cgit v0.12 From 96309fc6e2439ede2604fc18ad04e82ffc54b606 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 17 Dec 2010 12:28:33 -0500 Subject: Make TestsWorkingDirectory test a C file --- Tests/TestsWorkingDirectory/CMakeLists.txt | 2 +- Tests/TestsWorkingDirectory/main.c | 66 ++++++++++++++++++++++++++++++ Tests/TestsWorkingDirectory/main.cxx | 66 ------------------------------ 3 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 Tests/TestsWorkingDirectory/main.c delete mode 100644 Tests/TestsWorkingDirectory/main.cxx diff --git a/Tests/TestsWorkingDirectory/CMakeLists.txt b/Tests/TestsWorkingDirectory/CMakeLists.txt index 24dc5e6..01e6650 100644 --- a/Tests/TestsWorkingDirectory/CMakeLists.txt +++ b/Tests/TestsWorkingDirectory/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.6) project(TestsWorkingDirectoryProj) -add_executable(WorkingDirectory main.cxx) +add_executable(WorkingDirectory main.c) enable_testing() 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 +#include +#include +#include + +#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) + +#include +#include + +#if defined(__WATCOMC__) +#include +#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 +#include +#include + +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; +} diff --git a/Tests/TestsWorkingDirectory/main.cxx b/Tests/TestsWorkingDirectory/main.cxx deleted file mode 100644 index 42c3d34..0000000 --- a/Tests/TestsWorkingDirectory/main.cxx +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include - -#include - -#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) - -#include -#include - -#if defined(__WATCOMC__) -#include -#define _getcwd getcwd -#endif - -inline const char* Getcwd(char* buf, unsigned int len) -{ - const char* ret = _getcwd(buf, len); - if(!ret) - { - std::cerr << "No current working directory." << std::endl; - abort(); - } - // make sure the drive letter is capital - if(strlen(buf) > 1 && buf[1] == ':') - { - buf[0] = toupper(buf[0]); - } - for(char* p = buf; *p; ++p) - { - if(*p == '\\') - { - *p = '/'; - } - } - return ret; -} - -#else -#include -#include -#include - -inline const char* Getcwd(char* buf, unsigned int len) -{ - const char* ret = getcwd(buf, len); - if(!ret) - { - std::cerr << "No current working directory" << std::endl; - abort(); - } - return ret; -} - -#endif - -int main(int argc, char *argv[]) -{ - char buf[2048]; - const char *cwd = Getcwd(buf, sizeof(buf)); - - std::cout << "Working directory: -->" << cwd << "<--"; - - return 0; -} -- cgit v0.12 From 667a90a0844a2b00a046e9597811c06905b6347d Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 21 Dec 2010 14:15:05 -0500 Subject: Fix sentence break in add_test documentation Commit 42de5d02 (Add WORKING_DIRECTORY argument to add_test, 2010-12-16) added a new sentence to a paragraph without separating it by " " from the previous sentence. Add the missing spaces. --- Source/cmAddTestCommand.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmAddTestCommand.h b/Source/cmAddTestCommand.h index 9eb4e9f..6a0ace0 100644 --- a/Source/cmAddTestCommand.h +++ b/Source/cmAddTestCommand.h @@ -74,7 +74,7 @@ public: "add_executable) it will automatically be replaced by the location " "of the executable created at build time. " "If a CONFIGURATIONS option is given then the test will be executed " - "only when testing under one of the named configurations." + "only when testing under one of the named configurations. " "If a WORKING_DIRECTORY option is given then the test will be executed " "in the given directory." "\n" -- cgit v0.12