Skip to content

Commit

Permalink
Merge pull request #2 from peelonet/testing
Browse files Browse the repository at this point in the history
Attempt to compile on other platforms
  • Loading branch information
RauliL authored Sep 7, 2024
2 parents ff72543 + a4979b3 commit 58efecb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion include/peelo/xdg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions test/test_multiple_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
#include <cstdlib>
#include <functional>

#if defined(_WIN32)
# include <windows.h>
#endif

#include <peelo/xdg.hpp>

using callback_type = std::function<std::vector<std::filesystem::path>()>;

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();

Expand Down
23 changes: 18 additions & 5 deletions test/test_single_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <cstring>
#include <functional>

#if defined(_WIN32)
# include <windows.h>
#endif

#include <peelo/xdg.hpp>

using std::filesystem::path;
Expand All @@ -14,10 +18,14 @@ using callback_type = std::function<std::optional<std::filesystem::path>()>;
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();

Expand All @@ -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<path>& 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();

Expand All @@ -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<path>& expected_result_without_env_var = nullopt
)
{
Expand Down

0 comments on commit 58efecb

Please sign in to comment.