[llvm] r358451 - [Support] Add a test for recursive response file expansion
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 14:31:25 PDT 2019
Author: smeenai
Date: Mon Apr 15 14:31:25 2019
New Revision: 358451
URL: http://llvm.org/viewvc/llvm-project?rev=358451&view=rev
Log:
[Support] Add a test for recursive response file expansion
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
Modified:
llvm/trunk/unittests/Support/CommandLineTest.cpp
Modified: llvm/trunk/unittests/Support/CommandLineTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CommandLineTest.cpp?rev=358451&r1=358450&r2=358451&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/CommandLineTest.cpp (original)
+++ llvm/trunk/unittests/Support/CommandLineTest.cpp Mon Apr 15 14:31:25 2019
@@ -782,6 +782,37 @@ 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.
+ llvm::SmallVector<const char *, 4> Argv = {"test/test",
+ ResponseFileRef.c_str()};
+ llvm::BumpPtrAllocator A;
+ llvm::StringSaver Saver(A);
+ bool Res = llvm::cl::ExpandResponseFiles(
+ Saver, llvm::cl::TokenizeGNUCommandLine, 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();
More information about the llvm-commits
mailing list