Skip to content

Commit 63ab29a

Browse files
tharun571vgvassilev
authored andcommitted
Add tests for xinspect, update cmake
1 parent a2841c6 commit 63ab29a

File tree

5 files changed

+103
-33
lines changed

5 files changed

+103
-33
lines changed

CMakeLists.txt

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,26 @@ 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+
# 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+
30+
set(XEUS_CPP_CONF_DIR "etc/xeus-cpp" CACHE STRING "xeus-cpp configuration directory")
31+
set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d)
32+
2633
# Versionning
2734
# ===========
2835

29-
file(STRINGS "${XEUS_CPP_INCLUDE_DIR}/xeus-cpp/xeus_cpp_config.hpp" version_defines
30-
REGEX "#define XEUS_CPP_VERSION_(MAJOR|MINOR|PATCH)")
31-
foreach (ver ${version_defines})
32-
if (ver MATCHES "#define XEUS_CPP_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
33-
set(XEUS_CPP_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
34-
endif ()
35-
endforeach ()
36+
file(STRINGS "VERSION" XEUS_CPP_VERSION)
37+
string(REPLACE "." ";" VERSION_LIST "${XEUS_CPP_VERSION}")
38+
string(REPLACE "\\" "" VERSION_LIST "${VERSION_LIST}")
39+
list(GET VERSION_LIST 0 XEUS_CPP_VERSION_MAJOR)
40+
list(GET VERSION_LIST 1 XEUS_CPP_VERSION_MINOR)
41+
list(GET VERSION_LIST 2 XEUS_CPP_VERSION_PATCH)
42+
3643
set(${PROJECT_NAME}_VERSION
3744
${XEUS_CPP_VERSION_MAJOR}.${XEUS_CPP_VERSION_MINOR}.${XEUS_CPP_VERSION_PATCH})
38-
message(STATUS "Building xeus-cpp v${${PROJECT_NAME}_VERSION}")
45+
message(STATUS "Building xeus-cpp v${XEUS_CPP_VERSION}")
3946

4047
# Build options
4148
# =============
@@ -164,6 +171,9 @@ message("Configure kernels: ...")
164171
configure_kernel("/share/jupyter/kernels/xcpp17/")
165172
configure_kernel("/share/jupyter/kernels/xcpp20/")
166173

174+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp.in"
175+
"${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_config.hpp")
176+
167177
# Source files
168178
# ============
169179

@@ -383,6 +393,12 @@ include(CMakePackageConfigHelpers)
383393

384394
set(XEUS_CPP_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for xeus-cppConfig.cmake")
385395

396+
install(DIRECTORY ${XCPP_TAGFILES_DIR}
397+
DESTINATION ${XEUS_CPP_DATA_DIR})
398+
399+
install(DIRECTORY ${XCPP_TAGCONFS_DIR}
400+
DESTINATION ${XEUS_CPP_CONF_DIR})
401+
386402
# Install xeus-cpp and xeus-cpp-static
387403
if (XEUS_CPP_BUILD_SHARED)
388404
install(TARGETS ${XEUS_CPP_TARGETS}
@@ -430,26 +446,6 @@ configure_package_config_file(${PROJECT_NAME}Config.cmake.in
430446
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
431447
INSTALL_DESTINATION ${PROJECT_BINARY_DIR})
432448

433-
# Install xeus-cpp tag files
434-
set(XEUS_CPP_DATA_DIR "share/xeus-cpp" CACHE STRING "xeus-cpp data directory")
435-
set(XCPP_TAGFILES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/share/xeus-cpp/tagfiles)
436-
install(DIRECTORY ${XCPP_TAGFILES_DIR}
437-
DESTINATION ${XEUS_CPP_DATA_DIR})
438-
439-
set(XEUS_CPP_CONF_DIR "etc/xeus-cpp" CACHE STRING "xeus-cpp configuration directory")
440-
set(XCPP_TAGCONFS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/etc/xeus-cpp/tags.d)
441-
install(DIRECTORY ${XCPP_TAGCONFS_DIR}
442-
DESTINATION ${XEUS_CPP_CONF_DIR})
443-
444-
# Add definitions for the kernel to find tagfiles.
445-
add_definitions(-DXCPP_TAGFILES_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CPP_DATA_DIR}/tagfiles")
446-
if(CMAKE_INSTALL_PREFIX STREQUAL "/usr")
447-
# install into /etc instead of /usr/etc
448-
add_definitions(-DXCPP_TAGCONFS_DIR="/${XEUS_CPP_CONF_DIR}/tags.d")
449-
else()
450-
add_definitions(-DXCPP_TAGCONFS_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CPP_CONF_DIR}/tags.d")
451-
endif()
452-
453449
# Configure 'xeus-cppConfig.cmake.in for an install tree
454450
set(XEUS_CPP_CONFIG_CODE "")
455451
configure_package_config_file(${PROJECT_NAME}Config.cmake.in

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.5.0;dev

include/xeus-cpp/xeus_cpp_config.hpp renamed to include/xeus-cpp/xeus_cpp_config.hpp.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#define XEUS_CPP_CONFIG_HPP
1111

1212
// Project version
13-
#define XEUS_CPP_VERSION_MAJOR 0
14-
#define XEUS_CPP_VERSION_MINOR 4
15-
#define XEUS_CPP_VERSION_PATCH 0
13+
#define XEUS_CPP_VERSION_MAJOR @XEUS_CPP_VERSION_MAJOR@
14+
#define XEUS_CPP_VERSION_MINOR @XEUS_CPP_VERSION_MINOR@
15+
#define XEUS_CPP_VERSION_PATCH @XEUS_CPP_VERSION_PATCH@
16+
17+
#define XCPP_TAGFILES_DIR "@XCPP_TAGFILES_DIR@"
18+
#define XCPP_TAGCONFS_DIR "@XCPP_TAGCONFS_DIR@"
1619

1720
// Composing the version string from major, minor and patch
1821
#define XEUS_CPP_CONCATENATE(A, B) XEUS_CPP_CONCATENATE_IMPL(A, B)

src/xinterpreter.cpp

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

2323
#include "xeus-cpp/xbuffer.hpp"
2424
#include "xeus-cpp/xeus_cpp_config.hpp"
25-
2625
#include "xeus-cpp/xinterpreter.hpp"
2726
#include "xeus-cpp/xmagics.hpp"
2827

test/test_interpreter.cpp

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
#include "xeus-cpp/xmanager.hpp"
1515
#include "xeus-cpp/xutils.hpp"
1616
#include "xeus-cpp/xoptions.hpp"
17+
#include "xeus-cpp/xeus_cpp_config.hpp"
1718

1819
#include "../src/xparser.hpp"
1920
#include "../src/xsystem.hpp"
2021
#include "../src/xmagics/os.hpp"
22+
#include "../src/xinspect.hpp"
2123

22-
#include <iostream>
2324

25+
#include <iostream>
26+
#include <pugixml.hpp>
2427
#include <fstream>
2528
#if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
2629
#include <sys/wait.h>
@@ -761,6 +764,20 @@ TEST_SUITE("xmagics_apply"){
761764
REQUIRE(redirect.getCaptured() == "UsageError: %%test is a cell magic, but the cell body is empty.\n"
762765
"If you only intend to display %%test help, please use a double line break to fill in the cell body.\n");
763766
}
767+
TEST_CASE("cell magic with empty cell body") {
768+
xcpp::xmagics_manager manager;
769+
770+
std::stringstream ss;
771+
auto cerr_buff = std::cerr.rdbuf();
772+
std::cerr.rdbuf(ss.rdbuf());
773+
774+
manager.apply("test", "line", "");
775+
776+
std::cerr.rdbuf(cerr_buff);
777+
REQUIRE(ss.str() == "UsageError: %%test is a cell magic, but the cell body is empty.\n"
778+
"If you only intend to display %%test help, please use a double line break to fill in the cell body.\n");
779+
780+
}
764781
}
765782

766783
#if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
@@ -830,4 +847,58 @@ TEST_SUITE("complete_request")
830847
}
831848
REQUIRE(found == 2);
832849
}
850+
}
851+
852+
TEST_SUITE("xinspect"){
853+
TEST_CASE("class_member_predicate_get_filename"){
854+
xcpp::class_member_predicate cmp;
855+
cmp.class_name = "TestClass";
856+
cmp.kind = "public";
857+
cmp.child_value = "testMethod";
858+
859+
pugi::xml_document doc;
860+
pugi::xml_node node = doc.append_child("node");
861+
node.append_attribute("kind") = "class";
862+
pugi::xml_node name = node.append_child("name");
863+
name.append_child(pugi::node_pcdata).set_value("TestClass");
864+
pugi::xml_node child = node.append_child("node");
865+
child.append_attribute("kind") = "public";
866+
pugi::xml_node child_name = child.append_child("name");
867+
child_name.append_child(pugi::node_pcdata).set_value("testMethod");
868+
pugi::xml_node anchorfile = child.append_child("anchorfile");
869+
anchorfile.append_child(pugi::node_pcdata).set_value("testfile.cpp");
870+
871+
REQUIRE(cmp.get_filename(node) == "testfile.cpp");
872+
873+
cmp.child_value = "nonexistentMethod";
874+
REQUIRE(cmp.get_filename(node) == "");
875+
}
876+
877+
TEST_CASE("class_member_predicate_operator"){
878+
xcpp::class_member_predicate cmp;
879+
cmp.class_name = "TestClass";
880+
cmp.kind = "public";
881+
cmp.child_value = "testMethod";
882+
883+
pugi::xml_document doc;
884+
pugi::xml_node node = doc.append_child("node");
885+
node.append_attribute("kind") = "class";
886+
pugi::xml_node name = node.append_child("name");
887+
name.append_child(pugi::node_pcdata).set_value("TestClass");
888+
pugi::xml_node child = node.append_child("node");
889+
child.append_attribute("kind") = "public";
890+
pugi::xml_node child_name = child.append_child("name");
891+
child_name.append_child(pugi::node_pcdata).set_value("testMethod");
892+
893+
894+
REQUIRE(cmp(node) == true);
895+
node.attribute("kind").set_value("struct");
896+
REQUIRE(cmp(node) == true);
897+
cmp.class_name = "NonexistentClass";
898+
REQUIRE(cmp(node) == false);
899+
cmp.kind = "private";
900+
REQUIRE(cmp(node) == false);
901+
cmp.child_value = "nonexistentMethod";
902+
REQUIRE(cmp(node) == false);
903+
}
833904
}

0 commit comments

Comments
 (0)