1 //===- unittests/Frontend/UtilsTest.cpp -----------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "clang/Frontend/Utils.h" 10 #include "clang/Basic/Diagnostic.h" 11 #include "clang/Basic/TargetOptions.h" 12 #include "clang/Frontend/CompilerInstance.h" 13 #include "clang/Frontend/CompilerInvocation.h" 14 #include "llvm/Support/VirtualFileSystem.h" 15 #include "gmock/gmock.h" 16 #include "gtest/gtest.h" 17 18 namespace clang { 19 namespace { 20 21 TEST(BuildCompilerInvocationTest, RecoverMultipleJobs) { 22 // This generates multiple jobs and we recover by using the first. 23 std::vector<const char *> Args = {"clang", "--target=macho", "-arch", "i386", 24 "-arch", "x86_64", "foo.cpp"}; 25 clang::IgnoringDiagConsumer D; 26 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> CommandLineDiagsEngine = 27 clang::CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, 28 false); 29 std::unique_ptr<CompilerInvocation> CI = createInvocationFromCommandLine( 30 Args, CommandLineDiagsEngine, new llvm::vfs::InMemoryFileSystem(), 31 /*ShouldRecoverOnErrors=*/true); 32 ASSERT_TRUE(CI); 33 EXPECT_THAT(CI->TargetOpts->Triple, testing::StartsWith("i386-")); 34 } 35 36 } // namespace 37 } // namespace clang 38