Skip to content

Update tags definition, add tests for xinspect #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
set(XCPP_TAGFILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/xeus-cpp/tagfiles)

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"
"${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using target_compile_definition would be a better alternative than configuring hpp files from cmake.
However, let's merge it for now to have a reference to test against.


# 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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
59 changes: 58 additions & 1 deletion test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>

#include <iostream>
#include <pugixml.hpp>
#include <fstream>
#if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
#include <sys/wait.h>
Expand Down Expand Up @@ -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);
}
}