diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24f1462..bc07f4e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ set(JUCI_SHARED_FILES menu.cpp meson.cpp project_build.cpp + python_interpreter.cc snippets.cpp source.cpp source_base.cpp @@ -42,19 +43,18 @@ target_link_libraries(juci_shared ) set(JUCI_SOURCES - config.cc - dialogs.cc - dialogs_unix.cc - directories.cc - entrybox.cc - info.cc - juci.cc - notebook.cc - project.cc - selection_dialog.cc - tooltips.cc - window.cc - python_interpreter.cc + config.cpp + dialogs.cpp + dialogs_unix.cpp + directories.cpp + entrybox.cpp + info.cpp + juci.cpp + notebook.cpp + project.cpp + selection_dialog.cpp + tooltips.cpp + window.cpp ) if(APPLE) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f41cd14..2999a72 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -121,3 +121,12 @@ if(BUILD_FUZZING) target_link_options(markdown_fuzzer PRIVATE -fsanitize=address,fuzzer) target_link_libraries(markdown_fuzzer juci_shared) endif() + +add_executable(git_test git_test.cc $) +target_link_libraries(git_test juci_shared) +add_test(git_test git_test) + +add_executable(python_interpreter_test python_interpreter_test.cc $) +target_link_libraries(python_interpreter_test juci_shared ${PYTHON_LIBRARIES}) +add_test(python_interpreter_test python_interpreter_test) + diff --git a/tests/python_interpreter_test.cc b/tests/python_interpreter_test.cc new file mode 100644 index 0000000..ed877ae --- /dev/null +++ b/tests/python_interpreter_test.cc @@ -0,0 +1,76 @@ +#include "config.h" +#include "plugins.h" +#include "python_interpreter.h" +#include "python_module.h" +#include "terminal.h" + + +class __attribute__((visibility("default"))) +suite { +public: + Glib::RefPtr app = Gtk::Application::create(); + py::detail::embedded_module jucipp = py::detail::embedded_module("Jucipp", Module::init_jucipp_module); + Python::Interpreter interpreter; + Terminal &terminal = Terminal::get(); + Config &config = Config::get(); + boost::filesystem::path test_file_path = boost::filesystem::canonical(std::string(JUCI_TESTS_PATH) + "/python_interpreter_test_files"); + bool has_assertion = false; + suite() { + auto sys = interpreter.add_module("sys"); + sys.attr("path").cast().append(test_file_path.string()); + config.terminal.history_size = 100; + } + ~suite() { + g_assert_true(has_assertion); + } +}; + +int main() { + { + suite test_suite; + { + py::module::import("basic_test"); + try { + py::module::import("exception_test"); + } + catch(const py::error_already_set &error) { + test_suite.has_assertion = true; + } + } + } + + { + suite test_suite; + { + auto connection = test_suite.terminal.get_buffer()->signal_insert().connect([&](const Gtk::TextBuffer::iterator &, const Glib::ustring &msg, int) { + g_assert_cmpstr(msg.c_str(), ==, "Hello, World!\n"); + test_suite.has_assertion = true; + }); + auto module = py::module::import("terminal_test"); + module.attr("hello_world")(); + connection.disconnect(); + } + } + { + suite test_suite; + { + auto connection = test_suite.terminal.get_buffer()->signal_insert().connect([&](const Gtk::TextBuffer::iterator &, const Glib::ustring &msg, int) { + g_assert_cmpstr(msg.c_str(), ==, "hello_world.txt\n"); + test_suite.has_assertion = true; + test_suite.app->release(); + }); + test_suite.app->hold(); + std::thread thread([&] { + const auto ls_dir = test_suite.test_file_path / "ls"; + auto module = py::module::import("terminal_test"); + auto res = module.attr("process")(ls_dir).cast(); + g_assert_cmpint(res, ==, 0); + }); + test_suite.app->run(); + thread.join(); + connection.disconnect(); + } + } + + return 0; +} diff --git a/tests/python_interpreter_test_files/basic_test.py b/tests/python_interpreter_test_files/basic_test.py new file mode 100644 index 0000000..200f1f5 --- /dev/null +++ b/tests/python_interpreter_test_files/basic_test.py @@ -0,0 +1 @@ +import Jucipp diff --git a/tests/python_interpreter_test_files/exception_test.py b/tests/python_interpreter_test_files/exception_test.py new file mode 100644 index 0000000..618a16e --- /dev/null +++ b/tests/python_interpreter_test_files/exception_test.py @@ -0,0 +1 @@ +invalid code diff --git a/tests/python_interpreter_test_files/ls/hello_world.txt b/tests/python_interpreter_test_files/ls/hello_world.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/python_interpreter_test_files/terminal_test.py b/tests/python_interpreter_test_files/terminal_test.py new file mode 100644 index 0000000..e2d3736 --- /dev/null +++ b/tests/python_interpreter_test_files/terminal_test.py @@ -0,0 +1,15 @@ +from Jucipp import Terminal + +t = Terminal(); + +def hello_world(): + t.print("Hello, World!\n") + +def clear(): + t.clear() + +def process(path): + return t.process("ls", path, True) + +def async_print(): + return t.async_print("Hello, World!")