diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 8db55b9..8c3f607 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -41,7 +41,7 @@ jobs: # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=ON - name: Build working-directory: ${{runner.workspace}}/build @@ -66,37 +66,44 @@ jobs: - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, - cc: "gcc-10", cxx: "g++-10" + cc: "gcc-10", cxx: "g++-10", + build-file-system: 'ON' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, - cc: "gcc-9", cxx: "g++-9" + cc: "gcc-9", cxx: "g++-9", + build-file-system: 'ON' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, - cc: "gcc-8", cxx: "g++-8" + cc: "gcc-8", cxx: "g++-8", + build-file-system: 'ON' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, - cc: "gcc-7", cxx: "g++-7" + cc: "gcc-7", cxx: "g++-7", + build-file-system: 'OFF' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, - cc: "gcc-6", cxx: "g++-6" + cc: "gcc-6", cxx: "g++-6", + build-file-system: 'OFF' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, - cc: "gcc-5", cxx: "g++-5" + cc: "gcc-5", cxx: "g++-5", + build-file-system: 'OFF' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, - cc: "gcc-4.8", cxx: "g++-4.8" + cc: "gcc-4.8", cxx: "g++-4.8", + build-file-system: 'OFF' } steps: - uses: actions/checkout@v2 @@ -120,7 +127,7 @@ jobs: # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=${{matrix.config.build-file-system}} env: CC: ${{matrix.config.cc}} CXX: ${{matrix.config.cxx}} @@ -149,36 +156,43 @@ jobs: name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, clang-version: "4.0", + build-file-system: 'OFF' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, clang-version: "5.0", + build-file-system: 'OFF' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, clang-version: "6.0", + build-file-system: 'OFF' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, clang-version: "7", + build-file-system: 'OFF' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, clang-version: "8", + build-file-system: 'ON' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, clang-version: "9", + build-file-system: 'ON' } - { name: "Ubuntu 18.04", artifact: "Linux.7z", os: ubuntu-18.04, clang-version: "10", + build-file-system: 'ON' } steps: - uses: actions/checkout@v2 @@ -204,7 +218,7 @@ jobs: # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=${{matrix.config.build-file-system}} - name: Build working-directory: ${{runner.workspace}}/build shell: bash @@ -228,12 +242,14 @@ jobs: - { name: "MacOS 11", artifact: "macos.7z", os: macos-11, - cc: "clang", cxx: "clang++" + cc: "clang", cxx: "clang++", + build-file-system: 'ON' } - { name: MacOS 12", artifact: "macos.7z", os: macos-12, - cc: "clang", cxx: "clang++" + cc: "clang", cxx: "clang++", + build-file-system: 'ON' } steps: - uses: actions/checkout@v2 @@ -251,7 +267,7 @@ jobs: # Note the current convention is to use the -S and -B options here to specify source # and build directories, but this is only available with CMake 3.13 and higher. # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DFileWatch_Build_Tests=ON -DFileWatch_Build_Tests_FileSystem=${{matrix.config.build-file-system}} env: CC: ${{matrix.config.cc}} CXX: ${{matrix.config.cxx}} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a268acd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,85 @@ +{ + "cmake.configureOnOpen": true, + "cmake.configureSettings": { + "FileWatch_Build_Example": "ON", + "FileWatch_Build_Tests": "ON", + "FileWatch_Build_Tests_FileSystem": "ON" + }, + "files.associations": { + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "filesystem": "cpp", + "format": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "regex": "cpp", + "set": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "utility": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4297df4..744a031 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,9 @@ cmake_minimum_required(VERSION 3.1) # Project name project( FileWatch VERSION 0.0.1 LANGUAGES C CXX) -option(BuildTests "Build the unit tests" ON) +option(FileWatch_Build_Example "Build the example") +option(FileWatch_Build_Tests "Build the unit tests") +option(FileWatch_Build_Tests_FileSystem "Build the unit c++17 > filesystem tests") enable_testing() # Enable c++11 @@ -18,8 +20,8 @@ else() endif() if(APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CoreServices") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CoreServices") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") endif() # dial up the warnings @@ -36,9 +38,11 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic") endif() + # create and configure the unit test target -if(BuildTests) - add_subdirectory(tests) -endif() +add_subdirectory(tests) -# add_subdirectory(example) + +if(FileWatch_Build_Example) + add_subdirectory(example) +endif() diff --git a/FileWatch.hpp b/FileWatch.hpp index 4eba08b..a9e4ce2 100644 --- a/FileWatch.hpp +++ b/FileWatch.hpp @@ -87,6 +87,10 @@ #include #include +#ifdef __cpp_lib_filesystem +#include +#endif + #ifdef FILEWATCH_PLATFORM_MAC extern "C" int __getdirentries64(int, char *, int, long *); #endif // FILEWATCH_PLATFORM_MAC @@ -659,6 +663,22 @@ namespace filewatch { } #endif // __unix__ + template + struct absolute_path_of_helper { + static StringType get(const char* buf) { + return StringType{buf}; + } + }; + +#ifdef __cpp_lib_filesystem + template<> + struct absolute_path_of_helper { + static std::filesystem::path get(const char* buf) { + return std::filesystem::u8path(buf); + } + }; +#endif + #if FILEWATCH_PLATFORM_MAC static StringType absolute_path_of(const StringType& path) { char buf[PATH_MAX]; @@ -684,12 +704,11 @@ namespace filewatch { close(fd); if (IsWChar::value) { - size_t needed = mbsrtowcs(nullptr, &str, 0, &state) + 1; - StringType s; - - s.reserve(needed); - mbsrtowcs((wchar_t*)&s[0], &str, s.size(), &state); - return s; + std::mbstate_t state = std::mbstate_t(); + size_t needed = std::mbsrtowcs(nullptr, &str, 0, &state) + 1; + std::wstring s(needed, L'\0'); + std::mbsrtowcs(&s[0], &str, s.size(), &state); + return StringType {s}; } return StringType {buf}; } @@ -715,12 +734,11 @@ namespace filewatch { } if (IsWChar::value) { - size_t needed = mbsrtowcs(nullptr, &str, 0, &state) + 1; - StringType s; - - s.reserve(needed); - mbsrtowcs((wchar_t*)&s[0], &str, s.size(), &state); - return s; + std::mbstate_t state = std::mbstate_t(); + size_t needed = std::mbsrtowcs(nullptr, &str, 0, &state) + 1; + std::wstring s(needed, L'\0'); + std::mbsrtowcs(&s[0], &str, s.size(), &state); + return StringType {s}; } return StringType {buf}; } @@ -738,7 +756,7 @@ namespace filewatch { size / sizeof(TCHAR), buf, nullptr); - return StringType{(C*)buf, length}; + return StringType{std::basic_string((C*)buf, length)}; } #endif diff --git a/README.md b/README.md index a74f92b..b805714 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Single header folder/file watcher in C++11 for windows and linux, with optional Drop [FileWatch.hpp](https://github.com/ThomasMonkman/filewatch/blob/master/FileWatch.hpp) in to your include path, and you should be good to go. #### Compiler Support: - + Works on: -- Clang 4 and higher -- GCC 4.8 and higher +- Clang 4 and higher +- GCC 4.8 and higher - Visual Studio 2015 and higher should be supported, however only 2019 is on the ci and tested #### Examples: @@ -29,7 +29,7 @@ On linux or none unicode windows change std::wstring for std::string or std::fil ###### Simple: ```cpp filewatch::FileWatch watch( - L"C:/Users/User/Desktop/Watch/Test"s, + L"C:/Users/User/Desktop/Watch/Test"s, [](const std::wstring& path, const filewatch::Event change_type) { std::wcout << path << L"\n"; } @@ -39,7 +39,7 @@ filewatch::FileWatch watch( ###### Change Type: ```cpp filewatch::FileWatch watch( - L"C:/Users/User/Desktop/Watch/Test"s, + L"C:/Users/User/Desktop/Watch/Test"s, [](const std::wstring& path, const filewatch::Event change_type) { std::wcout << path << L" : "; switch (change_type) @@ -80,9 +80,9 @@ filewatch::FileWatch watch( ###### Using std::filesystem: ```cpp filewatch::FileWatch watch( - L"C:/Users/User/Desktop/Watch/Test"s, + L"C:/Users/User/Desktop/Watch/Test"s, [](const std::filesystem::path& path, const filewatch::Event change_type) { - std::wcout << std::filesystem::absolute(path) << L"\n"; + std::wcout << std::filesystem::absolute(path) << L"\n"; } ); ``` @@ -90,9 +90,9 @@ filewatch::FileWatch watch( ###### Works with relative paths: ```cpp filewatch::FileWatch watch( - L"./"s, + L"./"s, [](const std::filesystem::path& path, const filewatch::Event change_type) { - std::wcout << std::filesystem::absolute(path) << L"\n"; + std::wcout << std::filesystem::absolute(path) << L"\n"; } ); ``` @@ -100,9 +100,9 @@ filewatch::FileWatch watch( ###### Single file watch: ```cpp filewatch::FileWatch watch( - L"./test.txt"s, + L"./test.txt"s, [](const std::wstring& path, const filewatch::Event change_type) { - std::wcout << path << L"\n"; + std::wcout << path << L"\n"; } ); ``` diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 0c00332..2fa48b2 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,3 +1,5 @@ +set(CMAKE_CXX_STANDARD 11) + add_executable( main main.cpp diff --git a/example/main.cpp b/example/main.cpp index 89661fe..8eb1590 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -1,17 +1,19 @@ +#include #include #include #include #include -int main() { - filewatch::FileWatch watch { - ".", - [] (const std::string& path, const filewatch::Event event) { - std::cout << path << ' ' << filewatch::event_to_string(event) << '\n'; - } - }; +int main() +{ + filewatch::FileWatch watch( + ".", + [](const std::filesystem::path& path, const filewatch::Event change_type) { + std::cout << path << "\n"; + } + ); - while (true) { + while (true) { - } -} + } +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c85a50d..6dae475 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,26 +1,11 @@ #include catch add_library(Catch INTERFACE) -target_include_directories(Catch INTERFACE ${PROJECT_SOURCE_DIR}/tests/catch/catch.hpp) +target_include_directories(Catch INTERFACE ${PROJECT_SOURCE_DIR}/tests/catch) -#add tests -set(FILEWATCH_UNIT_TEST_TARGET_NAME "filewatch_unit") -add_executable(${FILEWATCH_UNIT_TEST_TARGET_NAME} - ${PROJECT_SOURCE_DIR}/tests/CatchMain.cpp - ${PROJECT_SOURCE_DIR}/tests/Test.cpp) +if(FileWatch_Build_Tests) + add_subdirectory(string) +endif() -#target_compile_features(${FILEWATCH_UNIT_TEST_TARGET_NAME} PRIVATE cxx_std_14) - -#enable pthreads for linux -set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Threads REQUIRED) - -target_link_libraries(${FILEWATCH_UNIT_TEST_TARGET_NAME} - Catch - Threads::Threads) - -add_test(NAME "${FILEWATCH_UNIT_TEST_TARGET_NAME}_default" - COMMAND ${FILEWATCH_UNIT_TEST_TARGET_NAME} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) - -install(TARGETS ${FILEWATCH_UNIT_TEST_TARGET_NAME} DESTINATION ${PROJECT_BINARY_DIR}/bin) \ No newline at end of file +if(FileWatch_Build_Tests_FileSystem) + add_subdirectory(filesystem) +endif() \ No newline at end of file diff --git a/tests/filesystem/CMakeLists.txt b/tests/filesystem/CMakeLists.txt new file mode 100644 index 0000000..8bf3b07 --- /dev/null +++ b/tests/filesystem/CMakeLists.txt @@ -0,0 +1,24 @@ +#add tests +set(CMAKE_CXX_STANDARD 17) + +set(FILEWATCH_UNIT_TEST_FILESYSTEM_TARGET_NAME "filewatch_unit_filesystem") +add_executable(${FILEWATCH_UNIT_TEST_FILESYSTEM_TARGET_NAME} + ${PROJECT_SOURCE_DIR}/tests/CatchMain.cpp + ${PROJECT_SOURCE_DIR}/tests/filesystem/Test.cpp) + +#target_compile_features(${FILEWATCH_UNIT_TEST_FILESYSTEM_TARGET_NAME} PRIVATE cxx_std_14) + +#enable pthreads for linux +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + +target_link_libraries(${FILEWATCH_UNIT_TEST_FILESYSTEM_TARGET_NAME} + Catch + Threads::Threads) + +add_test(NAME "${FILEWATCH_UNIT_TEST_FILESYSTEM_TARGET_NAME}_default" + COMMAND ${FILEWATCH_UNIT_TEST_FILESYSTEM_TARGET_NAME} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + +install(TARGETS ${FILEWATCH_UNIT_TEST_FILESYSTEM_TARGET_NAME} DESTINATION ${PROJECT_BINARY_DIR}/bin) \ No newline at end of file diff --git a/tests/filesystem/Test.cpp b/tests/filesystem/Test.cpp new file mode 100644 index 0000000..b1b01bb --- /dev/null +++ b/tests/filesystem/Test.cpp @@ -0,0 +1,167 @@ +#include +#include +#ifdef _WIN32 +#define _UNICODE +#define UNICODE +using test_string = std::wstring; +using test_char = wchar_t*; +using test_regex = std::wregex; +#endif // _WIN32 + +#if __unix__ || __APPLE__ +using test_string = std::string; +using test_char = char*; +using test_regex = std::regex; +#endif // __unix__ + +#include + +#include "../../FileWatch.hpp" + +#include "../Util/TestHelper.hpp" + +#include +#include +#include +#include +#include +#include +#include + +TEST_CASE("watch for file add", "[added]") { + const auto test_folder_path = std::filesystem::path("./"); + const auto test_file_name = std::filesystem::path("test.txt"); + + std::promise promise; + std::future future = promise.get_future(); + filewatch::FileWatch watch(test_folder_path, [&promise](const std::filesystem::path& path, const filewatch::Event change_type) { + promise.set_value(path); + }); + + testhelper::create_and_modify_file(test_file_name); + + auto path = testhelper::get_with_timeout(future); + REQUIRE(path == test_file_name); +} + +// TEST_CASE("single file", "[single-file]") { +// const auto test_folder_path = testhelper::cross_platform_string("./test.txt"); +// const auto test_ignore_path = testhelper::cross_platform_string("./ignore.txt"); +// const auto test_file_name = testhelper::cross_platform_string("test.txt"); +// // create the file otherwise the Filewatch will throw +// testhelper::create_and_modify_file(test_file_name); + +// std::promise promise; +// std::future future = promise.get_future(); + +// filewatch::FileWatch watch(test_folder_path, [&promise, &test_file_name](const test_string& path, const filewatch::Event change_type) { +// REQUIRE(path == test_file_name); +// promise.set_value(path); +// }); + +// testhelper::create_and_modify_file(test_ignore_path); +// testhelper::create_and_modify_file(test_file_name); + +// auto path = testhelper::get_with_timeout(future); +// REQUIRE(path == test_file_name); +// } + + +// TEST_CASE("copy constructor", "[constructors]") { +// const auto test_folder_path = testhelper::cross_platform_string("./"); +// const auto test_file_name = testhelper::cross_platform_string("test.txt"); + +// std::promise promise; +// std::future future = promise.get_future(); +// std::vector files_triggered; +// std::set file_watch_threads; +// std::mutex mutex; +// const auto expected_triggers = 2u; + +// filewatch::FileWatch watch(test_folder_path, [&promise, &files_triggered, &file_watch_threads, &expected_triggers, &mutex](const test_string& path, const filewatch::Event change_type) { +// std::lock_guard lock(mutex); +// file_watch_threads.insert(std::this_thread::get_id()); +// files_triggered.push_back(path); +// if (file_watch_threads.size() == expected_triggers) { +// promise.set_value(); +// } +// }); + +// filewatch::FileWatch watch2(watch); + +// testhelper::create_and_modify_file(test_file_name); + +// testhelper::get_with_timeout(future); +// const auto files_match = std::all_of(files_triggered.begin(), files_triggered.end(), [&test_file_name](const test_string& path) { return path == test_file_name; }); +// REQUIRE(files_match); +// } + + +// TEST_CASE("copy assignment operator", "[operator]") { +// const auto test_folder_path = testhelper::cross_platform_string("./"); +// const auto test_file_name = testhelper::cross_platform_string("test.txt"); + +// std::promise promise; +// std::future future = promise.get_future(); +// std::vector files_triggered; +// std::set file_watch_threads; +// std::mutex mutex; +// const auto expected_triggers = 2u; + +// filewatch::FileWatch watch(test_folder_path, [&promise, &files_triggered, &file_watch_threads, &expected_triggers, &mutex](const test_string& path, const filewatch::Event change_type) { +// std::lock_guard lock(mutex); +// file_watch_threads.insert(std::this_thread::get_id()); +// files_triggered.push_back(path); +// if (file_watch_threads.size() == expected_triggers) { +// promise.set_value(); +// } +// }); + +// filewatch::FileWatch watch2 = watch; + +// testhelper::create_and_modify_file(test_file_name); + +// testhelper::get_with_timeout(future); +// const auto files_match = std::all_of(files_triggered.begin(), files_triggered.end(), [&test_file_name](const test_string& path) { return path == test_file_name; }); +// REQUIRE(files_match); +// } + +// TEST_CASE("regex", "[regex]") { +// const auto test_folder_path = testhelper::cross_platform_string("./"); +// const auto test_ignore_path = testhelper::cross_platform_string("./ignore.txt"); +// const auto test_file_name = testhelper::cross_platform_string("test.txt"); +// // create the file otherwise the Filewatch will throw +// testhelper::create_and_modify_file(test_file_name); + +// std::promise promise; +// std::future future = promise.get_future(); + +// filewatch::FileWatch watch(test_folder_path, test_regex(testhelper::cross_platform_string("test.*")),[&promise, &test_file_name](const test_string& path, const filewatch::Event change_type) { +// REQUIRE(path == test_file_name); +// promise.set_value(path); +// }); + +// testhelper::create_and_modify_file(test_ignore_path); +// testhelper::create_and_modify_file(test_file_name); + +// auto path = testhelper::get_with_timeout(future); +// REQUIRE(path == test_file_name); +// } + +#ifdef _WIN32 +//TEST_CASE("base type", "[char]") { +// const auto test_folder_path = _T("./"); +// const auto test_file_name = _T("test.txt"); +// +// std::promise promise; +// std::future future = promise.get_future(); +// filewatch::FileWatch watch(test_folder_path, [&promise](const test_char& path, const filewatch::Event change_type) { +// promise.set_value(path); +// }); +// +// testhelper::create_and_modify_file(test_file_name); +// +// auto path = testhelper::get_with_timeout(future); +// REQUIRE(path == test_file_name); +//} +#endif \ No newline at end of file diff --git a/tests/string/CMakeLists.txt b/tests/string/CMakeLists.txt new file mode 100644 index 0000000..4d0b672 --- /dev/null +++ b/tests/string/CMakeLists.txt @@ -0,0 +1,22 @@ +#add tests +set(FILEWATCH_UNIT_TEST_TARGET_NAME "filewatch_unit_string") +add_executable(${FILEWATCH_UNIT_TEST_TARGET_NAME} + ${PROJECT_SOURCE_DIR}/tests/CatchMain.cpp + ${PROJECT_SOURCE_DIR}/tests/string/Test.cpp) + +#target_compile_features(${FILEWATCH_UNIT_TEST_TARGET_NAME} PRIVATE cxx_std_14) + +#enable pthreads for linux +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + +target_link_libraries(${FILEWATCH_UNIT_TEST_TARGET_NAME} + Catch + Threads::Threads) + +add_test(NAME "${FILEWATCH_UNIT_TEST_TARGET_NAME}_default" + COMMAND ${FILEWATCH_UNIT_TEST_TARGET_NAME} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + +install(TARGETS ${FILEWATCH_UNIT_TEST_TARGET_NAME} DESTINATION ${PROJECT_BINARY_DIR}/bin) \ No newline at end of file diff --git a/tests/Test.cpp b/tests/string/Test.cpp similarity index 98% rename from tests/Test.cpp rename to tests/string/Test.cpp index c30efb1..4f06e76 100644 --- a/tests/Test.cpp +++ b/tests/string/Test.cpp @@ -14,11 +14,11 @@ using test_char = char*; using test_regex = std::regex; #endif // __unix__ -#include "catch/catch.hpp" +#include -#include "../FileWatch.hpp" +#include "../../FileWatch.hpp" -#include "Util/TestHelper.hpp" +#include "../Util/TestHelper.hpp" #include #include