From 856ad86775fcce1bb82fa7aabc80da30ddbd6509 Mon Sep 17 00:00:00 2001 From: tharun571 Date: Tue, 4 Jun 2024 23:33:03 +0530 Subject: [PATCH 1/2] Update tags, add tests for xinspect, add label --- CMakeLists.txt | 42 ++++++------- ..._cpp_config.hpp => xeus_cpp_config.hpp.in} | 4 ++ src/xinterpreter.cpp | 1 - test/test_interpreter.cpp | 59 ++++++++++++++++++- 4 files changed, 81 insertions(+), 25 deletions(-) rename include/xeus-cpp/{xeus_cpp_config.hpp => xeus_cpp_config.hpp.in} (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 251379af..d4ec6915 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,18 +23,28 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") set(XEUS_CPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) +# xeus-cpp tag files +set(XEUS_CPP_DATA_DIR "share/xeus-cpp" CACHE STRING "xeus-cpp data directory") +set(XCPP_TAGFILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/xeus-cpp/tagfiles) + +set(XEUS_CPP_CONF_DIR "etc/xeus-cpp" CACHE STRING "xeus-cpp configuration directory") +set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d) + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp.in" + "${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp") + # Versionning # =========== file(STRINGS "${XEUS_CPP_INCLUDE_DIR}/xeus-cpp/xeus_cpp_config.hpp" version_defines - REGEX "#define XEUS_CPP_VERSION_(MAJOR|MINOR|PATCH)") + REGEX "#define XEUS_CPP_VERSION_(MAJOR|MINOR|PATCH|LABEL)") foreach (ver ${version_defines}) - if (ver MATCHES "#define XEUS_CPP_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") + if (ver MATCHES "#define XEUS_CPP_VERSION_(MAJOR|MINOR|PATCH|LABEL) +([^ ]+)$") set(XEUS_CPP_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") endif () endforeach () set(${PROJECT_NAME}_VERSION - ${XEUS_CPP_VERSION_MAJOR}.${XEUS_CPP_VERSION_MINOR}.${XEUS_CPP_VERSION_PATCH}) + ${XEUS_CPP_VERSION_MAJOR}.${XEUS_CPP_VERSION_MINOR}.${XEUS_CPP_VERSION_PATCH}${XEUS_CPP_VERSION_LABEL}) message(STATUS "Building xeus-cpp v${${PROJECT_NAME}_VERSION}") # Build options @@ -383,6 +393,12 @@ include(CMakePackageConfigHelpers) set(XEUS_CPP_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xeus-cppConfig.cmake") +install(DIRECTORY ${XCPP_TAGFILES_DIR} + DESTINATION ${XEUS_CPP_DATA_DIR}) + +install(DIRECTORY ${XCPP_TAGCONFS_DIR} + DESTINATION ${XEUS_CPP_CONF_DIR}) + # Install xeus-cpp and xeus-cpp-static if (XEUS_CPP_BUILD_SHARED) install(TARGETS ${XEUS_CPP_TARGETS} @@ -430,26 +446,6 @@ configure_package_config_file(${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${PROJECT_BINARY_DIR}) -# Install xeus-cpp tag files -set(XEUS_CPP_DATA_DIR "share/xeus-cpp" CACHE STRING "xeus-cpp data directory") -set(XCPP_TAGFILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/xeus-cpp/tagfiles) -install(DIRECTORY ${XCPP_TAGFILES_DIR} - DESTINATION ${XEUS_CPP_DATA_DIR}) - -set(XEUS_CPP_CONF_DIR "etc/xeus-cpp" CACHE STRING "xeus-cpp configuration directory") -set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d) -install(DIRECTORY ${XCPP_TAGCONFS_DIR} - DESTINATION ${XEUS_CPP_CONF_DIR}) - -# Add definitions for the kernel to find tagfiles. -add_definitions(-DXCPP_TAGFILES_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CPP_DATA_DIR}/tagfiles") -if(CMAKE_INSTALL_PREFIX STREQUAL "/usr") - # install into /etc instead of /usr/etc - add_definitions(-DXCPP_TAGCONFS_DIR="/${XEUS_CPP_CONF_DIR}/tags.d") -else() - add_definitions(-DXCPP_TAGCONFS_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CPP_CONF_DIR}/tags.d") -endif() - # Configure 'xeus-cppConfig.cmake.in for an install tree set(XEUS_CPP_CONFIG_CODE "") configure_package_config_file(${PROJECT_NAME}Config.cmake.in diff --git a/include/xeus-cpp/xeus_cpp_config.hpp b/include/xeus-cpp/xeus_cpp_config.hpp.in similarity index 93% rename from include/xeus-cpp/xeus_cpp_config.hpp rename to include/xeus-cpp/xeus_cpp_config.hpp.in index 5dd2c3b6..d05f51ea 100644 --- a/include/xeus-cpp/xeus_cpp_config.hpp +++ b/include/xeus-cpp/xeus_cpp_config.hpp.in @@ -13,6 +13,10 @@ #define XEUS_CPP_VERSION_MAJOR 0 #define XEUS_CPP_VERSION_MINOR 5 #define XEUS_CPP_VERSION_PATCH 0 +#define XEUS_CPP_VERSION_LABEL dev + +#define XCPP_TAGFILES_DIR "@XCPP_TAGFILES_DIR@" +#define XCPP_TAGCONFS_DIR "@XCPP_TAGCONFS_DIR@" // Composing the version string from major, minor and patch #define XEUS_CPP_CONCATENATE(A, B) XEUS_CPP_CONCATENATE_IMPL(A, B) diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index e7dd2963..121b90a6 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -22,7 +22,6 @@ #include "xeus-cpp/xbuffer.hpp" #include "xeus-cpp/xeus_cpp_config.hpp" - #include "xeus-cpp/xinterpreter.hpp" #include "xeus-cpp/xmagics.hpp" diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index 26d5484e..a53a9042 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -14,13 +14,16 @@ #include "xeus-cpp/xmanager.hpp" #include "xeus-cpp/xutils.hpp" #include "xeus-cpp/xoptions.hpp" +#include "xeus-cpp/xeus_cpp_config.hpp" #include "../src/xparser.hpp" #include "../src/xsystem.hpp" #include "../src/xmagics/os.hpp" +#include "../src/xinspect.hpp" -#include +#include +#include #include #if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD) #include @@ -830,4 +833,58 @@ TEST_SUITE("complete_request") } REQUIRE(found == 2); } +} + +TEST_SUITE("xinspect"){ + TEST_CASE("class_member_predicate_get_filename"){ + xcpp::class_member_predicate cmp; + cmp.class_name = "TestClass"; + cmp.kind = "public"; + cmp.child_value = "testMethod"; + + pugi::xml_document doc; + pugi::xml_node node = doc.append_child("node"); + node.append_attribute("kind") = "class"; + pugi::xml_node name = node.append_child("name"); + name.append_child(pugi::node_pcdata).set_value("TestClass"); + pugi::xml_node child = node.append_child("node"); + child.append_attribute("kind") = "public"; + pugi::xml_node child_name = child.append_child("name"); + child_name.append_child(pugi::node_pcdata).set_value("testMethod"); + pugi::xml_node anchorfile = child.append_child("anchorfile"); + anchorfile.append_child(pugi::node_pcdata).set_value("testfile.cpp"); + + REQUIRE(cmp.get_filename(node) == "testfile.cpp"); + + cmp.child_value = "nonexistentMethod"; + REQUIRE(cmp.get_filename(node) == ""); + } + + TEST_CASE("class_member_predicate_operator"){ + xcpp::class_member_predicate cmp; + cmp.class_name = "TestClass"; + cmp.kind = "public"; + cmp.child_value = "testMethod"; + + pugi::xml_document doc; + pugi::xml_node node = doc.append_child("node"); + node.append_attribute("kind") = "class"; + pugi::xml_node name = node.append_child("name"); + name.append_child(pugi::node_pcdata).set_value("TestClass"); + pugi::xml_node child = node.append_child("node"); + child.append_attribute("kind") = "public"; + pugi::xml_node child_name = child.append_child("name"); + child_name.append_child(pugi::node_pcdata).set_value("testMethod"); + + + REQUIRE(cmp(node) == true); + node.attribute("kind").set_value("struct"); + REQUIRE(cmp(node) == true); + cmp.class_name = "NonexistentClass"; + REQUIRE(cmp(node) == false); + cmp.kind = "private"; + REQUIRE(cmp(node) == false); + cmp.child_value = "nonexistentMethod"; + REQUIRE(cmp(node) == false); + } } \ No newline at end of file From 469be108c79105ec900887f8bfe6dbd3f4b08203 Mon Sep 17 00:00:00 2001 From: tharun571 Date: Wed, 5 Jun 2024 11:00:25 +0530 Subject: [PATCH 2/2] Update cmake --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4ec6915..841dfdab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,10 +24,10 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") set(XEUS_CPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) # xeus-cpp tag files -set(XEUS_CPP_DATA_DIR "share/xeus-cpp" CACHE STRING "xeus-cpp data directory") +set(XEUS_CPP_DATA_DIR "share/xeus-cpp") set(XCPP_TAGFILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/xeus-cpp/tagfiles) -set(XEUS_CPP_CONF_DIR "etc/xeus-cpp" CACHE STRING "xeus-cpp configuration directory") +set(XEUS_CPP_CONF_DIR "etc/xeus-cpp") set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp.in"