mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-09 05:19:55 -05:00
tests: merge build of tests within main build
Instead of a separate CMakeLists.txt for the tests, make them built together with the rest of the main project. This behaviour is off by default, and can be enabled using ENABLE_TESTING. Furthermore, the testing facilities of cmake are now used, so ctest (invoked by `make test`) knows about the sqlb-unittests. Thus, adapt the Travis build steps, building the main sources and executing the tests twice, one for sqlite and one for sqlcipher.
This commit is contained in:
+5
-8
@@ -9,19 +9,16 @@ before_install:
|
||||
- sudo apt-get install -qq libqt4-dev libsqlite3-dev libsqlcipher-dev
|
||||
|
||||
script:
|
||||
- mkdir tests/build
|
||||
- mkdir build
|
||||
- mkdir build_cipher
|
||||
- cd tests/build
|
||||
- cmake ..
|
||||
- make
|
||||
- ./sqlb-unittests
|
||||
- cd ../../build
|
||||
- cmake ..
|
||||
- cd build
|
||||
- cmake -DENABLE_TESTING=ON ..
|
||||
- make
|
||||
- ctest -V
|
||||
- cd ../build_cipher
|
||||
- cmake -Dsqlcipher=1 ..
|
||||
- cmake -DENABLE_TESTING=ON -Dsqlcipher=1 ..
|
||||
- make
|
||||
- ctest -V
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
@@ -2,6 +2,7 @@ project(sqlitebrowser)
|
||||
cmake_minimum_required(VERSION 2.8.7)
|
||||
|
||||
OPTION(USE_QT5 FALSE "Build with qt5")
|
||||
OPTION(ENABLE_TESTING FALSE "Enable the unit tests")
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
@@ -42,6 +43,10 @@ else()
|
||||
add_definitions(${QT_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
if(ENABLE_TESTING)
|
||||
enable_testing()
|
||||
endif()
|
||||
|
||||
set(SQLB_HDR
|
||||
src/gen_version.h
|
||||
src/sqlitetypes.h
|
||||
@@ -260,6 +265,11 @@ install(TARGETS ${PROJECT_NAME}
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib)
|
||||
|
||||
|
||||
if(ENABLE_TESTING)
|
||||
add_subdirectory(src/tests)
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
install(FILES src/icons/${PROJECT_NAME}.png
|
||||
DESTINATION share/icons/hicolor/256x256/apps/)
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
if(USE_QT5)
|
||||
else()
|
||||
find_package(Qt4 COMPONENTS QtTest REQUIRED)
|
||||
include("${QT_USE_FILE}")
|
||||
add_definitions(${QT_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
set(SQLB_UNITTESTS_SRC
|
||||
../sqlitedb.cpp
|
||||
../sqlitetablemodel.cpp
|
||||
../sqlitetypes.cpp
|
||||
../csvparser.cpp
|
||||
../grammar/Sqlite3Lexer.cpp
|
||||
../grammar/Sqlite3Parser.cpp
|
||||
../PreferencesDialog.cpp
|
||||
TestImport.cpp
|
||||
testsqlobjects.cpp
|
||||
TestMain.cpp
|
||||
../FileDialog.cpp
|
||||
)
|
||||
|
||||
set(SQLB_UNITTESTS_HDR
|
||||
../grammar/sqlite3TokenTypes.hpp
|
||||
../grammar/Sqlite3Lexer.hpp
|
||||
../grammar/Sqlite3Parser.hpp
|
||||
../csvparser.h
|
||||
../sqlitetypes.h)
|
||||
|
||||
set(SQLB_UNITTESTS_FORMS
|
||||
../PreferencesDialog.ui)
|
||||
|
||||
set(SQLB_UNITTESTS_MOC_HDR
|
||||
../sqlitedb.h
|
||||
../sqlitetablemodel.h
|
||||
../PreferencesDialog.h
|
||||
TestImport.h
|
||||
testsqlobjects.h
|
||||
../FileDialog.h
|
||||
)
|
||||
|
||||
if(sqlcipher)
|
||||
list(APPEND SQLB_UNITTESTS_SRC ../CipherDialog.cpp)
|
||||
list(APPEND SQLB_UNITTESTS_FORMS ../CipherDialog.ui)
|
||||
list(APPEND SQLB_UNITTESTS_MOC_HDR ../CipherDialog.h)
|
||||
endif()
|
||||
|
||||
if(USE_QT5)
|
||||
QT5_WRAP_UI(SQLB_UNITTESTS_FORM_HDR ${SQLB_UNITTESTS_FORMS})
|
||||
else()
|
||||
QT4_WRAP_CPP(SQLB_UNITTESTS_MOC ${SQLB_UNITTESTS_MOC_HDR})
|
||||
QT4_WRAP_UI(SQLB_UNITTESTS_FORM_HDR ${SQLB_UNITTESTS_FORMS})
|
||||
endif()
|
||||
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${ANTLR_DIR}" ..)
|
||||
|
||||
add_executable(sqlb-unittests ${SQLB_UNITTESTS_MOC} ${SQLB_UNITTESTS_HDR} ${SQLB_UNITTESTS_SRC} ${SQLB_UNITTESTS_FORM_HDR})
|
||||
|
||||
if(USE_QT5)
|
||||
qt5_use_modules(sqlb-unittests Test Widgets Gui)
|
||||
set(QT_LIBRARIES "")
|
||||
endif()
|
||||
|
||||
add_dependencies(sqlb-unittests antlr)
|
||||
target_link_libraries(sqlb-unittests antlr ${QT_LIBRARIES} ${LIBSQLITE})
|
||||
add_test(sqlb-unittests sqlb-unittests)
|
||||
@@ -1,84 +0,0 @@
|
||||
project(sqlb-unittests)
|
||||
cmake_minimum_required(VERSION 2.8.7)
|
||||
|
||||
OPTION(USE_QT5 FALSE "Build with qt5")
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
set(ANTLR_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../libs/antlr-2.7.7")
|
||||
add_subdirectory("${ANTLR_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/antlr")
|
||||
|
||||
if(USE_QT5)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
else()
|
||||
find_package(Qt4 COMPONENTS QtCore QtTest QtGui REQUIRED)
|
||||
include("${QT_USE_FILE}")
|
||||
add_definitions(${QT_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
# add extra library path for MacOS
|
||||
if(APPLE)
|
||||
find_library(LIBSQLITE sqlite3 HINTS /usr/local/lib /usr/local/opt/sqlite/lib)
|
||||
set(ADDITIONAL_INCLUDE_PATHS /usr/local/include /usr/local/opt/sqlite/include)
|
||||
else(APPLE)
|
||||
find_library(LIBSQLITE sqlite3)
|
||||
endif(APPLE)
|
||||
|
||||
set(SQLB_SRC
|
||||
../src/sqlitedb.cpp
|
||||
../src/sqlitetablemodel.cpp
|
||||
../src/sqlitetypes.cpp
|
||||
../src/csvparser.cpp
|
||||
../src/grammar/Sqlite3Lexer.cpp
|
||||
../src/grammar/Sqlite3Parser.cpp
|
||||
../src/PreferencesDialog.cpp
|
||||
../src/tests/TestImport.cpp
|
||||
../src/tests/testsqlobjects.cpp
|
||||
../src/tests/TestMain.cpp
|
||||
../src/FileDialog.cpp
|
||||
)
|
||||
|
||||
set(SQLB_HDR
|
||||
../src/grammar/sqlite3TokenTypes.hpp
|
||||
../src/grammar/Sqlite3Lexer.hpp
|
||||
../src/grammar/Sqlite3Parser.hpp
|
||||
../src/csvparser.h
|
||||
../src/sqlitetypes.h)
|
||||
|
||||
set(SQLB_FORMS
|
||||
../src/PreferencesDialog.ui)
|
||||
|
||||
set(SQLB_MOC_HDR
|
||||
../src/sqlitedb.h
|
||||
../src/sqlitetablemodel.h
|
||||
../src/PreferencesDialog.h
|
||||
../src/tests/TestImport.h
|
||||
../src/tests/testsqlobjects.h
|
||||
../src/FileDialog.h
|
||||
)
|
||||
|
||||
if(USE_QT5)
|
||||
QT5_WRAP_CPP(SQLB_MOC ${SQLB_MOC_HDR})
|
||||
QT5_WRAP_UI(SQLB_FORM_HDR ${SQLB_FORMS})
|
||||
else()
|
||||
QT4_WRAP_CPP(SQLB_MOC ${SQLB_MOC_HDR})
|
||||
QT4_WRAP_UI(SQLB_FORM_HDR ${SQLB_FORMS})
|
||||
endif()
|
||||
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${ANTLR_DIR}" ../src)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SQLB_MOC} ${SQLB_HDR} ${SQLB_SRC} ${SQLB_FORM_HDR})
|
||||
|
||||
if(USE_QT5)
|
||||
qt5_use_modules(${PROJECT_NAME} Test Widgets Gui)
|
||||
set(QT_LIBRARIES "")
|
||||
endif()
|
||||
|
||||
add_dependencies(${PROJECT_NAME} antlr)
|
||||
target_link_libraries(${PROJECT_NAME} antlr ${QT_LIBRARIES} ${LIBSQLITE})
|
||||
|
||||
MESSAGE(STATUS "Build type is ${CMAKE_BUILD_TYPE}")
|
||||
Reference in New Issue
Block a user