Skip to content

Commit 8748388

Browse files
squash this commit with the previous commit
fix ExternalInterpreterTest `Cpp::UseExternalInterpreter` expects `Cpp::Interpreter` (clang-repl) or `cling::Interpreter` (cling). Account for this and update the test to reflect the same.
1 parent cfb00a4 commit 8748388

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,7 @@ bool DeleteInterpreter(TInterp_t I /*=nullptr*/) {
34453445

34463446
if (!I) {
34473447
auto foundAST = find_interpreter_in_map(sInterpreters->back().get());
3448+
assert(foundAST != sInterpreterASTMap->end());
34483449
sInterpreterASTMap->erase(foundAST);
34493450
sInterpreters->pop_back();
34503451
return true;
@@ -3455,6 +3456,7 @@ bool DeleteInterpreter(TInterp_t I /*=nullptr*/) {
34553456
return false; // failure
34563457

34573458
auto foundAST = find_interpreter_in_map((*found).get());
3459+
assert(foundAST != sInterpreterASTMap->end());
34583460
sInterpreterASTMap->erase(foundAST);
34593461
sInterpreters->erase(found);
34603462
return true;

lib/CppInterOp/CppInterOpInterpreter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ namespace Cpp {
140140
/// CppInterOp Interpreter
141141
///
142142
class Interpreter {
143-
private:
144143
std::unique_ptr<clang::Interpreter> inner;
145144

145+
public:
146146
Interpreter(std::unique_ptr<clang::Interpreter> CI) : inner(std::move(CI)) {}
147147

148-
public:
149148
static std::unique_ptr<Interpreter>
150149
create(int argc, const char* const* argv, const char* llvmdir = nullptr,
151150
const std::vector<std::shared_ptr<clang::ModuleFileExtension>>&

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,9 @@ TEST(InterpreterTest, DeleteInterpreter) {
8888

8989
EXPECT_EQ(I3, Cpp::GetInterpreter()) << "I3 is not active";
9090

91-
auto* D1 = Cpp::TakeInterpreter();
92-
EXPECT_EQ(D1, I3);
93-
94-
Cpp::UseExternalInterpreter(D1);
95-
9691
EXPECT_TRUE(Cpp::DeleteInterpreter(nullptr));
9792
EXPECT_EQ(I2, Cpp::GetInterpreter());
9893

99-
auto* D2 = Cpp::TakeInterpreter(I2);
100-
EXPECT_EQ(I2, D2);
101-
102-
Cpp::UseExternalInterpreter(D2);
103-
10494
auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U));
10595
EXPECT_FALSE(Cpp::DeleteInterpreter(I4));
10696

@@ -341,7 +331,9 @@ if (llvm::sys::RunningOnValgrind())
341331
// Create the interpreter instance.
342332
std::unique_ptr<clang::Interpreter> I =
343333
ExitOnErr(clang::Interpreter::create(std::move(CI)));
344-
auto ExtInterp = I.get();
334+
335+
auto CPPI = Cpp::Interpreter(std::move(I));
336+
auto ExtInterp = &CPPI;
345337
#endif // CPPINTEROP_USE_REPL
346338

347339
#ifdef CPPINTEROP_USE_CLING
@@ -358,12 +350,9 @@ if (llvm::sys::RunningOnValgrind())
358350

359351
EXPECT_NE(ExtInterp, nullptr);
360352

361-
#if !defined(NDEBUG) && GTEST_HAS_DEATH_TEST
362-
#ifndef _WIN32 // Windows seems to fail to die...
363-
EXPECT_DEATH(Cpp::UseExternalInterpreter(ExtInterp), "sInterpreter already in use!");
364-
#endif // _WIN32
365-
#endif
366-
EXPECT_TRUE(Cpp::GetInterpreter()) << "External Interpreter not set";
353+
Cpp::UseExternalInterpreter(ExtInterp);
354+
EXPECT_EQ(ExtInterp, Cpp::GetInterpreter());
355+
EXPECT_EQ(ExtInterp, Cpp::TakeInterpreter(ExtInterp));
367356

368357
#ifndef CPPINTEROP_USE_CLING
369358
I.release();

0 commit comments

Comments
 (0)