Browse Source

add ctags test

python
Jørgen Lien Sellæg 7 years ago committed by Jørgen Sverre Lien Sellæg
parent
commit
86e6a12180
  1. 3
      src/ctags.cpp
  2. 4
      tests/python_bindings/CMakeLists.txt
  3. 39
      tests/python_bindings/Ctags_tests/ctags_test.cc
  4. 27
      tests/python_bindings/Ctags_tests/ctags_test.py

3
src/ctags.cpp

@ -282,6 +282,7 @@ std::vector<Ctags::Location> Ctags::get_locations(const boost::filesystem::path
void Ctags::init_module(py::module &api) { void Ctags::init_module(py::module &api) {
py::class_<Ctags> ctags(api, "Ctags"); py::class_<Ctags> ctags(api, "Ctags");
py::class_<Ctags::Location>(api, "Location") py::class_<Ctags::Location>(api, "Location")
.def(py::init<>())
.def_readwrite("file_path", &Ctags::Location::file_path) .def_readwrite("file_path", &Ctags::Location::file_path)
.def_readwrite("line", &Ctags::Location::line) .def_readwrite("line", &Ctags::Location::line)
.def_readwrite("index", &Ctags::Location::index) .def_readwrite("index", &Ctags::Location::index)
@ -293,8 +294,6 @@ void Ctags::init_module(py::module &api) {
; ;
ctags ctags
.def_static("get_result", &Ctags::get_result,
py::arg("path"))
.def_static("get_location", &Ctags::get_location, .def_static("get_location", &Ctags::get_location,
py::arg("line"), py::arg("line"),
py::arg("markup")) py::arg("markup"))

4
tests/python_bindings/CMakeLists.txt

@ -23,3 +23,7 @@ add_test(pb_compile_commands_test pb_compile_commands_test)
add_executable(pb_config_test Config_tests/config_test.cc $<TARGET_OBJECTS:test_stubs>) add_executable(pb_config_test Config_tests/config_test.cc $<TARGET_OBJECTS:test_stubs>)
target_link_libraries(pb_config_test test_suite) target_link_libraries(pb_config_test test_suite)
add_test(pb_config_test pb_config_test) add_test(pb_config_test pb_config_test)
add_executable(pb_ctags_test Ctags_tests/ctags_test.cc $<TARGET_OBJECTS:test_stubs>)
target_link_libraries(pb_ctags_test test_suite)
add_test(pb_ctags_test pb_ctags_test)

39
tests/python_bindings/Ctags_tests/ctags_test.cc

@ -0,0 +1,39 @@
#include "test_suite.h"
#include <iostream>
int main() {
auto &config = Config::get();
config.project.ctags_command = "ctags";
#ifdef _WIN32
std::string slash = "\\";
config.project.cmake.command =
"cmake -G\"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=/mingw64";
#else
auto slash = "/";
config.project.cmake.command = "cmake";
#endif
auto suite_name = "Ctags_tests";
{
auto doTest = [&](auto test) {
auto test_suite = suite(suite_name);
{
auto module = py::module::import("ctags_test");
test_suite.has_assertion = false;
auto project_path = (test_suite.test_file_path / "cmake_project")
.make_preferred()
.string();
try {
module.attr(test)(project_path, slash);
test_suite.has_assertion = true;
}
catch(const std::exception &error) {
std::cout << error.what();
}
}
};
doTest("get_location");
doTest("get_locations");
}
}

27
tests/python_bindings/Ctags_tests/ctags_test.py

@ -0,0 +1,27 @@
from Jucipp import Ctags
from jucipp_test import assert_equal
def get_location(a, b):
line = 'main main.cpp /^int main() { return 0; }$/;" line:1'
location = Ctags.get_location(line, False)
if location:
assert_equal('main.cpp', location.file_path)
assert_equal(0, location.line)
assert_equal(4, location.index)
assert_equal('main', location.symbol)
assert_equal('', location.scope)
assert_equal('int main() { return 0; }', location.source)
else:
raise ValueError('File path was empty')
def get_locations(project_path, slash):
path = project_path + slash + 'main.cpp'
locations = Ctags.get_locations(project_path + slash + 'main.cpp', 'main', 'int ()')
assert_equal(len(locations), 1)
location = locations[0];
assert_equal(path, location.file_path)
assert_equal(0, location.line)
assert_equal(4, location.index)
assert_equal('main', location.symbol)
assert_equal('', location.scope)
assert_equal('int main() { return 0; }', location.source)
Loading…
Cancel
Save