1 | //=== unittests/Interpreter/IncrementalCompilerBuilderTest.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/Basic/TargetOptions.h" |
10 | #include "clang/Frontend/CompilerInstance.h" |
11 | #include "clang/Interpreter/Interpreter.h" |
12 | #include "clang/Lex/PreprocessorOptions.h" |
13 | #include "llvm/Support/Error.h" |
14 | #include "gtest/gtest.h" |
15 | |
16 | using namespace llvm; |
17 | using namespace clang; |
18 | |
19 | namespace { |
20 | |
21 | // Usually FrontendAction takes the raw pointers and wraps them back into |
22 | // unique_ptrs in InitializeFileRemapping() |
23 | static void cleanupRemappedFileBuffers(CompilerInstance &CI) { |
24 | for (const auto &RB : CI.getPreprocessorOpts().RemappedFileBuffers) { |
25 | delete RB.second; |
26 | } |
27 | CI.getPreprocessorOpts().clearRemappedFiles(); |
28 | } |
29 | |
30 | TEST(IncrementalCompilerBuilder, SetCompilerArgs) { |
31 | std::vector<const char *> ClangArgv = {"-Xclang", "-ast-dump-all"}; |
32 | auto CB = clang::IncrementalCompilerBuilder(); |
33 | CB.SetCompilerArgs(ClangArgv); |
34 | auto CI = cantFail(ValOrErr: CB.CreateCpp()); |
35 | EXPECT_TRUE(CI->getFrontendOpts().ASTDumpAll); |
36 | cleanupRemappedFileBuffers(CI&: *CI); |
37 | } |
38 | |
39 | TEST(IncrementalCompilerBuilder, SetTargetTriple) { |
40 | auto CB = clang::IncrementalCompilerBuilder(); |
41 | CB.SetTargetTriple("armv6-none-eabi"); |
42 | auto CI = cantFail(ValOrErr: CB.CreateCpp()); |
43 | EXPECT_EQ(CI->getTargetOpts().Triple, "armv6-none-unknown-eabi"); |
44 | cleanupRemappedFileBuffers(CI&: *CI); |
45 | } |
46 | |
47 | } // end anonymous namespace |
48 |