From 63a24816f561a5d8e28ca7054892bd8602618be4 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Mon, 21 Dec 2020 14:28:09 +0100 Subject: [clang][cli] Implement `getAllArgValues` marshalling This infrastructure can be used ~30 more command line options. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D93631 --- .../unittests/Frontend/CompilerInvocationTest.cpp | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp') diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 71e8d09..5738f707 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -18,6 +18,7 @@ using namespace llvm; using namespace clang; using ::testing::Contains; +using ::testing::HasSubstr; using ::testing::StrEq; namespace { @@ -408,6 +409,45 @@ TEST_F(CommandLineTest, JoinedEnumDefault) { ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("legacy")))); } +TEST_F(CommandLineTest, StringVectorEmpty) { + const char *Args[] = {""}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles.empty()); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-fmodule-map-file=")))); +} + +TEST_F(CommandLineTest, StringVectorSingle) { + const char *Args[] = {"-fmodule-map-file=a"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getFrontendOpts().ModuleMapFiles, + std::vector({"a"})); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1); +} + +TEST_F(CommandLineTest, StringVectorMultiple) { + const char *Args[] = {"-fmodule-map-file=a", "-fmodule-map-file=b"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles == + std::vector({"a", "b"})); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1); + ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=b")), 1); +} + // Tree of boolean options that can be (directly or transitively) implied by // their parent: // -- cgit v1.1