@@ -76,16 +76,21 @@ TEST(InterpreterTest, Evaluate) {
7676 GTEST_SKIP () << " Test fails for OOP JIT builds" ;
7777 }
7878 // EXPECT_TRUE(Cpp::Evaluate(I, "") == 0);
79- // EXPECT_TRUE(Cpp::Evaluate(I, "__cplusplus;") == 201402);
79+ // EXPECT_TRUE(Cpp::Evaluate(I, "__cplusplus;") == 201402);
8080 // Due to a deficiency in the clang-repl implementation to get the value we
8181 // always must omit the ;
82+
83+ // this needs to be added because TestUtils::CreateInterpreter creates
84+ // Cpp::CreateInterpreter. But, the later goes out of scope(destroyed) at the
85+ // end of every test due to TestUtils::CreateInterpreter.
86+ TestUtils::CreateInterpreter ();
8287 EXPECT_TRUE (Cpp::Evaluate (" __cplusplus" ) == 201402 );
8388
8489 bool HadError;
8590 EXPECT_TRUE (Cpp::Evaluate (" #error" , &HadError) == (intptr_t )~0UL );
8691 EXPECT_TRUE (HadError);
8792 EXPECT_EQ (Cpp::Evaluate (" int i = 11; ++i" , &HadError), 12 );
88- EXPECT_FALSE (HadError) ;
93+ EXPECT_FALSE (HadError);
8994}
9095
9196TEST (InterpreterTest, DeleteInterpreter) {
@@ -147,7 +152,7 @@ TEST(InterpreterTest, Process) {
147152#endif
148153 if (llvm::sys::RunningOnValgrind ())
149154 GTEST_SKIP () << " XFAIL due to Valgrind report" ;
150- std::vector<const char *> interpreter_args = { " -include" , " new" };
155+ std::vector<const char *> interpreter_args = {" -include" , " new" };
151156 auto * I = TestUtils::CreateInterpreter (interpreter_args);
152157 EXPECT_TRUE (Cpp::Process (" " ) == 0 );
153158 EXPECT_TRUE (Cpp::Process (" int a = 12;" ) == 0 );
@@ -172,20 +177,18 @@ TEST(InterpreterTest, Process) {
172177
173178TEST (InterpreterTest, EmscriptenExceptionHandling) {
174179#ifndef EMSCRIPTEN
175- GTEST_SKIP () << " This test is intended to check exception handling for Emscripten builds." ;
180+ GTEST_SKIP () << " This test is intended to check exception handling for "
181+ " Emscripten builds." ;
176182#endif
177183 if (TestUtils::use_oop_jit ()) {
178184 GTEST_SKIP () << " Test fails for OOP JIT builds" ;
179185 }
180186
181187 std::vector<const char *> Args = {
182- " -std=c++20" ,
183- " -v" ,
184- " -fexceptions" ,
185- " -fcxx-exceptions" ,
186- " -mllvm" , " -enable-emscripten-cxx-exceptions" ,
187- " -mllvm" , " -enable-emscripten-sjlj"
188- };
188+ " -std=c++20" , " -v" ,
189+ " -fexceptions" , " -fcxx-exceptions" ,
190+ " -mllvm" , " -enable-emscripten-cxx-exceptions" ,
191+ " -mllvm" , " -enable-emscripten-sjlj" };
189192
190193 TestUtils::CreateInterpreter (Args);
191194
@@ -206,23 +209,22 @@ TEST(InterpreterTest, CreateInterpreter) {
206209 // Check if the default standard is c++14
207210
208211 Cpp::Declare (" #if __cplusplus==201402L\n "
209- " int cpp14() { return 2014; }\n "
210- " #else\n "
211- " void cppUnknown() {}\n "
212- " #endif" );
212+ " int cpp14() { return 2014; }\n "
213+ " #else\n "
214+ " void cppUnknown() {}\n "
215+ " #endif" );
213216 EXPECT_TRUE (Cpp::GetNamed (" cpp14" ));
214217 EXPECT_FALSE (Cpp::GetNamed (" cppUnknown" ));
215218
216219 I = TestUtils::CreateInterpreter ({" -std=c++17" });
217220 Cpp::Declare (" #if __cplusplus==201703L\n "
218- " int cpp17() { return 2017; }\n "
219- " #else\n "
220- " void cppUnknown() {}\n "
221- " #endif" );
221+ " int cpp17() { return 2017; }\n "
222+ " #else\n "
223+ " void cppUnknown() {}\n "
224+ " #endif" );
222225 EXPECT_TRUE (Cpp::GetNamed (" cpp17" ));
223226 EXPECT_FALSE (Cpp::GetNamed (" cppUnknown" ));
224227
225-
226228#ifndef CPPINTEROP_USE_CLING
227229 // C API
228230 auto * CXI = clang_createInterpreterFromRawPtr (I);
@@ -238,7 +240,7 @@ TEST(InterpreterTest, CreateInterpreter) {
238240#ifndef CPPINTEROP_USE_CLING
239241TEST (InterpreterTest, CreateInterpreterCAPI) {
240242 const char * argv[] = {" -std=c++17" };
241- auto * CXI = clang_createInterpreter (argv, 1 );
243+ auto * CXI = clang_createInterpreter (argv, 1 );
242244 auto CLI = clang_Interpreter_getClangInterpreter (CXI);
243245 EXPECT_TRUE (CLI);
244246 clang_Interpreter_dispose (CXI);
@@ -249,7 +251,7 @@ TEST(InterpreterTest, CreateInterpreterCAPIFailure) {
249251 GTEST_SKIP () << " Disabled on Windows. Needs fixing." ;
250252#endif
251253 const char * argv[] = {" -fsyntax-only" , " -Xclang" , " -invalid-plugin" };
252- auto * CXI = clang_createInterpreter (argv, 3 );
254+ auto * CXI = clang_createInterpreter (argv, 3 );
253255 EXPECT_EQ (CXI, nullptr );
254256}
255257#endif
@@ -313,7 +315,7 @@ TEST(InterpreterTest, IncludePaths) {
313315 Cpp::AddIncludePath (" /non/existent/" );
314316 Cpp::GetIncludePaths (includes);
315317 EXPECT_NE (std::find (includes.begin (), includes.end (), " /non/existent/" ),
316- std::end (includes));
318+ std::end (includes));
317319}
318320
319321TEST (InterpreterTest, CodeCompletion) {
@@ -338,8 +340,8 @@ TEST(InterpreterTest, CodeCompletion) {
338340
339341TEST (InterpreterTest, ExternalInterpreterTest) {
340342
341- if (llvm::sys::RunningOnValgrind ())
342- GTEST_SKIP () << " XFAIL due to Valgrind report" ;
343+ if (llvm::sys::RunningOnValgrind ())
344+ GTEST_SKIP () << " XFAIL due to Valgrind report" ;
343345
344346#ifndef CPPINTEROP_USE_CLING
345347 llvm::ExitOnError ExitOnErr;
@@ -359,15 +361,15 @@ if (llvm::sys::RunningOnValgrind())
359361#endif // CPPINTEROP_USE_REPL
360362
361363#ifdef CPPINTEROP_USE_CLING
362- std::string MainExecutableName = sys::fs::getMainExecutable (nullptr , nullptr );
363- llvm::SmallString<128 > P (LLVM_BINARY_DIR);
364- llvm::sys::path::append (P, CLANG_INSTALL_LIBDIR_BASENAME, " clang" ,
365- CLANG_VERSION_MAJOR_STRING);
366- std::string ResourceDir = std::string (P.str ());
367- std::vector<const char *> ClingArgv = {" -resource-dir" , ResourceDir.c_str (),
368- " -std=c++14" };
369- ClingArgv.insert (ClingArgv.begin (), MainExecutableName.c_str ());
370- auto * ExtInterp = new compat::Interpreter (ClingArgv.size (), &ClingArgv[0 ]);
364+ std::string MainExecutableName = sys::fs::getMainExecutable (nullptr , nullptr );
365+ llvm::SmallString<128 > P (LLVM_BINARY_DIR);
366+ llvm::sys::path::append (P, CLANG_INSTALL_LIBDIR_BASENAME, " clang" ,
367+ CLANG_VERSION_MAJOR_STRING);
368+ std::string ResourceDir = std::string (P.str ());
369+ std::vector<const char *> ClingArgv = {" -resource-dir" , ResourceDir.c_str (),
370+ " -std=c++14" };
371+ ClingArgv.insert (ClingArgv.begin (), MainExecutableName.c_str ());
372+ auto * ExtInterp = new compat::Interpreter (ClingArgv.size (), &ClingArgv[0 ]);
371373#endif
372374
373375 EXPECT_NE (ExtInterp, nullptr );
0 commit comments