From a84caf6fd7867eaf6073d074d448998a8699ea6e Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 7 Apr 2016 10:44:04 -0400 Subject: [PATCH] test: handle root home directories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Saúl Ibarra Corretgé --- test/test-get-passwd.c | 10 ++++++++-- test/test-homedir.c | 14 ++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/test-get-passwd.c b/test/test-get-passwd.c index 58d9c73c..8e16fb83 100644 --- a/test/test-get-passwd.c +++ b/test/test-get-passwd.c @@ -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 diff --git a/test/test-homedir.c b/test/test-homedir.c index 5027d44c..856534a4 100644 --- a/test/test-homedir.c +++ b/test/test-homedir.c @@ -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;