From 473c85fabef8a732bb49e2aaf507c8ef9d4ef11c Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Wed, 15 Mar 2023 13:03:48 +0000 Subject: [PATCH 01/11] wip: created seperate std::filesystem test --- .github/workflows/cmake.yml | 2 +- .vscode/settings.json | 85 ++++++++++++++++ CMakeLists.txt | 18 ++-- FileWatch.hpp | 2 +- example/CMakeLists.txt | 2 + example/main.cpp | 22 +++-- tests/CMakeLists.txt | 27 ++---- tests/filesystem/CMakeLists.txt | 22 +++++ tests/filesystem/Test.cpp | 167 ++++++++++++++++++++++++++++++++ tests/string/CMakeLists.txt | 22 +++++ tests/{ => string}/Test.cpp | 0 11 files changed, 329 insertions(+), 40 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 tests/filesystem/CMakeLists.txt create mode 100644 tests/filesystem/Test.cpp create mode 100644 tests/string/CMakeLists.txt rename tests/{ => string}/Test.cpp (100%) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 8db55b9..ccab4ce 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 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..36b1911 100644 --- a/FileWatch.hpp +++ b/FileWatch.hpp @@ -738,7 +738,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/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..2f841a7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,25 +2,10 @@ add_library(Catch INTERFACE) target_include_directories(Catch INTERFACE ${PROJECT_SOURCE_DIR}/tests/catch/catch.hpp) -#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..ff77882 --- /dev/null +++ b/tests/filesystem/CMakeLists.txt @@ -0,0 +1,22 @@ +#add tests +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..105a0d7 --- /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 "catch/catch.hpp" + +#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 100% rename from tests/Test.cpp rename to tests/string/Test.cpp From 67f4e9e585a8f694d3d95a6b4b5b41d786b18d03 Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Wed, 15 Mar 2023 13:57:26 +0000 Subject: [PATCH 02/11] fix: include paths --- .github/workflows/cmake.yml | 2 +- tests/filesystem/Test.cpp | 6 +++--- tests/string/Test.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ccab4ce..5afd5cd 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -120,7 +120,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 env: CC: ${{matrix.config.cc}} CXX: ${{matrix.config.cxx}} diff --git a/tests/filesystem/Test.cpp b/tests/filesystem/Test.cpp index 105a0d7..eb1bf6d 100644 --- a/tests/filesystem/Test.cpp +++ b/tests/filesystem/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 diff --git a/tests/string/Test.cpp b/tests/string/Test.cpp index c30efb1..c036291 100644 --- a/tests/string/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 From dc769a750265b082afcbb5f7a48165e06cd7e5dd Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Wed, 15 Mar 2023 19:50:50 +0000 Subject: [PATCH 03/11] fix: changed import dirs for catch --- tests/CMakeLists.txt | 2 +- tests/filesystem/Test.cpp | 2 +- tests/string/Test.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2f841a7..6dae475 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,6 @@ #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) if(FileWatch_Build_Tests) add_subdirectory(string) diff --git a/tests/filesystem/Test.cpp b/tests/filesystem/Test.cpp index eb1bf6d..b1b01bb 100644 --- a/tests/filesystem/Test.cpp +++ b/tests/filesystem/Test.cpp @@ -14,7 +14,7 @@ using test_char = char*; using test_regex = std::regex; #endif // __unix__ -#include +#include #include "../../FileWatch.hpp" diff --git a/tests/string/Test.cpp b/tests/string/Test.cpp index c036291..4f06e76 100644 --- a/tests/string/Test.cpp +++ b/tests/string/Test.cpp @@ -14,7 +14,7 @@ using test_char = char*; using test_regex = std::regex; #endif // __unix__ -#include +#include #include "../../FileWatch.hpp" From e5c9ea9ca2a5f397be29236c203dd8b8cedd0591 Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Thu, 16 Mar 2023 13:43:46 +0000 Subject: [PATCH 04/11] fix: setting 17 flag on filesystem test --- FileWatch.hpp | 2 +- tests/filesystem/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/FileWatch.hpp b/FileWatch.hpp index 36b1911..b0b603f 100644 --- a/FileWatch.hpp +++ b/FileWatch.hpp @@ -738,7 +738,7 @@ namespace filewatch { size / sizeof(TCHAR), buf, nullptr); - return StringType{std::basic_string{(C*)buf, length}}; + return StringType{std::basic_string((C*)buf, length)}; } #endif diff --git a/tests/filesystem/CMakeLists.txt b/tests/filesystem/CMakeLists.txt index ff77882..8bf3b07 100644 --- a/tests/filesystem/CMakeLists.txt +++ b/tests/filesystem/CMakeLists.txt @@ -1,4 +1,6 @@ #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 From 3d4f2333f5eb907aaf0321da26fc7e359b4b6ac5 Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Fri, 17 Mar 2023 20:47:39 +0000 Subject: [PATCH 05/11] feat: added file system test to ci --- .github/workflows/cmake.yml | 40 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5afd5cd..8c3f607 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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 -DFileWatch_Build_Tests=ON + 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}} From 9408cef91dbbf8d991576512027cc99b923b6ac7 Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Sat, 18 Mar 2023 09:52:46 +0000 Subject: [PATCH 06/11] fix: remove reserve for combatabilty with filesystem::path --- FileWatch.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FileWatch.hpp b/FileWatch.hpp index b0b603f..849df85 100644 --- a/FileWatch.hpp +++ b/FileWatch.hpp @@ -718,7 +718,7 @@ namespace filewatch { size_t needed = mbsrtowcs(nullptr, &str, 0, &state) + 1; StringType s; - s.reserve(needed); + // s.reserve(needed); mbsrtowcs((wchar_t*)&s[0], &str, s.size(), &state); return s; } From 4333ecf8176f8db758423dc68d750bb4e45c5b15 Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Mon, 8 May 2023 18:43:46 +0100 Subject: [PATCH 07/11] wip: hopefully wstring, path, and string aware.... --- FileWatch.hpp | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/FileWatch.hpp b/FileWatch.hpp index 849df85..bbb2db4 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}; } From 8061c34b8b31328785980774f443b232c6feee7c Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Mon, 8 May 2023 20:53:45 +0100 Subject: [PATCH 08/11] fix: mingw --- FileWatch.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FileWatch.hpp b/FileWatch.hpp index bbb2db4..ee09375 100644 --- a/FileWatch.hpp +++ b/FileWatch.hpp @@ -756,7 +756,7 @@ namespace filewatch { size / sizeof(TCHAR), buf, nullptr); - return StringType{std::basic_string((C*)buf, length)}; + return StringType{std::basic_string((C*)buf, length)}; } #endif From 0e4fa066914493df0577296ee9503f38d843af01 Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Mon, 8 May 2023 20:54:28 +0100 Subject: [PATCH 09/11] fix: wrong type --- FileWatch.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FileWatch.hpp b/FileWatch.hpp index ee09375..a9e4ce2 100644 --- a/FileWatch.hpp +++ b/FileWatch.hpp @@ -756,7 +756,7 @@ namespace filewatch { size / sizeof(TCHAR), buf, nullptr); - return StringType{std::basic_string((C*)buf, length)}; + return StringType{std::basic_string((C*)buf, length)}; } #endif From 2b596d5894f5b9d93ab6f2650d0ce517841b2d75 Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Sun, 21 Apr 2024 23:10:27 +0100 Subject: [PATCH 10/11] wip: triggering build --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a74f92b..b4cd0df 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Drop [FileWatch.hpp](https://github.com/ThomasMonkman/filewatch/blob/master/File 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"; } ); ``` From e8b394bf7534cfe938ccbbc6c24cdd346295faad Mon Sep 17 00:00:00 2001 From: Thomas Monkman Date: Tue, 27 Aug 2024 22:48:17 +0100 Subject: [PATCH 11/11] ci: trigger build again --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b4cd0df..b805714 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ 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