1 //===- unittest/Support/ProgramTest.cpp -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/CommandLine.h"
11 #include "llvm/Support/Path.h"
12 #include "llvm/Support/Program.h"
13 #include "gtest/gtest.h"
22 static cl::opt<std::string>
23 ProgramTestStringArg1("program-test-string-arg1");
24 static cl::opt<std::string>
25 ProgramTestStringArg2("program-test-string-arg2");
27 TEST(ProgramTest, CreateProcessTrailingSlash) {
28 if (getenv("LLVM_PROGRAM_TEST_CHILD")) {
29 if (ProgramTestStringArg1 == "has\\\\ trailing\\" &&
30 ProgramTestStringArg2 == "has\\\\ trailing\\") {
31 exit(0); // Success! The arguments were passed and parsed.
36 // FIXME: Hardcoding argv0 here since I don't know a good cross-platform way
37 // to get it. Maybe ParseCommandLineOptions() should save it?
38 Path my_exe = Path::GetMainExecutable("SupportTests", &ProgramTestStringArg1);
39 const char *argv[] = {
41 "--gtest_filter=ProgramTest.CreateProcessTrailingSlashChild",
42 "-program-test-string-arg1", "has\\\\ trailing\\",
43 "-program-test-string-arg2", "has\\\\ trailing\\",
46 const char *envp[] = { "LLVM_PROGRAM_TEST_CHILD=1", 0 };
49 // Redirect stdout and stdin to NUL, but let stderr through.
53 Path nul("/dev/null");
55 const Path *redirects[] = { &nul, &nul, 0 };
56 int rc = Program::ExecuteAndWait(my_exe, argv, envp, redirects,
57 /*secondsToWait=*/10, /*memoryLimit=*/0,
58 &error, &ExecutionFailed);
59 EXPECT_FALSE(ExecutionFailed) << error;
63 } // end anonymous namespace