mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Factor out lookupExecutable
and other PATH improvments
This ended up motivating a good deal of other infra improvements in order to get Windows right: - `OsString` to complement `std::filesystem::path` - env var code for working with the underlying `OsString`s - Rename `PATHNG_LITERAL` to `OS_STR` - `NativePathTrait` renamed to `OsPathTrait`, given a character template parameter until #9205 is complete. Split `tests.cc` matching split of `util.{cc,hh}` last year. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
0836888002
commit
6c861b9c51
32 changed files with 616 additions and 97 deletions
64
tests/unit/libutil/executable-path.cc
Normal file
64
tests/unit/libutil/executable-path.cc
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "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 "."));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue