test: handle root home directories

Currently, the tests assert that the home directory doesn't end
in a slash. However, if the home directory is / or something like
C:\, then this assertion is incorrect. This commit adds special
handling for these cases.

Fixes: https://github.com/libuv/libuv/issues/812
PR-URL: https://github.com/libuv/libuv/pull/813
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
cjihrig 2016-04-07 10:44:04 -04:00
parent d476185bb3
commit a84caf6fd7
2 changed files with 16 additions and 8 deletions

View File

@ -45,9 +45,15 @@ TEST_IMPL(get_passwd) {
ASSERT(len > 0);
#ifdef _WIN32
ASSERT(pwd.homedir[len - 1] != '\\');
if (len == 3 && pwd.homedir[1] == ':')
ASSERT(pwd.homedir[2] == '\\');
else
ASSERT(pwd.homedir[len - 1] != '\\');
#else
ASSERT(pwd.homedir[len - 1] != '/');
if (len == 1)
ASSERT(pwd.homedir[0] == '/');
else
ASSERT(pwd.homedir[len - 1] != '/');
#endif
#ifdef _WIN32

View File

@ -29,7 +29,6 @@
TEST_IMPL(homedir) {
char homedir[PATHMAX];
size_t len;
char last;
int r;
/* Test the normal case */
@ -42,14 +41,17 @@ TEST_IMPL(homedir) {
ASSERT(len > 0);
ASSERT(homedir[len] == '\0');
if (len > 1) {
last = homedir[len - 1];
#ifdef _WIN32
ASSERT(last != '\\');
if (len == 3 && homedir[1] == ':')
ASSERT(homedir[2] == '\\');
else
ASSERT(homedir[len - 1] != '\\');
#else
ASSERT(last != '/');
if (len == 1)
ASSERT(homedir[0] == '/');
else
ASSERT(homedir[len - 1] != '/');
#endif
}
/* Test the case where the buffer is too small */
len = SMALLPATH;