diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2020-12-08 12:29:14 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2020-12-09 08:58:46 +0100 |
commit | 35621cc2e3b3778abc2bacf37f3b1e9dfac52895 (patch) | |
tree | ecb50ac3981c80525b3c78afeb1c30f4b598a5ef /clang/unittests/Frontend/CompilerInvocationTest.cpp | |
parent | 216d43053b4e7327e5f9eb5705a7c8e4f6ae850b (diff) | |
download | llvm-35621cc2e3b3778abc2bacf37f3b1e9dfac52895.zip llvm-35621cc2e3b3778abc2bacf37f3b1e9dfac52895.tar.gz llvm-35621cc2e3b3778abc2bacf37f3b1e9dfac52895.tar.bz2 |
[clang][cli] CompilerInvocationTest: add tests for boolean options
Add more tests of the command line marshalling infrastructure.
The new tests now make a "round-trip": from arguments, to CompilerInvocation instance to arguments again in a single test case.
The TODOs are resolved in a follow-up patch.
Depends on D92830.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D92774
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r-- | clang/unittests/Frontend/CompilerInvocationTest.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index c3bdd6bf..b0fe11d 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -77,6 +77,150 @@ TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagUnknownPresent) { ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary); } +// Boolean option with a keypath that defaults to true. +// The flag with negative spelling can set the keypath to false. +// The flag with positive spelling can reset the keypath to true. + +TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNone) { + const char *Args[] = {""}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink); + + // TODO: Test argument generation. +} + +TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNegChange) { + const char *Args[] = {"-fno-autolink"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_FALSE(Invocation.getCodeGenOpts().Autolink); + + // TODO: Test argument generation. +} + +TEST_F(CommandLineTest, BoolOptionDefaultTruePresentPosReset) { + const char *Args[] = {"-fautolink"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag. + ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink); +} + +// Boolean option with a keypath that defaults to false. +// The flag with negative spelling can set the keypath to true. +// The flag with positive spelling can reset the keypath to false. + +TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNone) { + const char *Args[] = {""}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables); + + // TODO: Test argument generation. +} + +TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegChange) { + const char *Args[] = {"-gno-inline-line-tables"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getCodeGenOpts().NoInlineLineTables); + + // TODO: Test argument generation. +} + +TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosReset) { + const char *Args[] = {"-ginline-line-tables"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag. + ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables); +} + +// Boolean option with a keypath that defaults to false. +// The flag with positive spelling can set the keypath to true. +// The flag with negative spelling can reset the keypath to false. + +TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNoneX) { + const char *Args[] = {""}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash); + + // TODO: Test argument generation. +} + +TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosChange) { + const char *Args[] = {"-gcodeview-ghash"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getCodeGenOpts().CodeViewGHash); + + // TODO: Test argument generation. +} + +TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegReset) { + const char *Args[] = {"-gno-codeview-ghash"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag. + ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash); +} + +// Boolean option with a keypath that defaults to an arbitrary expression. +// The flag with positive spelling can set the keypath to true. +// The flag with negative spelling can set the keypath to false. + +// NOTE: The following tests need to be updated when we start enabling the new +// pass manager by default. + +TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentNone) { + const char *Args = {""}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_FALSE(Invocation.getCodeGenOpts().ExperimentalNewPassManager); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, + Not(Contains(StrEq("-fexperimental-new-pass-manager")))); +} + +TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentPos) { + const char *Args[] = {"-fexperimental-new-pass-manager"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getCodeGenOpts().ExperimentalNewPassManager); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, + Contains(StrEq("-fexperimental-new-pass-manager"))); + ASSERT_THAT(GeneratedArgs, + Not(Contains(StrEq("-fno-experimental-new-pass-manager")))); +} + +TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentNeg) { + const char *Args[] = {"-fno-experimental-new-pass-manager"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_FALSE(Invocation.getCodeGenOpts().ExperimentalNewPassManager); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, + Contains(StrEq("-fno-experimental-new-pass-manager"))); + ASSERT_THAT(GeneratedArgs, + Not(Contains(StrEq("-fexperimental-new-pass-manager")))); +} + TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) { const char *Args[] = {"-fmodules-strict-context-hash"}; |