1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-24 19:29:36 +01:00
nix/src/libutil-tests/executable-path.cc
Graham Christensen e4f62e4608 Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.
2025-07-18 12:47:27 -04:00

64 lines
1.5 KiB
C++

#include <gtest/gtest.h>
#include "nix/util/executable-path.hh"
namespace nix {
#ifdef WIN32
# define PATH_VAR_SEP L";"
#else
# define PATH_VAR_SEP ":"
#endif
#define PATH_ENV_ROUND_TRIP(NAME, STRING_LIT, CXX_LIT) \
TEST(ExecutablePath, NAME) \
{ \
OsString s = STRING_LIT; \
auto v = ExecutablePath::parse(s); \
EXPECT_EQ(v, (ExecutablePath CXX_LIT)); \
auto s2 = v.render(); \
EXPECT_EQ(s2, s); \
}
PATH_ENV_ROUND_TRIP(emptyRoundTrip, OS_STR(""), ({}))
PATH_ENV_ROUND_TRIP(
oneElemRoundTrip,
OS_STR("/foo"),
({
OS_STR("/foo"),
}))
PATH_ENV_ROUND_TRIP(
twoElemsRoundTrip,
OS_STR("/foo" PATH_VAR_SEP "/bar"),
({
OS_STR("/foo"),
OS_STR("/bar"),
}))
PATH_ENV_ROUND_TRIP(
threeElemsRoundTrip,
OS_STR("/foo" PATH_VAR_SEP "." PATH_VAR_SEP "/bar"),
({
OS_STR("/foo"),
OS_STR("."),
OS_STR("/bar"),
}))
TEST(ExecutablePath, elementyElemNormalize)
{
auto v = ExecutablePath::parse(PATH_VAR_SEP PATH_VAR_SEP PATH_VAR_SEP);
EXPECT_EQ(
v,
(ExecutablePath{{
OS_STR("."),
OS_STR("."),
OS_STR("."),
OS_STR("."),
}}));
auto s2 = v.render();
EXPECT_EQ(s2, OS_STR("." PATH_VAR_SEP "." PATH_VAR_SEP "." PATH_VAR_SEP "."));
}
} // namespace nix