From a828fb463ed9f6085849bb3a4f225b3c84e7cf29 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Mon, 21 Dec 2020 16:35:32 +0100 Subject: [clang][cli] Port a CommaJoined option to the marshalling infrastructure Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D93698 --- .../unittests/Frontend/CompilerInvocationTest.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp') diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 8fcf34d..7b8efb9 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -508,6 +508,53 @@ TEST_F(CommandLineTest, StringVectorMultiple) { ASSERT_THAT(GeneratedArgs, ContainsN(HasSubstr("-fmodule-map-file"), 2)); } +// CommaJoined option with MarshallingInfoStringVector. + +TEST_F(CommandLineTest, StringVectorCommaJoinedNone) { + const char *Args[] = {""}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getLangOpts()->CommentOpts.BlockCommandNames.empty()); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + + ASSERT_THAT(GeneratedArgs, + Not(Contains(HasSubstr("-fcomment-block-commands")))); +} + +TEST_F(CommandLineTest, StringVectorCommaJoinedSingle) { + const char *Args[] = {"-fcomment-block-commands=x,y"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getLangOpts()->CommentOpts.BlockCommandNames, + std::vector({"x", "y"})); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + + ASSERT_THAT(GeneratedArgs, + ContainsN(StrEq("-fcomment-block-commands=x,y"), 1)); +} + +TEST_F(CommandLineTest, StringVectorCommaJoinedMultiple) { + const char *Args[] = {"-fcomment-block-commands=x,y", + "-fcomment-block-commands=a,b"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getLangOpts()->CommentOpts.BlockCommandNames, + std::vector({"x", "y", "a", "b"})); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + + ASSERT_THAT(GeneratedArgs, + ContainsN(StrEq("-fcomment-block-commands=x,y,a,b"), 1)); +} + // A flag that should be parsed only if a condition is met. TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagNotPresent) { -- cgit v1.1