X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FSupport%2FProgramTest.cpp;h=6852ca616e08aa9d48af8d244c25e1117ade8205;hb=7172b38af7ed5d1c1e2c97fadfb0ae0c19aff816;hp=80b0334c675c87a9bc0e5836d30ac077ffc0e983;hpb=8eca677afee90d6a28487fd3db0bca129bde7186;p=oota-llvm.git diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp old mode 100755 new mode 100644 index 80b0334c675..6852ca616e0 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -8,18 +8,22 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" #include "gtest/gtest.h" #include -#ifdef __APPLE__ +#if defined(__APPLE__) # include -#else +#elif !defined(_MSC_VER) // Forward declare environ in case it's not provided by stdlib.h. extern char **environ; #endif +// From TestMain.cpp. +extern const char *TestMainArgv0; + namespace { using namespace llvm; @@ -32,8 +36,6 @@ ProgramTestStringArg2("program-test-string-arg2"); static void CopyEnvironment(std::vector &out) { #ifdef __APPLE__ - // _NSGetEnviron() only works from the main exe on Mac. Fortunately the test - // should be in the executable. char **envp = *_NSGetEnviron(); #else // environ seems to work for Windows and most other Unices. @@ -54,9 +56,8 @@ TEST(ProgramTest, CreateProcessTrailingSlash) { exit(1); } - // FIXME: Hardcoding argv0 here since I don't know a good cross-platform way - // to get it. Maybe ParseCommandLineOptions() should save it? - Path my_exe = Path::GetMainExecutable("SupportTests", &ProgramTestStringArg1); + std::string my_exe = + sys::fs::getMainExecutable(TestMainArgv0, &ProgramTestStringArg1); const char *argv[] = { my_exe.c_str(), "--gtest_filter=ProgramTest.CreateProcessTrailingSlashChild", @@ -75,14 +76,14 @@ TEST(ProgramTest, CreateProcessTrailingSlash) { bool ExecutionFailed; // Redirect stdout and stdin to NUL, but let stderr through. #ifdef LLVM_ON_WIN32 - Path nul("NUL"); + StringRef nul("NUL"); #else - Path nul("/dev/null"); + StringRef nul("/dev/null"); #endif - const Path *redirects[] = { &nul, &nul, 0 }; - int rc = Program::ExecuteAndWait(my_exe, argv, &envp[0], redirects, - /*secondsToWait=*/10, /*memoryLimit=*/0, - &error, &ExecutionFailed); + const StringRef *redirects[] = { &nul, &nul, 0 }; + int rc = ExecuteAndWait(my_exe, argv, &envp[0], redirects, + /*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error, + &ExecutionFailed); EXPECT_FALSE(ExecutionFailed) << error; EXPECT_EQ(0, rc); }