Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit c8f7243

Browse files
committed
Added source_clang test, and tests cleanup
1 parent b60d6f5 commit c8f7243

12 files changed

Lines changed: 139 additions & 77 deletions

CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
cmake_minimum_required (VERSION 2.8.4)
1+
cmake_minimum_required (VERSION 2.8.8)
22

33
set(project_name juci)
44
project (${project_name})
55

66
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder")
7-
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
7+
if(CMAKE_BUILD_TYPE STREQUAL "")
88
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
99
endif()
1010

@@ -18,6 +18,22 @@ endif()
1818

1919
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/")
2020
find_package(LibClang REQUIRED)
21+
22+
#Find liblldb with the same version as the version of libclang found
23+
string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}")
24+
if(EXISTS "${LIBLLDB_LIBRARIES}")
25+
set(LIBLLDB_FOUND TRUE)
26+
elseif(EXISTS "${LIBLLDB_LIBRARIES}.1")
27+
set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1")
28+
set(LIBLLDB_FOUND TRUE)
29+
endif()
30+
if(LIBLLDB_FOUND)
31+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG")
32+
else()
33+
set(LIBLLDB_LIBRARIES "")
34+
message("liblldb not found. Building juCi++ without debugging support")
35+
endif()
36+
2137
find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED)
2238
find_package(ASPELL REQUIRED)
2339
include(FindPkgConfig)

src/CMakeLists.txt

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ if(MSYS)
1313
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSYS_PROCESS_USE_SH")
1414
endif()
1515

16-
string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}")
17-
if(EXISTS "${LIBLLDB_LIBRARIES}")
18-
set(LIBLLDB_FOUND TRUE)
19-
elseif(EXISTS "${LIBLLDB_LIBRARIES}.1")
20-
set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1")
21-
set(LIBLLDB_FOUND TRUE)
22-
endif()
23-
if(LIBLLDB_FOUND)
24-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG")
25-
else()
26-
set(LIBLLDB_LIBRARIES "")
27-
message("liblldb not found. Building juCi++ without debugging support")
28-
endif()
29-
3016
set(global_includes
3117
${Boost_INCLUDE_DIRS}
3218
${GTKMM_INCLUDE_DIRS}
@@ -38,54 +24,40 @@ set(global_includes
3824
)
3925

4026
set(global_libraries
41-
${LIBCLANG_LIBRARIES}
4227
${GTKMM_LIBRARIES}
4328
${GTKSVMM_LIBRARIES}
4429
${Boost_LIBRARIES}
45-
${ASPELL_LIBRARIES}
30+
${LIBCLANG_LIBRARIES}
4631
${LIBLLDB_LIBRARIES}
32+
${ASPELL_LIBRARIES}
4733
)
4834

4935
set(project_files
50-
cmake.cc
51-
cmake.h
5236
config.cc
53-
config.h
5437
dialogs.cc
55-
dialogs.h
5638
directories.cc
57-
directories.h
58-
dispatcher.cc
59-
dispatcher.h
6039
entrybox.cc
61-
entrybox.h
62-
files.h
63-
filesystem.cc
64-
filesystem.h
65-
info.h
6640
info.cc
6741
juci.cc
68-
juci.h
6942
menu.cc
70-
menu.h
7143
notebook.cc
72-
notebook.h
7344
project.cc
74-
project.h
75-
project_build.h
76-
project_build.cc
7745
selectiondialog.cc
78-
selectiondialog.h
79-
source.cc
80-
source.h
81-
source_clang.cc
82-
source_clang.h
8346
terminal.cc
84-
terminal.h
8547
tooltips.cc
86-
tooltips.h
8748
window.cc
88-
window.h
49+
50+
../tiny-process-library/process.cpp
51+
)
52+
53+
#Files used both in ../src and ../tests
54+
set(project_shared_files
55+
cmake.cc
56+
dispatcher.cc
57+
filesystem.cc
58+
project_build.cc
59+
source.cc
60+
source_clang.cc
8961

9062
../libclangmm/src/CodeCompleteResults.cc
9163
../libclangmm/src/CompilationDatabase.cc
@@ -101,11 +73,10 @@ set(project_files
10173
../libclangmm/src/Tokens.cc
10274
../libclangmm/src/TranslationUnit.cc
10375
../libclangmm/src/Utility.cc
104-
105-
../tiny-process-library/process.cpp)
76+
)
10677

10778
if(LIBLLDB_FOUND)
108-
list(APPEND project_files debug_clang.h debug_clang.cc)
79+
list(APPEND project_shared_files debug_clang.cc)
10980
endif()
11081

11182
if(MSYS)
@@ -116,11 +87,13 @@ endif()
11687

11788
include_directories(${global_includes})
11889

90+
add_library(project_shared ${project_shared_files})
91+
11992
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL ""))
12093
add_library(${project_name} OBJECT ${project_files})
12194
else()
12295
add_executable(${project_name} ${project_files})
123-
target_link_libraries(${project_name} ${global_libraries})
96+
target_link_libraries(${project_name} ${global_libraries} project_shared)
12497
install(TARGETS ${project_name}
12598
RUNTIME DESTINATION bin
12699
)

tests/CMakeLists.txt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,43 @@ set(global_includes
44
${Boost_INCLUDE_DIRS}
55
${GTKMM_INCLUDE_DIRS}
66
${GTKSVMM_INCLUDE_DIRS}
7+
${LIBCLANG_INCLUDE_DIRS}
78
${ASPELL_INCLUDE_DIR}
8-
../src
9+
../libclangmm/src
910
../tiny-process-library
11+
../src
1012
)
1113

1214
set(global_libraries
1315
${GTKMM_LIBRARIES}
1416
${GTKSVMM_LIBRARIES}
1517
${Boost_LIBRARIES}
18+
${LIBCLANG_LIBRARIES}
19+
${LIBLLDB_LIBRARIES}
1620
${ASPELL_LIBRARIES}
1721
)
1822

19-
set(stub_sources
23+
set(stub_files
2024
stubs/config.cc
2125
stubs/dialogs.cc
22-
stubs/dispatcher.cc
2326
stubs/info.cc
2427
stubs/selectiondialog.cc
2528
stubs/terminal.cc
2629
stubs/tooltips.cc
2730
)
2831

29-
include_directories(${global_includes})
32+
add_library(stubs ${stub_files})
3033

31-
add_library(stubs_library ${stub_sources})
34+
include_directories(${global_includes})
3235

33-
add_executable(cmake_build_test cmake_build_test.cc
34-
../src/filesystem.cc ../src/cmake.cc ../src/project_build.cc)
35-
target_link_libraries(cmake_build_test ${global_libraries} stubs_library)
36+
add_executable(cmake_build_test cmake_build_test.cc)
37+
target_link_libraries(cmake_build_test ${global_libraries} project_shared stubs)
3638
add_test(cmake_build_test cmake_build_test)
3739

38-
add_executable(source_test source_test.cc
39-
../src/source.cc)
40-
target_link_libraries(source_test ${global_libraries} stubs_library)
40+
add_executable(source_test source_test.cc)
41+
target_link_libraries(source_test ${global_libraries} project_shared stubs)
4142
add_test(source_test source_test)
43+
44+
add_executable(source_clang_test source_clang_test.cc)
45+
target_link_libraries(source_clang_test ${global_libraries} project_shared stubs)
46+
add_test(source_clang_test source_clang_test)

tests/clang_project/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(project_name hello)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"directory": "build",
4+
"command": "c++ -std=c++1y -Wall -Wextra -Wno-unused-parameter main.cpp",
5+
"file": "main.cpp"
6+
}
7+
]

tests/clang_project/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <iostream>
2+
3+
int main() {
4+
std::cout << "hello world\n";
5+
}

tests/source_clang_test.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <glib.h>
2+
#include "source_clang.h"
3+
#include "config.h"
4+
#include "filesystem.h"
5+
6+
std::string hello_world_error=R"(#include <iostream>
7+
8+
int main() {
9+
std::cout << "hello world\n"
10+
}
11+
)";
12+
13+
//Requires display server to work
14+
//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment:
15+
//broadwayd&
16+
//make test
17+
18+
int main() {
19+
auto app=Gtk::Application::create();
20+
Gsv::init();
21+
22+
Config::get().project.default_build_path="./build";
23+
Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/clang_project/main.cpp"),
24+
Gsv::LanguageManager::get_default()->get_language("cpp"));
25+
while(!clang_view->parsed) {
26+
while(Gtk::Main::events_pending())
27+
Gtk::Main::iteration(false);
28+
}
29+
g_assert(clang_view->diagnostics.size()==0);
30+
clang_view->get_buffer()->set_text(hello_world_error);
31+
while(Gtk::Main::events_pending())
32+
Gtk::Main::iteration(false);
33+
while(!clang_view->parsed) {
34+
while(Gtk::Main::events_pending())
35+
Gtk::Main::iteration(false);
36+
}
37+
g_assert(clang_view->diagnostics.size()>0);
38+
39+
clang_view->async_delete();
40+
clang_view->delete_thread.join();
41+
while(Gtk::Main::events_pending())
42+
Gtk::Main::iteration(false);
43+
}

tests/source_test.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22
#include "source.h"
33
#include "filesystem.h"
44

5-
int filesystem::read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
6-
return 0;
7-
}
8-
9-
int filesystem::read_non_utf8(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
10-
return 0;
11-
}
12-
13-
bool filesystem::write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) {
14-
return false;
15-
}
16-
175
std::string hello_world=R"(#include <iostream>
186
197
int main() {

tests/stubs/dispatcher.cc

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/stubs/selectiondialog.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ SelectionDialog::SelectionDialog(Gtk::TextView& text_view, Glib::RefPtr<Gtk::Tex
1717
SelectionDialogBase::~SelectionDialogBase() {}
1818

1919
bool SelectionDialog::on_key_press(GdkEventKey* key) { return true; }
20+
21+
CompletionDialog::CompletionDialog(Gtk::TextView &text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark):
22+
SelectionDialogBase(text_view, start_mark, false, false) {}
23+
2024
bool CompletionDialog::on_key_press(GdkEventKey* key) { return true;}
25+
26+
bool CompletionDialog::on_key_release(GdkEventKey* key) {return true;}

0 commit comments

Comments
 (0)