diff --git a/unittests/CppInterOp/InterpreterTest.cpp b/unittests/CppInterOp/InterpreterTest.cpp index 9b70b8a4..9def9467 100644 --- a/unittests/CppInterOp/InterpreterTest.cpp +++ b/unittests/CppInterOp/InterpreterTest.cpp @@ -1,6 +1,16 @@ + #include "Utils.h" #include "clang/Interpreter/CppInterOp.h" + +#ifdef USE_CLING +#include "cling/Interpreter/Interpreter.h" +#endif // USE_CLING + +#ifdef USE_REPL +#include "clang/Interpreter/Interpreter.h" +#endif // USE_REPL + #include "clang/Basic/Version.h" #include "llvm/ADT/SmallString.h" @@ -162,3 +172,35 @@ TEST(InterpreterTest, CodeCompletion) { GTEST_SKIP(); #endif } + +TEST(InterpreterTest, ExternalInterpreterTest) { + +#ifdef USE_REPL + llvm::ExitOnError ExitOnErr; + clang::IncrementalCompilerBuilder CB; + CB.SetCompilerArgs({"-std=c++20"}); + + // Create the incremental compiler instance. + std::unique_ptr CI; + CI = ExitOnErr(CB.CreateCpp()); + + // Create the interpreter instance. + std::unique_ptr I = + ExitOnErr(clang::Interpreter::create(std::move(CI))); +#endif + +#ifdef USE_CLING + std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr); + std::string ResourceDir = compat::MakeResourceDir(LLVM_BINARY_DIR); + std::vector ClingArgv = {"-resource-dir", ResourceDir.c_str(), + "-std=c++14"}; + ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str()); + std::unique_ptr I(ClingArgv.size(), &ClingArgv[0]); +#endif + + auto ExtInterp = I.get(); + EXPECT_NE(ExtInterp, nullptr); + Cpp::UseExternalInterpreter(ExtInterp); + EXPECT_FALSE(Cpp::OwnsInterpreter()); + I.release(); +}