diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eae9ee3..c97f96c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,14 +7,14 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/checkout@v2 - name: Checkout - - name: Build & Test - uses: ashutoshvarma/action-cmake-build@master - with: - build-dir: ${{ runner.workspace }}/build - build-type: Release - configure-options: -DCMAKE_CXX_FLAGS="-std=c++17" - run-test: true + - uses: actions/checkout@v2 + name: Checkout + - name: Build & Test + uses: ashutoshvarma/action-cmake-build@master + with: + build-dir: ${{ runner.workspace }}/build + build-type: Release + configure-options: -DCMAKE_CXX_FLAGS="-std=c++17" + run-test: true diff --git a/include/peelo/xdg.hpp b/include/peelo/xdg.hpp index 29f88c6..5e19f49 100644 --- a/include/peelo/xdg.hpp +++ b/include/peelo/xdg.hpp @@ -99,7 +99,7 @@ namespace peelo::xdg if (homedrive && *homedrive && homepath && *homepath) { - return std::filesystem::path(homedrive) / homepath; + return T(homedrive) / homepath; } } else { return userprofile; diff --git a/test/test_multiple_paths.cpp b/test/test_multiple_paths.cpp index 7c5e007..ddcd173 100644 --- a/test/test_multiple_paths.cpp +++ b/test/test_multiple_paths.cpp @@ -2,6 +2,10 @@ #include #include +#if defined(_WIN32) +# include +#endif + #include using callback_type = std::function()>; @@ -9,22 +13,18 @@ using callback_type = std::function()>; static void test_callback( const callback_type& callback, - const char* env_variable_name + const std::string& env_variable_name ) { using peelo::xdg::internal::path_separator; - - unsetenv(env_variable_name); - setenv( - env_variable_name, - ( - std::string("/xdg") + - path_separator + - path_separator + - "/xdg/xdg" - ).c_str(), - 1 - ); + const auto value = std::string("/xdg") + path_separator + path_separator + "/xdg/xdg"; + +#if defined(_WIN32) + _putenv((env_variable_name + "=" + value).c_str()); +#else + unsetenv(env_variable_name.c_str()); + setenv(env_variable_name.c_str(), value.c_str(), 1); +#endif const auto result = callback(); diff --git a/test/test_single_paths.cpp b/test/test_single_paths.cpp index 84b3aa0..c82fb86 100644 --- a/test/test_single_paths.cpp +++ b/test/test_single_paths.cpp @@ -3,6 +3,10 @@ #include #include +#if defined(_WIN32) +# include +#endif + #include using std::filesystem::path; @@ -14,10 +18,14 @@ using callback_type = std::function()>; static void test_with_env_variable( const callback_type& callback, - const char* env_variable_name + const std::string& env_variable_name ) { - setenv(env_variable_name, "xdg/test", 1); +#if defined(_WIN32) + _putenv((env_variable_name + "=" + "xdg\\test").c_str()); +#else + setenv(env_variable_name.c_str(), "xdg/test", 1); +#endif const auto result = callback(); @@ -28,12 +36,17 @@ test_with_env_variable( static void test_without_env_variable( const callback_type& callback, - const char* env_variable_name, + const std::string& env_variable_name, const optional& expected_result ) { - unsetenv(env_variable_name); +#if defined(_WIN32) + _putenv((env_variable_name + "=").c_str()); + _putenv("HOME=xdg"); +#else + unsetenv(env_variable_name.c_str()); setenv("HOME", "xdg", 1); +#endif const auto result = callback(); @@ -49,7 +62,7 @@ test_without_env_variable( static void test_callback( const callback_type& callback, - const char* env_variable_name, + const std::string& env_variable_name, const optional& expected_result_without_env_var = nullopt ) {