Fix test-get-currentexe on darwin.
Darwin uses _NSGetExecutablePath to determine the path of an executable, but that can return an absolute path. This patch tweaks the executable path to strip off a potential "./" prefix from argv[0], which fixes the test.
This commit is contained in:
parent
70bc6c0ca8
commit
f4e2d5559f
@ -30,15 +30,25 @@ TEST_IMPL(get_currentexe) {
|
||||
char buffer[PATHMAX];
|
||||
size_t size;
|
||||
char* match;
|
||||
char* path;
|
||||
int r;
|
||||
|
||||
size = sizeof(buffer) / sizeof(buffer[0]);
|
||||
r = uv_exepath(buffer, &size);
|
||||
ASSERT(!r);
|
||||
|
||||
match = strstr(buffer, executable_path);
|
||||
/* uv_exepath can return an absolute path on darwin, so if the test runner
|
||||
* was run with a relative prefix of "./", we need to strip that prefix off
|
||||
* executable_path or we'll fail. */
|
||||
if (executable_path[0] == '.' && executable_path[1] == '/') {
|
||||
path = executable_path + 2;
|
||||
} else {
|
||||
path = executable_path;
|
||||
}
|
||||
|
||||
match = strstr(buffer, path);
|
||||
/* Verify that the path returned from uv_exepath is a subdirectory of executable_path */
|
||||
ASSERT(match && !strcmp(match, executable_path));
|
||||
ASSERT(match && !strcmp(match, path));
|
||||
ASSERT(size == strlen(buffer));
|
||||
|
||||
/* Negative tests */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user