aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthecharlesblake2017-10-05 00:04:52 +0100
committerthecharlesblake2017-10-13 18:46:14 +0100
commit33f3a5e1a340a96d2481d2ef62d12bb26fa8d1bb (patch)
treeff4939bbb8cab80f413697dbda84724d30dfc372
parentAdd release as well as debug build (diff)
downloadmetasol-33f3a5e1a340a96d2481d2ef62d12bb26fa8d1bb.tar.gz
metasol-33f3a5e1a340a96d2481d2ef62d12bb26fa8d1bb.zip

Add GTest library to build and basic unit tests

-rw-r--r--CMakeLists.txt24
-rw-r--r--build-instructions.md3
-rwxr-xr-xclean-build.sh6
-rw-r--r--conanfile.txt4
-rw-r--r--src/test/all_tests.cpp10
-rw-r--r--src/test/main_test.cpp19
6 files changed, 59 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d70caad..0ff92bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,9 +12,8 @@ set(CMAKE_CXX_STANDARD 14)
# these instructions search the directory tree when cmake is
# invoked and put all files that match the pattern in the variables
# `sources` and `data`
-file(GLOB_RECURSE sources src/main/*.cpp src/main/*.h)
-file(GLOB_RECURSE sources_test src/test/*.cpp)
-file(GLOB_RECURSE data resources/*)
+set(sources src/main/main.cpp)
+set(sources_test src/test/all_tests.cpp src/test/main_test.cpp)
###############################################################################
## conan.io setup #############################################################
@@ -32,7 +31,7 @@ endif()
###############################################################################
# add the data to the target, so it becomes visible in some IDE
-add_executable(solitaire_pip ${sources} ${data})
+add_executable(solitaire_pip ${sources})
# just for example add some compiler flags
target_compile_options(solitaire_pip PUBLIC -std=c++1y -Wall -Wfloat-conversion)
@@ -48,6 +47,23 @@ target_link_libraries(solitaire_pip ${CONAN_LIBS})
file(COPY ${data} DESTINATION resources)
###############################################################################
+## testing ####################################################################
+###############################################################################
+
+add_executable(unit_tests ${sources_test})
+
+# this allows us to use our executable as a link library
+# therefore we can inherit all compiler options and library dependencies
+set_target_properties(solitaire_pip PROPERTIES ENABLE_EXPORTS on)
+
+target_link_libraries(unit_tests ${CONAN_LIBS} solitaire_pip)
+
+ENABLE_TESTING()
+ADD_TEST(NAME unit_tests
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
+ COMMAND unit_tests)
+
+###############################################################################
## packaging ##################################################################
###############################################################################
diff --git a/build-instructions.md b/build-instructions.md
index 8ecb321..1240c7b 100644
--- a/build-instructions.md
+++ b/build-instructions.md
@@ -5,7 +5,8 @@ building the project, running the program, and creating an installer.
### Installing dependencies
-`cd cmake-build-[debug|release]; conan install ..; cd ..`
+`cd cmake-build-[debug|release]; conan install .. --build missing -s \
+compiler=gcc -s compiler.version=6.3 -s compiler.libcxx=libstdc++11; cd ..`
### Generate Build System
diff --git a/clean-build.sh b/clean-build.sh
index b9847a3..d566226 100755
--- a/clean-build.sh
+++ b/clean-build.sh
@@ -4,8 +4,10 @@ echo "Cleaning..."
rm -r cmake-build-release/*; rm -r cmake-build-debug/*
echo "Installing..."
-cd cmake-build-debug; conan install ..; cd ..
-cd cmake-build-release; conan install ..; cd ..
+cd cmake-build-debug; conan install .. --build missing -s compiler=gcc \
+ -s compiler.version=6.3 -s compiler.libcxx=libstdc++11; cd ..
+cd cmake-build-release; conan install .. --build missing -s compiler=gcc \
+ -s compiler.version=6.3 -s compiler.libcxx=libstdc++11; cd ..
echo "Generating build..."
cmake -Bcmake-build-debug -H.
diff --git a/conanfile.txt b/conanfile.txt
index 2bcb821..f181ce5 100644
--- a/conanfile.txt
+++ b/conanfile.txt
@@ -1,5 +1,9 @@
[requires]
Boost/1.60.0@lasote/stable
+gtest/1.8.0@lasote/stable
+
+[options]
+gtest:shared=False
[generators]
cmake
diff --git a/src/test/all_tests.cpp b/src/test/all_tests.cpp
new file mode 100644
index 0000000..7dce333
--- /dev/null
+++ b/src/test/all_tests.cpp
@@ -0,0 +1,10 @@
+//
+// Created by thecharlesblake on 10/4/17.
+//
+
+#include <gtest/gtest.h>
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/src/test/main_test.cpp b/src/test/main_test.cpp
new file mode 100644
index 0000000..3f2081f
--- /dev/null
+++ b/src/test/main_test.cpp
@@ -0,0 +1,19 @@
+//
+// Created by thecharlesblake on 10/4/17.
+//
+
+#include <gtest/gtest.h>
+
+const int actualValTrue = 4;
+const int actualValFalse = 8;
+const int expectVal = 4;
+
+namespace {
+ TEST(StrCompare, CStrEqual) {
+ EXPECT_EQ(expectVal, actualValTrue);
+ }
+
+ TEST(StrCompare, CStrNotEqual) {
+ EXPECT_NE(expectVal, actualValFalse);
+ }
+}