|
| 1 | + |
1 | 2 | #include "Utils.h" |
2 | 3 |
|
3 | 4 | #include "clang/Interpreter/CppInterOp.h" |
| 5 | + |
| 6 | +#ifdef USE_CLING |
| 7 | +#include "cling/Interpreter/Interpreter.h" |
| 8 | +#endif // USE_CLING |
| 9 | + |
| 10 | +#ifdef USE_REPL |
| 11 | +#include "clang/Interpreter/Interpreter.h" |
| 12 | +#endif // USE_REPL |
| 13 | + |
4 | 14 | #include "clang/Basic/Version.h" |
5 | 15 |
|
6 | 16 | #include "llvm/ADT/SmallString.h" |
@@ -162,3 +172,37 @@ TEST(InterpreterTest, CodeCompletion) { |
162 | 172 | GTEST_SKIP(); |
163 | 173 | #endif |
164 | 174 | } |
| 175 | + |
| 176 | +TEST(InterpreterTest, ExternalInterpreterTest) { |
| 177 | + |
| 178 | +#ifdef USE_REPL |
| 179 | + llvm::ExitOnError ExitOnErr; |
| 180 | + clang::IncrementalCompilerBuilder CB; |
| 181 | + CB.SetCompilerArgs({"-std=c++20"}); |
| 182 | + |
| 183 | + // Create the incremental compiler instance. |
| 184 | + std::unique_ptr<clang::CompilerInstance> CI; |
| 185 | + CI = ExitOnErr(CB.CreateCpp()); |
| 186 | + |
| 187 | + // Create the interpreter instance. |
| 188 | + std::unique_ptr<clang::Interpreter> I = |
| 189 | + ExitOnErr(clang::Interpreter::create(std::move(CI))); |
| 190 | + auto ExtInterp = I.get(); |
| 191 | +#endif |
| 192 | + |
| 193 | +#ifdef USE_CLING |
| 194 | + std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); |
| 195 | + std::string ResourceDir = compat::MakeResourceDir(LLVM_BINARY_DIR); |
| 196 | + std::vector<const char *> ClingArgv = {"-resource-dir", ResourceDir.c_str(), |
| 197 | + "-std=c++14"}; |
| 198 | + ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str()); |
| 199 | + auto *I = new compat::Interpreter(ClingArgv.size(), &ClingArgv[0]); |
| 200 | + auto ExtInterp = I.get(); |
| 201 | +#endif |
| 202 | + |
| 203 | + EXPECT_NE(ExtInterp, nullptr); |
| 204 | + Cpp::UseExternalInterpreter(ExtInterp); |
| 205 | + EXPECT_FALSE(Cpp::OwnsInterpreter()); |
| 206 | + assert(Cpp::GetInterpreter() && "External Interpreter not set"); |
| 207 | + I.release(); |
| 208 | +} |
0 commit comments