diff options
author | Shoaib Meenai <smeenai@fb.com> | 2019-04-16 00:18:47 +0000 |
---|---|---|
committer | Shoaib Meenai <smeenai@fb.com> | 2019-04-16 00:18:47 +0000 |
commit | 0a61be96fc9f10f400497e98f5adb9cc467c98c6 (patch) | |
tree | 7d2ce0830302fb188319ed2c8dfb1ea06bbc9324 /llvm/unittests/Support/CommandLineTest.cpp | |
parent | b068f92d94a5c42ff21bfdf29344c54e2688dac3 (diff) | |
download | llvm-0a61be96fc9f10f400497e98f5adb9cc467c98c6.zip llvm-0a61be96fc9f10f400497e98f5adb9cc467c98c6.tar.gz llvm-0a61be96fc9f10f400497e98f5adb9cc467c98c6.tar.bz2 |
Reapply [Support] Add a test for recursive response file expansion
Use the appropriate tokenizer to fix the test on Windows.
Original commit message:
I'm going to be modifying the logic to avoid infinitely recursing on
self-referential response files, so add a unit test to verify the
expected behavior.
Differential Revision: https://reviews.llvm.org/D60630
> llvm-svn: 358451
llvm-svn: 358465
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r-- | llvm/unittests/Support/CommandLineTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index fcbfd33..263d0e3 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -782,6 +782,40 @@ TEST(CommandLineTest, ResponseFiles) { llvm::sys::fs::remove(TestDir); } +TEST(CommandLineTest, RecursiveResponseFiles) { + SmallString<128> TestDir; + std::error_code EC = sys::fs::createUniqueDirectory("unittest", TestDir); + EXPECT_TRUE(!EC); + + SmallString<128> ResponseFilePath; + sys::path::append(ResponseFilePath, TestDir, "recursive.rsp"); + std::string ResponseFileRef = std::string("@") + ResponseFilePath.c_str(); + + std::ofstream ResponseFile(ResponseFilePath.str()); + EXPECT_TRUE(ResponseFile.is_open()); + ResponseFile << ResponseFileRef << "\n"; + ResponseFile << ResponseFileRef << "\n"; + ResponseFile.close(); + + // Ensure the recursive expansion terminates. + SmallVector<const char *, 4> Argv = {"test/test", ResponseFileRef.c_str()}; + BumpPtrAllocator A; + StringSaver Saver(A); +#ifdef _WIN32 + cl::TokenizerCallback Tokenizer = cl::TokenizeWindowsCommandLine; +#else + cl::TokenizerCallback Tokenizer = cl::TokenizeGNUCommandLine; +#endif + bool Res = cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false); + EXPECT_FALSE(Res); + + // Ensure some expansion took place. + EXPECT_GT(Argv.size(), 2U); + EXPECT_STREQ(Argv[0], "test/test"); + for (size_t i = 1; i < Argv.size(); ++i) + EXPECT_STREQ(Argv[i], ResponseFileRef.c_str()); +} + TEST(CommandLineTest, SetDefautValue) { cl::ResetCommandLineParser(); |