Skip to content

Commit b63bd9e

Browse files
committed
Update tags definition, add tests for xmagics, xinspect
1 parent 33ad76a commit b63bd9e

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ else()
455455
add_definitions(-DXCPP_TAGCONFS_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CPP_CONF_DIR}/tags.d")
456456
endif()
457457

458+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/xeus-cpp/xeus_cpp_tags_config.hpp.in"
459+
"${CMAKE_CURRENT_BINARY_DIR}/include/xeus-cpp/xeus_cpp_tags_config.hpp")
460+
458461
# Configure 'xeus-cppConfig.cmake.in for an install tree
459462
set(XEUS_CPP_CONFIG_CODE "")
460463
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

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)