Skip to content

Commit 28d397a

Browse files
committed
Update tags definition, add tests for xmanager, xinspect
1 parent 33ad76a commit 28d397a

File tree

4 files changed

+105
-21
lines changed

4 files changed

+105
-21
lines changed

CMakeLists.txt

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
2323

2424
set(XEUS_CPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
2525

26+
# Install xeus-cpp tag files
27+
set(XEUS_CPP_DATA_DIR "share/xeus-cpp" CACHE STRING "xeus-cpp data directory")
28+
set(XCPP_TAGFILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/xeus-cpp/tagfiles)
29+
install(DIRECTORY ${XCPP_TAGFILES_DIR}
30+
DESTINATION ${XEUS_CPP_DATA_DIR})
31+
32+
set(XEUS_CPP_CONF_DIR "etc/xeus-cpp" CACHE STRING "xeus-cpp configuration directory")
33+
set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d)
34+
install(DIRECTORY ${XCPP_TAGCONFS_DIR}
35+
DESTINATION ${XEUS_CPP_CONF_DIR})
36+
2637
# Versionning
2738
# ===========
2839

@@ -169,6 +180,10 @@ configure_kernel("/share/jupyter/kernels/xcpp14/")
169180
configure_kernel("/share/jupyter/kernels/xcpp17/")
170181
configure_kernel("/share/jupyter/kernels/xcpp20/")
171182

183+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_tags_config.hpp.in"
184+
"${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_tags_config.hpp")
185+
186+
172187
# Source files
173188
# ============
174189

@@ -183,6 +198,7 @@ set(XEUS_CPP_HEADERS
183198
include/xeus-cpp/xmagics.hpp
184199
include/xeus-cpp/xoptions.hpp
185200
include/xeus-cpp/xpreamble.hpp
201+
include/xeus-cpp/xeus_cpp_tags_config.hpp
186202
#src/xdemangle.hpp
187203
#src/xinspect.hpp
188204
#src/xsystem.hpp
@@ -435,26 +451,6 @@ configure_package_config_file(${PROJECT_NAME}Config.cmake.in
435451
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
436452
INSTALL_DESTINATION ${PROJECT_BINARY_DIR})
437453

438-
# Install xeus-cpp tag files
439-
set(XEUS_CPP_DATA_DIR "share/xeus-cpp" CACHE STRING "xeus-cpp data directory")
440-
set(XCPP_TAGFILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/xeus-cpp/tagfiles)
441-
install(DIRECTORY ${XCPP_TAGFILES_DIR}
442-
DESTINATION ${XEUS_CPP_DATA_DIR})
443-
444-
set(XEUS_CPP_CONF_DIR "etc/xeus-cpp" CACHE STRING "xeus-cpp configuration directory")
445-
set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d)
446-
install(DIRECTORY ${XCPP_TAGCONFS_DIR}
447-
DESTINATION ${XEUS_CPP_CONF_DIR})
448-
449-
# Add definitions for the kernel to find tagfiles.
450-
add_definitions(-DXCPP_TAGFILES_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CPP_DATA_DIR}/tagfiles")
451-
if(CMAKE_INSTALL_PREFIX STREQUAL "/usr")
452-
# install into /etc instead of /usr/etc
453-
add_definitions(-DXCPP_TAGCONFS_DIR="/${XEUS_CPP_CONF_DIR}/tags.d")
454-
else()
455-
add_definitions(-DXCPP_TAGCONFS_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CPP_CONF_DIR}/tags.d")
456-
endif()
457-
458454
# Configure 'xeus-cppConfig.cmake.in for an install tree
459455
set(XEUS_CPP_CONFIG_CODE "")
460456
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/************************************************************************************
2+
* Copyright (c) 2023, xeus-cpp contributors *
3+
* *
4+
* Distributed under the terms of the BSD 3-Clause License. *
5+
* *
6+
* The full license is in the file LICENSE, distributed with this software. *
7+
************************************************************************************/
8+
9+
#ifndef XEUS_CPP_TAGS_CONFIG_HPP
10+
#define XEUS_CPP_TAGS_CONFIG_HPP
11+
12+
#define XCPP_TAGFILES_DIR "@XCPP_TAGFILES_DIR@"
13+
#define XCPP_TAGCONFS_DIR "@XCPP_TAGCONFS_DIR@"
14+
15+
#endif

src/xinterpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "xeus-cpp/xbuffer.hpp"
2424
#include "xeus-cpp/xeus_cpp_config.hpp"
25-
25+
#include "xeus-cpp/xeus_cpp_tags_config.hpp"
2626
#include "xeus-cpp/xinterpreter.hpp"
2727
#include "xeus-cpp/xmagics.hpp"
2828

test/test_interpreter.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
#include "xeus-cpp/xmanager.hpp"
1313
#include "xeus-cpp/xutils.hpp"
1414
#include "xeus-cpp/xoptions.hpp"
15+
#include "xeus-cpp/xeus_cpp_tags_config.hpp"
1516

1617
#include "../src/xparser.hpp"
1718
#include "../src/xsystem.hpp"
1819
#include "../src/xmagics/os.hpp"
20+
#include "../src/xinspect.hpp"
1921

22+
#include <pugixml.hpp>
2023
#include <fstream>
2124
#if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
2225
#include <sys/wait.h>
@@ -626,6 +629,22 @@ TEST_SUITE("xmagics_apply"){
626629
manager.apply("%dummy", kernel_res);
627630
REQUIRE(kernel_res["status"] == "error");
628631
}
632+
633+
TEST_CASE("cell magic with empty cell body") {
634+
xcpp::xmagics_manager manager;
635+
636+
std::stringstream ss;
637+
auto cerr_buff = std::cerr.rdbuf();
638+
std::cerr.rdbuf(ss.rdbuf());
639+
640+
manager.apply("test", "line", "");
641+
642+
std::cerr.rdbuf(cerr_buff);
643+
REQUIRE(ss.str() == "UsageError: %%test is a cell magic, but the cell body is empty.\n"
644+
"If you only intend to display %%test help, please use a double line break to fill in the cell body.\n");
645+
646+
}
647+
629648
}
630649

631650
#if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
@@ -673,4 +692,58 @@ TEST_SUITE("complete_request")
673692
}
674693
REQUIRE(found == 2);
675694
}
695+
}
696+
697+
TEST_SUITE("xinspect"){
698+
TEST_CASE("class_member_predicate_get_filename"){
699+
xcpp::class_member_predicate cmp;
700+
cmp.class_name = "TestClass";
701+
cmp.kind = "public";
702+
cmp.child_value = "testMethod";
703+
704+
pugi::xml_document doc;
705+
pugi::xml_node node = doc.append_child("node");
706+
node.append_attribute("kind") = "class";
707+
pugi::xml_node name = node.append_child("name");
708+
name.append_child(pugi::node_pcdata).set_value("TestClass");
709+
pugi::xml_node child = node.append_child("node");
710+
child.append_attribute("kind") = "public";
711+
pugi::xml_node child_name = child.append_child("name");
712+
child_name.append_child(pugi::node_pcdata).set_value("testMethod");
713+
pugi::xml_node anchorfile = child.append_child("anchorfile");
714+
anchorfile.append_child(pugi::node_pcdata).set_value("testfile.cpp");
715+
716+
REQUIRE(cmp.get_filename(node) == "testfile.cpp");
717+
718+
cmp.child_value = "nonexistentMethod";
719+
REQUIRE(cmp.get_filename(node) == "");
720+
}
721+
722+
TEST_CASE("class_member_predicate_operator"){
723+
xcpp::class_member_predicate cmp;
724+
cmp.class_name = "TestClass";
725+
cmp.kind = "public";
726+
cmp.child_value = "testMethod";
727+
728+
pugi::xml_document doc;
729+
pugi::xml_node node = doc.append_child("node");
730+
node.append_attribute("kind") = "class";
731+
pugi::xml_node name = node.append_child("name");
732+
name.append_child(pugi::node_pcdata).set_value("TestClass");
733+
pugi::xml_node child = node.append_child("node");
734+
child.append_attribute("kind") = "public";
735+
pugi::xml_node child_name = child.append_child("name");
736+
child_name.append_child(pugi::node_pcdata).set_value("testMethod");
737+
738+
739+
REQUIRE(cmp(node) == true);
740+
node.attribute("kind").set_value("struct");
741+
REQUIRE(cmp(node) == true);
742+
cmp.class_name = "NonexistentClass";
743+
REQUIRE(cmp(node) == false);
744+
cmp.kind = "private";
745+
REQUIRE(cmp(node) == false);
746+
cmp.child_value = "nonexistentMethod";
747+
REQUIRE(cmp(node) == false);
748+
}
676749
}

0 commit comments

Comments
 (0)