diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-01-26 19:21:32 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-01-26 19:21:32 +0000 |
commit | 650d5bf3ba200ecbeccbfcec6e7b6cc6f40a1f60 (patch) | |
tree | 2c3c7d9501a94340bd4ee3bd4858ebc305bca3eb /src/gtest.cc | |
parent | b593ccbbbe6dcef342f833a37e41af0b750c7f14 (diff) | |
download | googletest-650d5bf3ba200ecbeccbfcec6e7b6cc6f40a1f60.tar.gz googletest-650d5bf3ba200ecbeccbfcec6e7b6cc6f40a1f60.tar.bz2 googletest-650d5bf3ba200ecbeccbfcec6e7b6cc6f40a1f60.zip |
Fixes the bug where the XML output path is affected by test changing the current directory. By Stefan Weigand.
Diffstat (limited to 'src/gtest.cc')
-rw-r--r-- | src/gtest.cc | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/gtest.cc b/src/gtest.cc index 0e3115ba..d6be608a 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -69,7 +69,7 @@ #include <sys/time.h> // NOLINT // On z/OS we additionally need strings.h for strcasecmp. -#include <strings.h> +#include <strings.h> // NOLINT #elif defined(_WIN32_WCE) // We are on Windows CE. @@ -289,6 +289,7 @@ Mutex g_linked_ptr_mutex(Mutex::NO_CONSTRUCTOR_NEEDED_FOR_STATIC_MUTEX); // Application pathname gotten in InitGoogleTest. String g_executable_path; +String g_original_working_dir; // Returns the current application's name, removing directory path if that // is present. @@ -319,16 +320,27 @@ String UnitTestOptions::GetOutputFormat() { // Returns the name of the requested output file, or the default if none // was explicitly specified. -String UnitTestOptions::GetOutputFile() { +String UnitTestOptions::GetAbsolutePathToOutputFile() { const char* const gtest_output_flag = GTEST_FLAG(output).c_str(); if (gtest_output_flag == NULL) return String(""); const char* const colon = strchr(gtest_output_flag, ':'); if (colon == NULL) - return String(kDefaultOutputFile); + return String(internal::FilePath::ConcatPaths( + internal::FilePath(g_original_working_dir), + internal::FilePath(kDefaultOutputFile)).ToString() ); internal::FilePath output_name(colon + 1); + if (!output_name.IsAbsolutePath()) + // TODO(wan@google.com): on Windows \some\path is not an absolute + // path (as its meaning depends on the current drive), yet the + // following logic for turning it into an absolute path is wrong. + // Fix it. + output_name = internal::FilePath::ConcatPaths( + internal::FilePath(g_original_working_dir), + internal::FilePath(colon + 1)); + if (!output_name.IsDirectory()) return output_name.ToString(); @@ -3675,7 +3687,7 @@ UnitTestEventListenerInterface* UnitTestImpl::result_printer() { const String& output_format = internal::UnitTestOptions::GetOutputFormat(); if (output_format == "xml") { repeater->AddListener(new XmlUnitTestResultPrinter( - internal::UnitTestOptions::GetOutputFile().c_str())); + internal::UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); } else if (output_format != "") { printf("WARNING: unrecognized output format \"%s\" ignored.\n", output_format.c_str()); @@ -3926,6 +3938,8 @@ void InitGoogleTestImpl(int* argc, CharType** argv) { if (*argc <= 0) return; internal::g_executable_path = internal::StreamableToString(argv[0]); + internal::g_original_working_dir = + internal::FilePath::GetCurrentDir().ToString(); #ifdef GTEST_HAS_DEATH_TEST g_argvs.clear(); |