Skip to content

Commit 11fea7d

Browse files
committed
Improve the test coverage of the C API -- Take 5
1 parent 0333803 commit 11fea7d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,26 @@ TEST(InterpreterTest, Process) {
8282
#endif
8383
if (llvm::sys::RunningOnValgrind())
8484
GTEST_SKIP() << "XFAIL due to Valgrind report";
85-
Cpp::CreateInterpreter();
85+
auto* I = Cpp::CreateInterpreter();
8686
EXPECT_TRUE(Cpp::Process("") == 0);
8787
EXPECT_TRUE(Cpp::Process("int a = 12;") == 0);
8888
EXPECT_FALSE(Cpp::Process("error_here;") == 0);
8989
// Linker/JIT error.
9090
EXPECT_FALSE(Cpp::Process("int f(); int res = f();") == 0);
91+
92+
// C API
93+
auto CXI = clang_createInterpreterFromRawPtr(I);
94+
clang_Interpreter_declare(CXI, "#include <iostream>", false);
95+
clang_Interpreter_process(CXI, "int c = 42;");
96+
auto* CXV = clang_createValue();
97+
auto Res = clang_Interpreter_evaluate(CXI, "c", CXV);
98+
EXPECT_EQ(Res, CXError_Success);
99+
clang_Value_dispose(CXV);
100+
clang_Interpreter_dispose(CXI);
91101
}
92102

93103
TEST(InterpreterTest, CreateInterpreter) {
94-
auto I = Cpp::CreateInterpreter();
104+
auto* I = Cpp::CreateInterpreter();
95105
EXPECT_TRUE(I);
96106
// Check if the default standard is c++14
97107

@@ -121,13 +131,6 @@ TEST(InterpreterTest, CreateInterpreter) {
121131

122132
clang_Interpreter_addSearchPath(CXI, "dummy", false, false);
123133
clang_Interpreter_addIncludePath(CXI, "dummy");
124-
clang_Interpreter_declare(CXI, "#include <iostream>", false);
125-
clang_Interpreter_process(CXI, "int c = 42;");
126-
auto* CXV = clang_createValue();
127-
auto Res = clang_Interpreter_evaluate(CXI, "c", CXV);
128-
EXPECT_EQ(Res, CXError_Success);
129-
130-
clang_Value_dispose(CXV);
131134
auto I2 = clang_Interpreter_takeInterpreterAsPtr(CXI);
132135
EXPECT_EQ(I, I2);
133136
clang_Interpreter_dispose(CXI);

0 commit comments

Comments
 (0)