Skip to content

Commit

Permalink
Merge pull request #527 from makaylas/testing
Browse files Browse the repository at this point in the history
Gtest and a small example test
  • Loading branch information
krlberry authored Nov 6, 2018
2 parents a3e2b23 + 31dbbad commit 32fe49a
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "gtest"]
path = gtest
url = git@github.com:google/googletest.git
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- bullet==2.86.1=0
- bz2file==0.98
- bzip2==1.0.6=1
- cmake==3.9.1=0
- cmake>=3.10
- cspice==66=h470a237_3
- curl==7.60.0=0
- doxygen==1.8.14=0
Expand Down
2 changes: 1 addition & 1 deletion environment_gcc4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- bullet==2.86.1=0
- bz2file==0.98
- bzip2==1.0.6=1
- cmake==3.9.1=0
- cmake>=3.10
- cspice==66=h470a237_3
- curl==7.60.0=0
- doxygen==1.8.14=0
Expand Down
1 change: 1 addition & 0 deletions gtest
Submodule gtest added at 529c2c
17 changes: 13 additions & 4 deletions isis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Specify the required version of CMake. If your machine does not
# have this, it should be easy to build from https://cmake.org/download/
cmake_minimum_required(VERSION 3.4)
cmake_minimum_required(VERSION 3.10)

# Point cmake to our other CMake files.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
Expand All @@ -16,6 +16,8 @@ include(AddIsisModule)
include(Utilities)
include(TestSetup)
include(InstallThirdParty)
include(cmake/gtest.cmake)
include(GoogleTest)

#===============================================================================
#===============================================================================
Expand All @@ -28,15 +30,15 @@ set(PACKAGE "ISIS")
set(PACKAGE_NAME "USGS ISIS")

# Version number
set(VERSION "3.5.00.0")
set(VERSION "3.6.00.0")
set(PACKAGE_VERSION ${VERSION})

# Full name and version number
set(PACKAGE_STRING "${PACKAGE_NAME} ${VERSION}")

# Other release information
set(VERSION_DATE "2017-04-24")
set(THIRD_PARTY_LIBS_VERSION "v007")
set(VERSION_DATE "2018-11-09")
set(THIRD_PARTY_LIBS_VERSION "v008")
set(RELEASE_STAGE "alpha") # (alpha, beta, stable)

# Define to the address where bug reports for this package should be sent.
Expand Down Expand Up @@ -245,6 +247,7 @@ find_package(PNG REQUIRED)
find_package(Kakadu)
find_package(Geos 3.5.0 REQUIRED)
find_package(Armadillo REQUIRED)
find_package(Threads)

if(pybindings)
find_package(Python REQUIRED)
Expand Down Expand Up @@ -459,3 +462,9 @@ install(DIRECTORY ${CMAKE_SOURCE_DIR}/scripts DESTINATION ${CMAKE_INSTA
# the end of this file containing a CMakeLists.txt file which includes all of
# the desired post-install commands inside.
add_subdirectory(cmake)
option (BUILD_TESTS "Build tests" ON)
if(BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
4 changes: 2 additions & 2 deletions isis/cmake/AddIsisModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ function(add_isis_module name)
# - Base module depends on 3rd party libs, other libs also depend on base.
# - Only the base module gets both a static and shared library.
if(${name} STREQUAL ${CORE_LIB_NAME})
set(reqLibs ${ALLLIBS})
set(reqLibs "${ALLLIBS};gtest;${CMAKE_THREAD_LIBS_INIT}")
set(alsoStatic ON)
else()
set(reqLibs "${CORE_LIB_NAME};${ALLLIBS}")
set(reqLibs "${CORE_LIB_NAME};${ALLLIBS};gtest;${CMAKE_THREAD_LIBS_INIT}")
set(alsoStatic OFF)
endif()

Expand Down
19 changes: 19 additions & 0 deletions isis/cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
if (NOT TARGET gtest)
set(GOOGLETEST_ROOT ${CMAKE_SOURCE_DIR}/../gtest/googletest CACHE STRING "Google Test source root")

include_directories(SYSTEM
${GOOGLETEST_ROOT}
${GOOGLETEST_ROOT}/include
)

set(GOOGLETEST_SOURCES
${GOOGLETEST_ROOT}/src/gtest-all.cc
${GOOGLETEST_ROOT}/src/gtest_main.cc
)

foreach(_source ${GOOGLETEST_SOURCES})
set_source_files_properties(${_source} PROPERTIES GENERATED 1)
endforeach()

add_library(gtest ${GOOGLETEST_SOURCES})
endif()
11 changes: 11 additions & 0 deletions isis/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.10)

add_dependencies(isis3 isis3)

# Link runISISTests with what we want to test and the GTest and pthread library
add_executable(runISISTests
FileNameTests.cpp)

target_link_libraries(runISISTests isis3 ${ALLLIBS} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)

gtest_discover_tests(runISISTests WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../tests)
18 changes: 18 additions & 0 deletions isis/tests/FileNameTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "FileName.h"

#include <QString>

#include <gtest/gtest.h>


TEST(FileNameTests, BaseName) {
QString test = "test.log";
Isis::FileName file(test);

EXPECT_EQ("test", file.baseName());
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 32fe49a

Please # to comment.