diff --git a/CMakeLists.txt b/CMakeLists.txt index da070a0..3cca56d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project (ccsh) option(WITH_LIB "Compile shared library." ON) option(WITH_CLING "Compile cling front-end (interactive shell) as well, requires cling at /opt/cling." ON) +option(WITH_SAMPLE "Compile sample code as well, not required for release." ON) option(WITH_TEST "Compile test code as well, not required for release." ON) option(BOOST_FILESYSTEM "Use boost::filesystem instead of std::[experimental::]filesystem" OFF) @@ -22,6 +23,10 @@ if(WITH_LIB) add_subdirectory(lib) endif() +if(WITH_SAMPLE) + add_subdirectory(sample) +endif() + if(WITH_TEST) add_subdirectory(test) endif() diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt new file mode 100644 index 0000000..8530e67 --- /dev/null +++ b/sample/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required (VERSION 2.6) + +add_subdirectory(./../lib ccsh_lib) + +include_directories(${SHARED_LIB_INCLUDE_DIR}) +include_directories(${WRAPPERS_INCLUDE_DIR}) + +file(GLOB_RECURSE wrappers ../wrappers/*.hpp) + +add_executable(ccsh_sample main.cpp ${wrappers}) +target_link_libraries( ccsh_sample PUBLIC ccsh_lib ${filesystem_lib}) +target_compile_options(ccsh_sample PUBLIC -std=c++11 -Wall -Wextra -pedantic -O0 -g -ggdb) diff --git a/test/main.cpp b/sample/main.cpp similarity index 100% rename from test/main.cpp rename to sample/main.cpp diff --git a/test/vars b/sample/vars similarity index 100% rename from test/vars rename to sample/vars diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ef4b546..8fd5ce2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,7 +6,12 @@ include_directories(${SHARED_LIB_INCLUDE_DIR}) include_directories(${WRAPPERS_INCLUDE_DIR}) file(GLOB_RECURSE wrappers ../wrappers/*.hpp) +file(GLOB_RECURSE tests test*.cpp) -add_executable(ccsh_test main.cpp ${wrappers}) -target_link_libraries( ccsh_test PUBLIC ccsh_lib ${filesystem_lib}) +enable_testing() +find_package(GTest REQUIRED) +include_directories(${GTEST_INCLUDE_DIRS}) + +add_executable(ccsh_test ${tests} ${wrappers}) +target_link_libraries( ccsh_test PUBLIC ccsh_lib ${filesystem_lib} ${GTEST_BOTH_LIBRARIES}) target_compile_options(ccsh_test PUBLIC -std=c++11 -Wall -Wextra -pedantic -O0 -g -ggdb) diff --git a/test/test1.cpp b/test/test1.cpp new file mode 100644 index 0000000..2e6e9d0 --- /dev/null +++ b/test/test1.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include + +using namespace ccsh; + +std::string ReadAllText(fs::path filename) +{ + std::ifstream t(filename.c_str()); + return std::string(std::istreambuf_iterator(t), + std::istreambuf_iterator()); +} + +TEST(NativeTest, CopyRemoveFile) +{ + fs::path example_path1{__FILE__}; + fs::path example_path2 = example_path1.parent_path() / "example1.file"; + + std::string example_content1 = ReadAllText(example_path1); + EXPECT_NE(example_content1, ""); + + shell("rm", {example_path2.string()}); + EXPECT_EQ(fs::exists(example_path2), false); + + shell("cp", {example_path1.string(), example_path2.string()}); + EXPECT_EQ(fs::exists(example_path2), true); + + fs::path example_content2 = ReadAllText(example_path2); + EXPECT_EQ(example_content1, example_content2); + + shell("rm", {example_path2.string()}); + EXPECT_EQ(fs::exists(example_path2), false); +} + diff --git a/test/test2.cpp b/test/test2.cpp new file mode 100644 index 0000000..ca12fe6 --- /dev/null +++ b/test/test2.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +#include + +using namespace ccsh; + +TEST(DummyTest, Dummy) +{ + EXPECT_EQ(true, true); +}