Skip to content

Commit

Permalink
Fix build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun571 committed Sep 12, 2024
1 parent e571ce3 commit e3cdbee
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 61 deletions.
4 changes: 0 additions & 4 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
#include "xinput.hpp"
#include "xinspect.hpp"
#include "xmagics/os.hpp"
#ifndef EMSCRIPTEN
#include "xmagics/xassist.hpp"
#endif
#include "xparser.hpp"
#include "xsystem.hpp"

Expand Down Expand Up @@ -407,8 +405,6 @@ __get_cxx_version ()
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("file", writefile());
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("timeit", timeit(&m_interpreter));
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("python", pythonexec());
#ifndef EMSCRIPTEN
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("xassist", xassist());
#endif
}
}
147 changes: 90 additions & 57 deletions test/test_xcpp_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,69 +69,102 @@ def test_continuation(self) -> None:


if platform.system() != 'Windows':
class XCppTests(jupyter_kernel_test.KernelTests):
# class XCppTests(jupyter_kernel_test.KernelTests):

# kernel_name = 'xcpp20'

# # language_info.name in a kernel_info_reply should match this
# language_name = 'C++'

# # Code that should write the exact string `hello, world` to STDOUT
# code_hello_world = '#include <iostream>\nstd::cout << "hello, world" << std::endl;'

# # Code that should cause (any) text to be written to STDERR
# code_stderr = '#include <iostream>\nstd::cerr << "oops" << std::endl;'

# # Pager: code that should display something (anything) in the pager
# code_page_something = "?std::vector"

# # Exception throwing
# # TODO: Remove 'if' when test work on MacOS/arm64. Throw Exceptions make
# # kernel/test non-workable.
# ###code_generate_error = 'throw std::runtime_error("Unknown exception");' if platform.system() != "Darwin" or platform.processor() != 'arm' else ''

# # Samples of code which generate a result value (ie, some text
# # displayed as Out[n])
# #code_execute_result = [
# # {
# # 'code': '6 * 7',
# # 'result': '42'
# # }
# #]

# # Samples of code which should generate a rich display output, and
# # the expected MIME type
# code_display_data = [
# {
# 'code': '#include <string>\n#include "xcpp/xdisplay.hpp"\nstd::string test("foobar");\nxcpp::display(test);',
# 'mime': 'text/plain'
# },
# {
# 'code': """
# #include <string>
# #include <fstream>
# #include "nlohmann/json.hpp"
# #include "xeus/xbase64.hpp"
# namespace im {
# struct image {
# inline image(const std::string& filename) {
# std::ifstream fin(filename, std::ios::binary);
# m_buffer << fin.rdbuf();
# }
# std::stringstream m_buffer;
# };
# nlohmann::json mime_bundle_repr(const image& i) {
# auto bundle = nlohmann::json::object();
# bundle["image/png"] = xeus::base64encode(i.m_buffer.str());
# return bundle;
# }
# }
# #include "xcpp/xdisplay.hpp"
# im::image marie("../notebooks/images/marie.png");
# xcpp::display(marie);""",
# 'mime': 'image/png'
# }
# ]

class XCppTests_debug(jupyter_kernel_test.KernelTests):

kernel_name = 'xcpp20'

# language_info.name in a kernel_info_reply should match this
language_name = 'C++'

# Code that should write the exact string `hello, world` to STDOUT
code_hello_world = '#include <iostream>\nstd::cout << "hello, world" << std::endl;'

# Code that should cause (any) text to be written to STDERR
code_stderr = '#include <iostream>\nstd::cerr << "oops" << std::endl;'

# Pager: code that should display something (anything) in the pager
code_page_something = "?std::vector"

# Exception throwing
# TODO: Remove 'if' when test work on MacOS/arm64. Throw Exceptions make
# kernel/test non-workable.
###code_generate_error = 'throw std::runtime_error("Unknown exception");' if platform.system() != "Darwin" or platform.processor() != 'arm' else ''

# Samples of code which generate a result value (ie, some text
# displayed as Out[n])
#code_execute_result = [
# {
# 'code': '6 * 7',
# 'result': '42'
# }
#]

# Samples of code which should generate a rich display output, and
# the expected MIME type
code_display_data = [
{
'code': '#include <string>\n#include "xcpp/xdisplay.hpp"\nstd::string test("foobar");\nxcpp::display(test);',
'mime': 'text/plain'
},
{
'code': """
#include <string>
#include <fstream>
#include "nlohmann/json.hpp"
#include "xeus/xbase64.hpp"
namespace im {
struct image {
inline image(const std::string& filename) {
std::ifstream fin(filename, std::ios::binary);
m_buffer << fin.rdbuf();
}
std::stringstream m_buffer;
};
nlohmann::json mime_bundle_repr(const image& i) {
auto bundle = nlohmann::json::object();
bundle["image/png"] = xeus::base64encode(i.m_buffer.str());
return bundle;
}
}
#include "xcpp/xdisplay.hpp"
im::image marie("../notebooks/images/marie.png");
xcpp::display(marie);""",
'mime': 'image/png'
}
]
code_err="""
#include <iostream>
std::cerr << "oops" << std::endl;
"""

code_stdout="""
#include <iostream>
std::cout << "oops_std" << std::endl;
"""

def test_xcpp_err(self):
self.flush_channels()
reply, output_msgs = self.execute_helper(code=self.code_err)
print(output_msgs)
self.assertEqual(output_msgs[0]['msg_type'], 'stream')
self.assertEqual(output_msgs[0]['content']['name'], 'stderr')
self.assertEqual(output_msgs[0]['content']['text'], 'oops\n')

def test_xcpp_stdout(self):
self.flush_channels()
reply, output_msgs = self.execute_helper(code=self.code_stdout)
print(output_msgs)
self.assertEqual(output_msgs[0]['msg_type'], 'stream')
self.assertEqual(output_msgs[0]['content']['name'], 'stdout')
self.assertEqual(output_msgs[0]['content']['text'], 'oops_std\n')

# Tests for Notebooks
class XCppNotebookTests(unittest.TestCase):
Expand Down

0 comments on commit e3cdbee

Please sign in to comment.