Browse Source

Added source_clang test, and tests cleanup

merge-requests/365/head
eidheim 10 years ago
parent
commit
c8f72431ed
  1. 20
      CMakeLists.txt
  2. 65
      src/CMakeLists.txt
  3. 27
      tests/CMakeLists.txt
  4. 1
      tests/clang_project/CMakeLists.txt
  5. 7
      tests/clang_project/build/compile_commands.json
  6. 5
      tests/clang_project/main.cpp
  7. 43
      tests/source_clang_test.cc
  8. 12
      tests/source_test.cc
  9. 5
      tests/stubs/dispatcher.cc
  10. 6
      tests/stubs/selectiondialog.cc
  11. 14
      tests/stubs/terminal.cc
  12. 11
      tests/stubs/tooltips.cc

20
CMakeLists.txt

@ -1,10 +1,10 @@
cmake_minimum_required (VERSION 2.8.4) cmake_minimum_required (VERSION 2.8.8)
set(project_name juci) set(project_name juci)
project (${project_name}) project (${project_name})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder")
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif() endif()
@ -18,6 +18,22 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/")
find_package(LibClang REQUIRED) find_package(LibClang REQUIRED)
#Find liblldb with the same version as the version of libclang found
string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}")
if(EXISTS "${LIBLLDB_LIBRARIES}")
set(LIBLLDB_FOUND TRUE)
elseif(EXISTS "${LIBLLDB_LIBRARIES}.1")
set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1")
set(LIBLLDB_FOUND TRUE)
endif()
if(LIBLLDB_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG")
else()
set(LIBLLDB_LIBRARIES "")
message("liblldb not found. Building juCi++ without debugging support")
endif()
find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED)
find_package(ASPELL REQUIRED) find_package(ASPELL REQUIRED)
include(FindPkgConfig) include(FindPkgConfig)

65
src/CMakeLists.txt

@ -13,20 +13,6 @@ if(MSYS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSYS_PROCESS_USE_SH") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSYS_PROCESS_USE_SH")
endif() endif()
string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}")
if(EXISTS "${LIBLLDB_LIBRARIES}")
set(LIBLLDB_FOUND TRUE)
elseif(EXISTS "${LIBLLDB_LIBRARIES}.1")
set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1")
set(LIBLLDB_FOUND TRUE)
endif()
if(LIBLLDB_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG")
else()
set(LIBLLDB_LIBRARIES "")
message("liblldb not found. Building juCi++ without debugging support")
endif()
set(global_includes set(global_includes
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS}
@ -38,54 +24,40 @@ set(global_includes
) )
set(global_libraries set(global_libraries
${LIBCLANG_LIBRARIES}
${GTKMM_LIBRARIES} ${GTKMM_LIBRARIES}
${GTKSVMM_LIBRARIES} ${GTKSVMM_LIBRARIES}
${Boost_LIBRARIES} ${Boost_LIBRARIES}
${ASPELL_LIBRARIES} ${LIBCLANG_LIBRARIES}
${LIBLLDB_LIBRARIES} ${LIBLLDB_LIBRARIES}
${ASPELL_LIBRARIES}
) )
set(project_files set(project_files
cmake.cc
cmake.h
config.cc config.cc
config.h
dialogs.cc dialogs.cc
dialogs.h
directories.cc directories.cc
directories.h
dispatcher.cc
dispatcher.h
entrybox.cc entrybox.cc
entrybox.h
files.h
filesystem.cc
filesystem.h
info.h
info.cc info.cc
juci.cc juci.cc
juci.h
menu.cc menu.cc
menu.h
notebook.cc notebook.cc
notebook.h
project.cc project.cc
project.h
project_build.h
project_build.cc
selectiondialog.cc selectiondialog.cc
selectiondialog.h
source.cc
source.h
source_clang.cc
source_clang.h
terminal.cc terminal.cc
terminal.h
tooltips.cc tooltips.cc
tooltips.h
window.cc window.cc
window.h
../tiny-process-library/process.cpp
)
#Files used both in ../src and ../tests
set(project_shared_files
cmake.cc
dispatcher.cc
filesystem.cc
project_build.cc
source.cc
source_clang.cc
../libclangmm/src/CodeCompleteResults.cc ../libclangmm/src/CodeCompleteResults.cc
../libclangmm/src/CompilationDatabase.cc ../libclangmm/src/CompilationDatabase.cc
@ -101,11 +73,10 @@ set(project_files
../libclangmm/src/Tokens.cc ../libclangmm/src/Tokens.cc
../libclangmm/src/TranslationUnit.cc ../libclangmm/src/TranslationUnit.cc
../libclangmm/src/Utility.cc ../libclangmm/src/Utility.cc
)
../tiny-process-library/process.cpp)
if(LIBLLDB_FOUND) if(LIBLLDB_FOUND)
list(APPEND project_files debug_clang.h debug_clang.cc) list(APPEND project_shared_files debug_clang.cc)
endif() endif()
if(MSYS) if(MSYS)
@ -116,11 +87,13 @@ endif()
include_directories(${global_includes}) include_directories(${global_includes})
add_library(project_shared ${project_shared_files})
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL "")) if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL ""))
add_library(${project_name} OBJECT ${project_files}) add_library(${project_name} OBJECT ${project_files})
else() else()
add_executable(${project_name} ${project_files}) add_executable(${project_name} ${project_files})
target_link_libraries(${project_name} ${global_libraries}) target_link_libraries(${project_name} ${global_libraries} project_shared)
install(TARGETS ${project_name} install(TARGETS ${project_name}
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
) )

27
tests/CMakeLists.txt

@ -4,38 +4,43 @@ set(global_includes
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS}
${GTKSVMM_INCLUDE_DIRS} ${GTKSVMM_INCLUDE_DIRS}
${LIBCLANG_INCLUDE_DIRS}
${ASPELL_INCLUDE_DIR} ${ASPELL_INCLUDE_DIR}
../src ../libclangmm/src
../tiny-process-library ../tiny-process-library
../src
) )
set(global_libraries set(global_libraries
${GTKMM_LIBRARIES} ${GTKMM_LIBRARIES}
${GTKSVMM_LIBRARIES} ${GTKSVMM_LIBRARIES}
${Boost_LIBRARIES} ${Boost_LIBRARIES}
${LIBCLANG_LIBRARIES}
${LIBLLDB_LIBRARIES}
${ASPELL_LIBRARIES} ${ASPELL_LIBRARIES}
) )
set(stub_sources set(stub_files
stubs/config.cc stubs/config.cc
stubs/dialogs.cc stubs/dialogs.cc
stubs/dispatcher.cc
stubs/info.cc stubs/info.cc
stubs/selectiondialog.cc stubs/selectiondialog.cc
stubs/terminal.cc stubs/terminal.cc
stubs/tooltips.cc stubs/tooltips.cc
) )
include_directories(${global_includes}) add_library(stubs ${stub_files})
add_library(stubs_library ${stub_sources}) include_directories(${global_includes})
add_executable(cmake_build_test cmake_build_test.cc add_executable(cmake_build_test cmake_build_test.cc)
../src/filesystem.cc ../src/cmake.cc ../src/project_build.cc) target_link_libraries(cmake_build_test ${global_libraries} project_shared stubs)
target_link_libraries(cmake_build_test ${global_libraries} stubs_library)
add_test(cmake_build_test cmake_build_test) add_test(cmake_build_test cmake_build_test)
add_executable(source_test source_test.cc add_executable(source_test source_test.cc)
../src/source.cc) target_link_libraries(source_test ${global_libraries} project_shared stubs)
target_link_libraries(source_test ${global_libraries} stubs_library)
add_test(source_test source_test) add_test(source_test source_test)
add_executable(source_clang_test source_clang_test.cc)
target_link_libraries(source_clang_test ${global_libraries} project_shared stubs)
add_test(source_clang_test source_clang_test)

1
tests/clang_project/CMakeLists.txt

@ -0,0 +1 @@
set(project_name hello)

7
tests/clang_project/build/compile_commands.json

@ -0,0 +1,7 @@
[
{
"directory": "build",
"command": "c++ -std=c++1y -Wall -Wextra -Wno-unused-parameter main.cpp",
"file": "main.cpp"
}
]

5
tests/clang_project/main.cpp

@ -0,0 +1,5 @@
#include <iostream>
int main() {
std::cout << "hello world\n";
}

43
tests/source_clang_test.cc

@ -0,0 +1,43 @@
#include <glib.h>
#include "source_clang.h"
#include "config.h"
#include "filesystem.h"
std::string hello_world_error=R"(#include <iostream>
int main() {
std::cout << "hello world\n"
}
)";
//Requires display server to work
//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment:
//broadwayd&
//make test
int main() {
auto app=Gtk::Application::create();
Gsv::init();
Config::get().project.default_build_path="./build";
Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/clang_project/main.cpp"),
Gsv::LanguageManager::get_default()->get_language("cpp"));
while(!clang_view->parsed) {
while(Gtk::Main::events_pending())
Gtk::Main::iteration(false);
}
g_assert(clang_view->diagnostics.size()==0);
clang_view->get_buffer()->set_text(hello_world_error);
while(Gtk::Main::events_pending())
Gtk::Main::iteration(false);
while(!clang_view->parsed) {
while(Gtk::Main::events_pending())
Gtk::Main::iteration(false);
}
g_assert(clang_view->diagnostics.size()>0);
clang_view->async_delete();
clang_view->delete_thread.join();
while(Gtk::Main::events_pending())
Gtk::Main::iteration(false);
}

12
tests/source_test.cc

@ -2,18 +2,6 @@
#include "source.h" #include "source.h"
#include "filesystem.h" #include "filesystem.h"
int filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
return 0;
}
int filesystem::read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
return 0;
}
bool filesystem::write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
return false;
}
std::string hello_world=R"(#include <iostream> std::string hello_world=R"(#include <iostream>
int main() { int main() {

5
tests/stubs/dispatcher.cc

@ -1,5 +0,0 @@
#include "dispatcher.h"
Dispatcher::Dispatcher() {}
Dispatcher::~Dispatcher() {}

6
tests/stubs/selectiondialog.cc

@ -17,4 +17,10 @@ SelectionDialog::SelectionDialog(Gtk::TextView& text_view, Glib::RefPtr<Gtk::Tex
SelectionDialogBase::~SelectionDialogBase() {} SelectionDialogBase::~SelectionDialogBase() {}
bool SelectionDialog::on_key_press(GdkEventKey* key) { return true; } bool SelectionDialog::on_key_press(GdkEventKey* key) { return true; }
CompletionDialog::CompletionDialog(Gtk::TextView &text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark):
SelectionDialogBase(text_view, start_mark, false, false) {}
bool CompletionDialog::on_key_press(GdkEventKey* key) { return true;} bool CompletionDialog::on_key_press(GdkEventKey* key) { return true;}
bool CompletionDialog::on_key_release(GdkEventKey* key) {return true;}

14
tests/stubs/terminal.cc

@ -1,5 +1,17 @@
#include "terminal.h" #include "terminal.h"
Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {}
Terminal::InProgress::~InProgress() {}
std::shared_ptr<Terminal::InProgress> Terminal::print_in_progress(std::string start_msg) {
return std::make_shared<Terminal::InProgress>("");
}
void Terminal::InProgress::done(const std::string& msg) {}
void Terminal::InProgress::cancel(const std::string &msg) {}
Terminal::Terminal() {} Terminal::Terminal() {}
bool Terminal::on_motion_notify_event(GdkEventMotion* motion_event) {return false;} bool Terminal::on_motion_notify_event(GdkEventMotion* motion_event) {return false;}
@ -17,3 +29,5 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c
size_t Terminal::print(const std::string &message, bool bold) { size_t Terminal::print(const std::string &message, bool bold) {
return 0; return 0;
} }
void Terminal::async_print(const std::string &message, bool bold) {}

11
tests/stubs/tooltips.cc

@ -1,7 +1,16 @@
#include "tooltips.h" #include "tooltips.h"
Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle();
Tooltip::Tooltip(std::function<Glib::RefPtr<Gtk::TextBuffer>()> create_tooltip_buffer,
Gtk::TextView& text_view,
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark,
Glib::RefPtr<Gtk::TextBuffer::Mark> end_mark): text_view(text_view) {}
Tooltip::~Tooltip() {} Tooltip::~Tooltip() {}
Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle(); void Tooltips::show(Gdk::Rectangle const&, bool) {}
void Tooltips::show(bool) {}
void Tooltips::hide() {} void Tooltips::hide() {}

Loading…
Cancel
Save