Skip to content

Commit 41e52c5

Browse files
committed
Implement GetVersion.
1 parent 645a034 commit 41e52c5

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ namespace Cpp {
117117
}
118118
};
119119

120+
///\returns the version string information of the library.
121+
std::string GetVersion();
122+
120123
/// Enables or disables the debugging printouts on stderr.
121124
/// Debugging output can be enabled also by the environment variable
122125
/// CPPINTEROP_EXTRA_INTERPRETER_ARGS. For example,

lib/Interpreter/CppInterOp.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ namespace Cpp {
115115

116116
#undef DEBUG_TYPE
117117

118+
std::string GetVersion() {
119+
const char* const VERSION = "1.0~dev";
120+
std::string fullVersion = "CppInterOp version";
121+
fullVersion += VERSION;
122+
fullVersion += "\n (based on "
123+
#ifdef USE_CLING
124+
"cling ";
125+
#else
126+
"clang-repl";
127+
#endif // USE_CLING
128+
return fullVersion + "[" + clang::getClangFullVersion() + "])\n";
129+
}
130+
118131
void EnableDebugOutput(bool value/* =true*/) {
119132
llvm::DebugFlag = value;
120133
}

unittests/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ if (NOT TARGET gtest)
77
include(GoogleTest)
88
endif()
99

10+
set(gtest_libs gtest gtest_main)
11+
# Clang prior than clang13 (I think) merges both gmock into gtest.
12+
if (TARGET gmock)
13+
list(APPEND gtest_libs gmock gmock_main)
14+
endif()
15+
1016
add_custom_target(CppInterOpUnitTests)
1117
set_target_properties(CppInterOpUnitTests PROPERTIES FOLDER "CppInterOp tests")
1218
add_dependencies(CppInterOpUnitTests clangCppInterOp)
@@ -18,7 +24,7 @@ function(add_cppinterop_unittest name)
1824
target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${GTEST_INCLUDE_DIR})
1925
set_property(TARGET ${name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
2026

21-
target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} gtest gtest_main pthread)
27+
target_link_libraries(${name} PUBLIC ${ARG_LIBRARIES} ${gtest_libs} pthread)
2228

2329
add_test(NAME cppinterop-${name} COMMAND ${name})
2430
set_tests_properties(cppinterop-${name} PROPERTIES

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#include "clang/Interpreter/CppInterOp.h"
22

3+
#include <gmock/gmock.h>
34
#include "gtest/gtest.h"
45

6+
using ::testing::StartsWith;
7+
8+
TEST(InterpreterTest, Version) {
9+
EXPECT_THAT(Cpp::GetVersion(), StartsWith("CppInterOp version"));
10+
}
11+
512
TEST(InterpreterTest, DebugFlag) {
613
EXPECT_FALSE(Cpp::IsDebugOutputEnabled());
714
std::string cerrs;

0 commit comments

Comments
 (0)