Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,22 @@ if(EMSCRIPTEN)
# 3) Shift the resource dir and the sysroot to a common location.
# 4) Preload everything required together.
endif()

# Tests
# =====

if(XEUS_CPP_BUILD_TESTS)
add_subdirectory(test)
endif()

set(XEUS_SEARCH_PATH $<JOIN:$<TARGET_PROPERTY:xeus-cpp,INCLUDE_DIRECTORIES>,:>)

if (NOT EMSCRIPTEN)
set(XEUS_SEARCH_PATH "${XEUS_SEARCH_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/src")
endif()

target_compile_definitions(xeus-cpp PRIVATE "XEUS_SEARCH_PATH=\"${XEUS_SEARCH_PATH}\"")

# Installation
# ============
include(CMakePackageConfigHelpers)
Expand Down
1 change: 1 addition & 0 deletions include/xeus-cpp/xinterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define XEUS_CPP_INTERPRETER_HPP

#include <memory>
#include <sstream>
#include <streambuf>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header sstream is not used directly [misc-include-cleaner]

Suggested change
#include <streambuf>
#include <streambuf>

#include <string>
#include <vector>
Expand Down
15 changes: 15 additions & 0 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ __get_cxx_version ()
createInterpreter(Args(argv ? argv + 1 : argv, argv + argc));
m_version = get_stdopt();
redirect_output();
init_includes();
init_preamble();
init_magic();
}
Expand Down Expand Up @@ -356,6 +357,20 @@ __get_cxx_version ()
publish_stream("stderr", s);
}

void interpreter::init_includes()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'init_includes' can be made static [readability-convert-member-functions-to-static]

include/xeus-cpp/xinterpreter.hpp:74:

-         void init_includes();
+         static void init_includes();

{
Cpp::AddIncludePath((xeus::prefix_path() + "/include/").c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Cpp::AddIncludePath" is directly included [misc-include-cleaner]

        Cpp::AddIncludePath((xeus::prefix_path() + "/include/").c_str());
             ^

if (const char* paths = std::getenv("XEUS_SEARCH_PATH")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::getenv" is directly included [misc-include-cleaner]

src/xinterpreter.cpp:19:

- #ifndef EMSCRIPTEN
+ #include <cstdlib>
+ #ifndef EMSCRIPTEN

std::istringstream stream(paths);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::istringstream" is directly included [misc-include-cleaner]

src/xinterpreter.cpp:19:

- #ifndef EMSCRIPTEN
+ #include <sstream>
+ #ifndef EMSCRIPTEN

std::string path;
char delimiter = (std::string(paths).find(';') != std::string::npos) ? ';' : ':';

while (std::getline(stream, path, delimiter))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::getline" is directly included [misc-include-cleaner]

            while (std::getline(stream, path, delimiter))
                        ^

if (!path.empty())
Cpp::AddIncludePath(path.c_str());
}
}

void interpreter::init_preamble()
{
//NOLINTBEGIN(cppcoreguidelines-owning-memory)
Expand Down
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ target_link_libraries(test_xeus_cpp xeus-cpp doctest::doctest ${CMAKE_THREAD_LIB
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})

add_custom_target(xtest COMMAND test_xeus_cpp DEPENDS test_xeus_cpp)

# Test for non-standard include paths
add_executable(test_include_paths test_include_paths.cpp)
target_link_libraries(test_include_paths PRIVATE doctest::doctest)
target_include_directories(test_include_paths PRIVATE
${CMAKE_SOURCE_DIR}/test/custom_includes
${DOCTEST_INCLUDE_DIR}
)
target_compile_definitions(test_include_paths PRIVATE DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
add_test(NAME test_include_paths COMMAND test_include_paths)

8 changes: 8 additions & 0 deletions test/custom_includes/test_header.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef TEST_HEADER_HPP
#define TEST_HEADER_HPP

namespace test_ns {
constexpr int test_value = 42;
}

#endif
8 changes: 8 additions & 0 deletions test/test_include_paths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <doctest/doctest.h>
#include <string>
#include "test_header.hpp"

TEST_CASE("Test non-standard include paths")
{
CHECK(test_ns::test_value == 42);
}
Loading